SDKs for Android / Integrate SDK on application side
  Back to Docs

SDKs for Android

Integrate SDK on application side

General purchase logic

  1. Implement the logic of getting payment tokens in one of the following ways:
    • Using the Store library (recommended):
      1. To purchase a single item, call the createOrderByItemSku method.
      2. To purchase the items in the cart:
        1. After the user has filled the cart, call the fillCurrentCartWithItems method.
        2. Call the createOrderFromCartById or createOrderFromCurrentCart method.

    • Using the IGS & BB API.
    • Using your own server methods or BaaS solution methods.

  1. Implement the logic of payment UI opening:
Note
Review the demo project for an implementation example.
Copy
Full screen
Small screen
vmPurchase.paymentToken.observe(this) { token ->
    val intent = XPayments.createIntentBuilder(this)
        .accessToken(AccessToken(token))
        .isSandbox(BuildConfig.IS_SANDBOX)
        .useWebview(true)
        .build()
    startActivityForResult(intent, RC_PAYSTATION)
}
  1. Implement payment result handling:
Copy
Full screen
Small screen
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == RC_PAYSTATION) {
        val (status, _) = XPayments.Result.fromResultIntent(data)
        when (status) {
            XPayments.Status.COMPLETED -> showSnack(getString(R.string.payment_completed))
            XPayments.Status.CANCELLED -> showSnack(getString(R.string.payment_cancelled))
            XPayments.Status.UNKNOWN -> showSnack(getString(R.string.payment_unknown))
        }
    }
}
Note
Review the demo project for an implementation example.

Payment UI opening options

Depending on what parameters are passed to the XPayments.createIntentBuilder method, the payment UI is opened in WebView or Custom Tab.

If the useWebview(true) parameter is passed, WebView is always used to open the payment UI.

Custom Tab is used if the following conditions are met:

  • When calling XPayments.createIntentBuilder, the useWebview parameter is not passed or useWebview(false) is passed.
  • The user’s device uses one of the following browsers by default:
    • Google Chrome
    • Samsung Internet Browser
    • Huawei Browser

If the different browser is used, the payment UI opens in WebView regardless of the parameters of the XPayments.createIntentBuilder method.

In WebView, the user doesn’t see the browser bar and standard navigation elements. This makes the in-app purchase process seemless. But you need to modify the application and add the icon so the user can close the payment UI at any stage of the purchase. Refer to the demo application for modification example.

In Custom Tab, the user can close the payment UI by clicking on the icon.

Example of using WebView:

Example of using Custom Tab:

Your progress
Thank you for your feedback!
Last updated: March 21, 2024

Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!