Guides • Accept Payments
Android
doc

Accept payments via Revolut Pay - Android

Welcome to the implementation guide for Revolut Pay on Android! This page provides a comprehensive walkthrough for integrating Revolut Pay into your Android application.

Revolut Pay - Mobile

How it works

From an implementation perspective, integrating Revolut Pay into your Android app with the Revolut Pay SDK involves the following components:

  1. Server-side: You need to set up an endpoint on your server that creates an order using the Merchant API: Create an order endpoint.
  2. Client-side: Your Android app uses the Revolut Pay SDK to collect payment details and communicates with your server to create the order and process the payment.
  3. Endpoint for webhooks: Optionally, you can set up an endpoint to receive webhook events from the Merchant API to track the payment lifecycle. For more information, see: Use webhooks to keep track of the payment lifecycle.

The payment flow is slightly different based on whether your customer has the Revolut app installed:

  1. The customer goes to the checkout screen in your app.
  2. The customer taps the Revolut Pay button.
  3. Your app uses your server endpoint to create an order and obtains the order token via the Merchant API: Create an order.
  4. The Revolut Pay SDK opens the Revolut app, where they review and authorise the payment.
  5. The SDK processes the payment and presents the payment result to the customer.
  6. Once the payment is successful, your customer is redirected to your app.
  7. Optionally, your server receives webhook notifications about each event you're subscribed to. For more information, see: Use webhooks to keep track of the payment lifecycle.
info

For more information about the order and payment lifecycle, see: Order and payment lifecycle.

Implementation overview

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:

  1. Install Android SDK
  2. Configure Android SDK
  3. Create Revolut Pay button
  4. (Optional) Create Revolut Pay promotional banner
  5. Handle button taps
  6. Confirm payments

Before you begin

Before you start this tutorial, ensure you have completed the following steps:

Implement Revolut Pay on Android

1. Install Android SDK

  1. Since the SDK is hosted on mavenCentral, to fetch the dependency add the following lines to your project level build.gradle:

    allprojects {
    repositories {
    mavenCentral()
    }
    }
  2. Add the dependency to the module level build.gradle:

    implementation 'com.revolut:revolutpayments:1.0.0'
    implementation 'com.revolut:revolutpay:2.3'
  3. Sync your project

note

The minimum Android SDK version that is supported by the SDK is Android 5.0 (API 21).

2. Configure Android SDK

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.

    note

    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.

    caution

    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.

note

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>

3. Create Revolut Pay button

You can add the Revolut Pay button to your app in the following two ways:

Via adding button from kotlin/java code

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.

(Optional) 4. Add the Revolut Pay promotional banner widget

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

Create a custom theme for the banner

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>
AttributeDescriptionFormatRequired
revolutPay_ColorAccentAccent colour of the banner. Default: #0666EBHex colour codeNo
revolutPay_ColorBackgroundBackground colour of the banner. Default: #F7F7F7Hex colour codeNo
revolutPay_BannerCornerRadiusCorner radius of the banner's corners. Default: 12dpDimensionNo
revolutPay_ComponentCornerRadiusCorner radius of the banner's inner components. Default: 12dpDimensionNo
revolutPay_StrokeWidthWidth of the banner's border stroke. Default: 0dpDimensionNo
revolutPay_StrokeColorColour of the banner's border stroke. Default: #BBC4CDHex colour codeNo

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

5. Handle button taps

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.

6. Confirm payments

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.

Example app

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.

Run the example application

Follow these steps to set up and run the example app:

  1. Clone the repository:
    git clone https://bitbucket.org/revolut/revolut-pay-android.git
  2. Open the project in Android Studio, or your preferred IDE.
  3. Run the example app.

What's next

Check out the follow pages for further information about:

Was this page helpful?