Enterprise-level SDKs for Android / Track order status
  Back to Docs

Enterprise-level SDKs for Android

Track order status

Notice
The SDK allows you to track order status on the client side of your application. However, we recommend setting up a Payment webhook handler to receive order information in the back end of your application. This allows you to implement additional validation of completed purchases.

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:

Notice

If you use both the Store and Payments libraries in your application, we recommend using the Store library method to track the order.

If you only use the Payments library, subscribe to order status changes using the Payments library method. Use the method to request the order status only as an auxiliary way to retrieve data to avoid overloading Xsolla systems.

Subscribe to order status changes

Use Store library method

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 type OrderStatusListener.
  • orderId — order ID received from the purchase via the shopping cart, one-click purchase, or purchase for virtual currency as the parameter.
SDK reference documentation
Learn more about SDK methods and its parameters.

Example of calling the XStore.getOrderStatus method:

Copy
Full screen
Small screen
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:

  1. A web socket connection is established.
  2. If the web socket connection is established successfully and order status changes to done or cancel, tracking stops. If a web socket connection fails or the response contains incorrect data, the order status is tracked using short-polling.
  3. 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 or cancel.

Use Payments library method

To track order status changes using the Payments library, use the payment status callback. To do this:
  1. When creating the XPayments.IntentBuilder object, pass the StatusReceivedCallback callback using the setStatusReceivedCallback method.
  2. Implement the onSuccess method in the StatusReceivedCallback callback, which is called with every unique status change.
Notice

Order status information is passed to the onSuccess method in an object of the InvoicesDataResponse type. This object contains an array of InvoiceData objects. Each InvoiceData object corresponds to a specific stage in the order processing and contains the status of this stage.

For example, if the user initially entered invalid data when placing the order, an object with the status InvoicesDataResponse.CANCELED will appear in the InvoiceData list. If the user then corrects the data and successfully pays for the order, a new InvoiceData object will appear in the array, now with the status InvoicesDataResponse.Status.DONE.

Status tracking stops if the final payment status (InvoicesDataResponse.Status.DONE or InvoicesDataResponse.Status.ERROR) is received.

Example:

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()

Request order status

To request the current status of the payment, call the getOrder method from the Store library, passing the following parameters to it:

Notice

Order status information is passed to the onSuccess method in an object of the InvoicesDataResponse type. This object contains an array of InvoiceData objects. Each InvoiceData object corresponds to a specific stage in the order processing and contains the status of this stage.

For example, if the user initially entered invalid data when placing the order, an object with the status InvoicesDataResponse.CANCELED will appear in the InvoiceData list. If the user then corrects the data and successfully pays for the order, a new InvoiceData object will appear in the array, now with the status InvoicesDataResponse.Status.DONE.

Status tracking stops if the final payment status (InvoicesDataResponse.Status.DONE or InvoicesDataResponse.Status.ERROR) is received.

Example:

Copy
Full screen
Small screen

XPayments.getStatus(<token>, <isSandbox>, object : GetStatusCallback {
            override fun onSuccess(data: InvoicesDataResponse?) {
                Log.d(TAG, "onSuccess is fired. Result data = $data")
            }

           override fun onError(throwable: Throwable?, errorMessage: String?) {
                Log.d(TAG, "onError is fired. ErrorMessage = $errorMessage")
            }

})
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.

Useful links

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!