Integrate SDK on application side
General purchase logic
- 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:
- After the user has filled the cart, call the
fillCurrentCartWithItems
method. - Call the
createOrderFromCartById
orcreateOrderFromCurrentCart
method.
- After the user has filled the cart, call the
- To purchase a single item, call the
- Using the Store library (recommended):
- Using the IGS & BB API.
- Using your own server methods or BaaS solution methods.
- Implement the logic of payment UI opening:
- kotlin
vmPurchase.paymentToken.observe(this) { token ->
val intent = XPayments.createIntentBuilder(this)
.accessToken(AccessToken(token))
.isSandbox(BuildConfig.IS_SANDBOX)
.useWebview(true)
.build()
startActivityForResult(intent, RC_PAYSTATION)
}
- Implement payment result handling:
- kotlin
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))
}
}
}
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
, theuseWebview
parameter is not passed oruseWebview(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:
Found a typo or other text error? Select the text and press Ctrl+Enter.