Guides • Accept Payments
Handle Revolut Pay button clicks
doc

Handle Revolut Pay button clicks

In order to process users clicking the Revolut Pay button, the following should be done:

  1. Invoke RevolutPayButton.createController() for the instance of the Revolut Pay button. This method will create an instance of Controller, to provide parameters for the payment configuration.
  2. After an instance of Controller is created you have to set up a callback by calling setHandler() method. This callback will be invoked once the user clicks the button, and an instance of the ConfirmationFlow will be provided for further processing. Once the callback is invoked, you have to create an order (please refer to this document to find more details about creating an order). Once it's created please follow these steps:
    • Invoke the ConfirmationFlow.setOrderToken() method for setting the order token (which you should receive once you create an order).
    • Set up the lifecycle of the component that hosts the button (most likely it's going to be either Fragment or Activity) via ConfirmationFlow.attachLifecycle(). The Revolut Pay button internally polls the latest state of the order from backend in order to notify the user about success in a timely manner. Lifecycle is used to pause/restart polling when the app goes to background, or the user navigates away from the screen that contains Revolut Pay button.
    • After the order token and lifecycle object are set, continue the flow by invoking the ConfirmationFlow.continueConfirmationFlow().
  3. Apart from click handler you should also set up the callback invoked when the payment succeeds or fails. The Controller.setOrderResultCallback() should be used for this purpose.

The following snippet showcases how to set up the Revolut Pay button properly:

  revolutPayButton.createController().apply {
setHandler { flow ->
//create an order via sending a backend request
flow.setOrderToken(orderToken = orderToken)
flow.attachLifecycle(this@FlowDemoFragment.lifecycle)
flow.continueConfirmationFlow()
}
setOrderResultCallback(object : OrderResultCallback {
override fun onOrderCompleted() {
//Inform the user about successful payment
}
override fun onOrderFailed(throwable: Throwable) {
//Inform the user about a failure
}
})
}
note

The callbacks that are set via setHandler() and setOrderResultCallback() are going to be invoked on the main thread, so if you need to make a network request or some other time-consuming operation, you will have to switch to background thread.

Also keep in mind that if there is an error at some point, the onOrderFailed() callback will be invoked, so you don't have to do anything for error handling, other than implementing this callback. This callback will also be invoked in case of a timeout error.

Was this page helpful?