In order to process users clicking the Revolut Pay button, the following should be done:
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.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:ConfirmationFlow.setOrderToken()
method for setting the order token (which you should receive once you create an order
).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.order
token and lifecycle
object are set, continue the flow by invoking the ConfirmationFlow.continueConfirmationFlow()
.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
}
})
}
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.