Welcome to the implementation guide for Revolut Pay on Android! This page provides a comprehensive walkthrough for integrating Revolut Pay into your Android application.
From an implementation perspective, integrating Revolut Pay into your Android app with the Revolut Pay SDK involves the following components:
The payment flow is slightly different based on whether your customer has the Revolut app installed:
token
via the Merchant API: Create an order.For more information about the order and payment lifecycle, see: Order and payment lifecycle.
Check the following high-level procedure of implementing Revolut Pay in your Android app. Use the links to jump to the details of each step:
Before you start this tutorial, ensure you have completed the following steps:
Since the SDK is hosted on mavenCentral
, to fetch the dependency add the following lines to your project level build.gradle
:
allprojects {
repositories {
mavenCentral()
}
}
Add the dependency to the module level build.gradle
:
implementation 'com.revolut:revolutpayments:1.0.0'
implementation 'com.revolut:revolutpay:2.3'
Sync your project
The minimum Android SDK version that is supported by the SDK is Android 5.0 (API 21).
Initialize the SDK by invoking RevolutPayments.revolutPay.init(environment: RevolutPayEnvironment, returnUri: Uri, merchantPublicKey: String, requestShipping: Boolean, customer: Customer?)
, where you will need to define:
environment
: either MAIN
or SANDBOX
. Use the Revolut Business Sandbox environment to test your Merchant account integration before you push the code changes to the production environment.
returnUri
: a URI that represents a deep link used by the Revolut app, to return to your app after the payment is confirmed or rejected. This will greatly improve the customer experience, as it will allow them to return to your app after authorizing the payment.
The deep link should be registered in manifest to allow opening an activity, if you want to support automatic redirection.
The returnUri
might be based on a custom host
-scheme
combination that can be defined within your application.
Here is an example of an activity that can handle returnUri
(note that launchMode
should be set to singleTop
, otherwise it will not be possible to return to your app):
<activity
android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="return_uri_host"
android:scheme="return_uri_scheme" />
</intent-filter>
</activity>
merchantPublicKey
: a public key for your merchant account from Revolut console.
requestShipping
: If you want the shipping address and delivery method to be quickly collected from the user through Revolut Pay, pass the requestShipping
parameter as true
.
This way, your app can skip the shipping flow during checkout and the user can use existing shipping details stored by Revolut Pay.
By default, Fast checkout is not enabled.
Your backend must support Fast checkout for this functionality to work. For more information, see: Implement Revolut Pay with Fast checkout.
customer
: object containing customer details the merchant already has (name, email, phone number, date of birth).
For more details about the available parameters, see: Parameters: Android.
Now you can integrate the Revolut Pay button into your layout. It can be done either by including it in your .xml
file, or by creating it via RevolutPayments.revolutPay.provideButton()
method.
Since the SDK relies on the internet connection to process your order, you need to make sure that the internet permission is added to your app. In case it isn't, add the following line to the manifest:
<queries>
<package android:name="com.revolut.revolut" />
</queries>
You can add the Revolut Pay button to your app in the following two ways:
In case you want to create a button from code, you can use the RevolutPayments.revolutPay.provideButton()
method, which has the following parameters:
context
- an instance of context used to create a view
buttonParams
- a set of parameters allowing to setup the appearance of the button
RevolutPayments.revolutPay.provideButton(
context: Context,
buttonParams: ButtonParams
): RevolutPayButton
For more details about the available parameters and button styling, see: Parameters: Android and Revolut Pay button guidelines.
Optionally, you can use the Revolut Pay promotional banner widget to offer rewards to customers who create a new Revolut account after checkout. You can add the widget to your app the following way.
To create the promotional banner, you can use the RevolutPayments.revolutPay.providePromotionalBannerWidget()
method, which has the following parameters:
context
- an instance of context used to create a view
bannerParams
- a set of parameters allowing to setup the widget
themeId
- (optional) resource ID of the visual theme to be applied to the banner. If it's not provided, the default theme will be applied.
RevolutPayments.revolutPay.providePromotionalBannerWidget(
context: Context,
bannerParams: BannerParams,
themeId: Int
): RevolutPayButton
For more details about the available parameters, see: Parameters: Android
To apply a customised theme to the banner, create a resource file with the following content:
<style name="RevolutPay_RevolutPayBanner">
<item name="revolutPay_ColorAccent">#0666EB</item>
<item name="revolutPay_ColorBackground">#F7F7F7</item>
<item name="revolutPay_BannerCornerRadius">12dp</item>
<item name="revolutPay_ComponentCornerRadius">12dp</item>
<item name="revolutPay_StrokeWidth">0dp</item>
<item name="revolutPay_StrokeColor">#BBC4CD</item>
</style>
Attribute | Description | Format | Required |
---|---|---|---|
revolutPay_ColorAccent | Accent colour of the banner. Default: #0666EB | Hex colour code | No |
revolutPay_ColorBackground | Background colour of the banner. Default: #F7F7F7 | Hex colour code | No |
revolutPay_BannerCornerRadius | Corner radius of the banner's corners. Default: 12dp | Dimension | No |
revolutPay_ComponentCornerRadius | Corner radius of the banner's inner components. Default: 12dp | Dimension | No |
revolutPay_StrokeWidth | Width of the banner's border stroke. Default: 0dp | Dimension | No |
revolutPay_StrokeColor | Colour of the banner's border stroke. Default: #BBC4CD | Hex colour code | No |
After defining the resource file for your custom theme, reference it in the RevolutPayments.revolutPay.providePromotionalBannerWidget()
method:
RevolutPayments.revolutPay.providePromotionalBannerWidget(
context: Context,
params: BannerParams,
themeId: Int = R.style.RevolutPay_RevolutPayBanner
): RevolutPayButton
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.
After the order
is created and the ConfirmationFlow.continueConfirmationFlow()
has been invoked, there might be 2 different flows that will allow the user to confirm the payment. Which flow is going to be utilized for the particular user is based on the presence/absence of the Revolut Retail app on their device.
If the Revolut Retail app is installed, it is opened to allow the user to confirm the payment within the app. This will simplify the confirmation procedure for the user, since the user most likely has a Revolut account signed in within the app. In this case, the user has to enter their passcode and simply click the Confirm button. Once the payment is confirmed, a success message is displayed and the user is redirected to your app.
However, it's possible that the user doesn't have the Revolut app installed. In such case, they won't leave the app where the SDK is integrated. Instead, the SDK will open an activity that includes a webview, which is going to be used to let the user make the payment. Once the payment is confirmed, the activity is automatically closed and the user is redirected to the screen where the Revolut Pay button is integrated.
The SDK's public repository contains a fully functional example app designed to demonstrate how to integrate the Revolut Pay SDK into your mobile application. This app serves as a practical reference for developers, showcasing a working implementation of the SDK's features.
Follow these steps to set up and run the example app:
git clone https://bitbucket.org/revolut/revolut-pay-android.git
Check out the follow pages for further information about: