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):
      • To purchase a single item, call the createOrderByItemSku method.
      • 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 API.
    • Using your own server methods or BaaS solution methods.

  1. Implement the logic of payment UI opening:
Copy
Full screen
Small screen
val intent = XPayments.createIntentBuilder(this)
               .accessToken(<accessToken>)
               .isSandbox(<isSandbox>)
           	.setStatusReceivedCallback(object : StatusReceivedCallback {
               	override fun onSuccess(data: InvoicesDataResponse) {
                   		Log.d(TAG, "StatusReceivedCallback is fired. Result data = $data")
               	}
           	})
           	.build()
Note
Review the demo project for an implementation example.

Payment UI opening options

The SDK for Android provides 3 ways to display the payment interface within the application:

WebViewCustom TabsTrusted Web Activity
Pros
  • Makes the in-app purchase process seamless, because users don’t see transitions between the application and the web page.
  • There is no standard toolbar at the top of the screen.
  • Integrates natively with Google Wallet and other on-device payment services. This allows users to automatically fill in fields with saved data, e.g., email, and bank card details.
  • Supports a smooth transition to a web page using a special background and fading effect.
  • Integrates natively with Google Wallet and other on-device payment services. This allows users to automatically fill in fields with saved data, for example, email, and bank card details.
  • Allows screen orientation locking.
  • There is no standard toolbar at the top of the screen.
Cons
  • Doesn’t support security features such as Google Wallet.
  • Auto-filling fields with saved data doesn’t work, e.g., email, bank card details.
  • Opens a web page in a separate window overlaying the application.
  • Features vary depending on the Chrome browser on the user’s device and its version.
  • Doesn’t allow screen orientation locking.

WebView display example:

Custom Tabs display example:

Trusted Web Activity display example:

Set up method for opening payment UI

By default the SDK uses Custom Tabs. If Custom Tabs is not available on the user’s device, e.g., if a suitable browser is not installed, the SDK will automatically switch to other methods to open payment UI: first WebView and then on the external browser installed on the device by default.

You can set a different primary method of opening the payment UI using the setActivityType method.

Example:

Copy
Full screen
Small screen
XPayments.createIntentBuilder(this)
  .accessToken(AccessToken(token))
  .isSandbox(BuildConfig.IS_SANDBOX)
  .setActivityType(ActivityType.TRUSTED_WEB_ACTIVITY)
  .build()

In case the primary method is not available, the SDK switches to other methods in the following order: Trusted Web Activity > Custom Tabs > WebView > external browser installed on the device by default.

Notice

If you want to install Trusted Web Activity as the main method of opening the payment interface, contact your Customer Success Manager or email to csm@xsolla.com.

You will need to provide the following information:

For more information about Trusted Web Activity, see Google documentation.

Set up payment UI close button

We recommend to set up a close button for the payment UI, since the browser bar and standard navigation elements are not visible to the user in WebView and Trusted Web Activity. To do this, in the PaymentOptions object in the ui.mobile parameter, pass the mobile = UiMobileProjectSettingHeader object with the closeButton=true parameter.

You can select the icon that will be displayed on the button. To do this, pass one of the following values ​​in the closeButtonIcon parameter:

  • “arrow” — to display the icon
  • “cross” — to display the × icon (used by default)

Example of PaymentOptions object:

Copy
Full screen
Small screen
val paymentOptions = PaymentOptions(
            isSandbox = isSandbox,
            settings = PaymentProjectSettings(
                ui = UiProjectSetting(mobile = MobileSettings(header = UiMobileProjectSettingHeader(closeButton = true, closeButtonIcon = "arrow"))),
                returnUrl = "app://xpayment.${getApplication<Application>().packageName}",
                redirectPolicy = SettingsRedirectPolicy(
                    redirectConditions = "any",
                    delay = 5,
                    statusForManualRedirection = "any",
                    redirectButtonCaption = "Back to the Game"
                )
            )
        )

Example of using the closeButton and closeButtonIcon parameters in WebView and Trusted Web Activity:

Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Last updated: September 5, 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!