Track order status
After a user makes a purchase, your application can perform the following actions:
- show the order status in the application UI
- credit a user’s balance after a successful payment
- grant the purchased items after a successful payment
When using the SDK to implement the logic of these actions, you can track the order status in the following ways:
Subscribe to order status changes
To subscribe to order status changes, use the getOrderStatus
SDK method from the Store library and pass the following parameters to the method:
listener
— listener object of typeOrderStatusListener
.orderId
— order ID received from the purchase via the shopping cart, one-click purchase, or purchase for virtual currency as the parameter.
Example of calling the XStore.getOrderStatus method:
- kotlin
XStore.getOrderStatus(object : OrderStatusListener() {
override fun onStatusUpdate(status: OrderResponse.Status) {
if(status == OrderResponse.Status.DONE) {
Log.d("MainActivity", "Success")
}
}
override fun onFailure() {
Log.d("MainActivity", "Failure")
}
}, orderId)
We recommend to call XStore.getOrderStatus
method when opening payment UI.
Purchase methods encapsulate several methods for tracking the order status. Tracking is performed according to the following algorithm:
- A web socket connection is established.
- If the web socket connection is established successfully and order status changes to
done
orcancel
, tracking stops. If a web socket connection fails or the response contains incorrect data, the order status is tracked using short-polling. - Order status tracking continues with short-polling. A simple HTTP order status request is sent once every 3 seconds. Tracking stops if order status changes to
done
orcancel
.
Request order status
You can also request order status, for example, when redirecting the user to the application from the payment UI. Use the statuses returned by the XPayments
class to track when the payment UI is closed.
XPayments
class indicate whether the user has completed a purchase flow in the payment UI and are not the same as payment transaction statuses.The XPayments
class can return the following statuses:
XPayments.Status.COMPLETED
— the user completed the payment and returned to the application.XPayments.Status.CANCELLED
— the user closed the payment UI without completing the payment.XPayments.Status.UNKNOWN
— аn error occurred during payment, for example, when the bank rejected the transaction.
To get the current status of a payment transaction, use the getOrder
method of the Store library. Pass the order ID received from the purchase via the shopping cart, one-click purchase, or purchase for virtual currency as the parameter.
Was this article helpful?
Rate this page
Don’t want to answer
Thank you for your feedback!
Useful links
Last updated: March 26, 2024Found a typo or other text error? Select the text and press Ctrl+Enter.