Enable Secure Remote Commerce - Android

This topic provides step-by-step instructions for integrating Secure Remote Commerce (SRC) with the In-App Payments SDK on an Android device. The SRC integration provides the ability for an application to offer Mastercard Click to Pay for a payment.

Link to section

Prerequisites and limitations

To enable SRC with the In-App Payments SDK on Android, the following must be true:

  • You're a US-based Square seller. SRC for the In-App Payments SDK is only available for Square sellers based in the United States.
  • You've followed the instructions in In-App Payments: Build on Android. This topic doesn't cover the general setup of the In-App Payments SDK.
  • You've read and will adhere to the Mastercard brand guidelines.
  • SRC isn't supported in the Square Sandbox.
Link to section

Step 1: Add SRC build dependencies

Add the SRC binary dependency to the build.gradle file of your :app module.

dependencies { ... implementation 'com.squareup.sdk.in-app-payments:secure-remote-commerce:1.5.0' ... }
Link to section

Step 2: Add an SRC button image resource to your project

Create the image for your Click to Pay button by following the guidance on the Mastercard Branding Requirements page. Choose Use in digital payments and then choose Signaling Mastercard Click to Pay enablement. The image you create should look like the following:

A graphic showing a Secure Remote Commerce button image for Mastercard.

The examples on this page assume that you have created a PNG file (src_logo_button) and added it as a resource in the drawable folder in your project resources.

Important

If you don't obtain an SRC image and store it in your project, you should download the image URL at runtime, convert the image into a PNG, and cache it.

Link to section

Step 3: Add an SRC item to your activity layout

Add a clickable item to your activity layout for starting an SRC payment. Step 6 shows you how to add an onClickListener to the item you create.

<ImageButton android:id="@+id/pay_with_src_button" style="@style/CustomButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="32dp" android:layout_marginStart="8dp" android:background="@drawable/src_button" android:enabled="false" android:src="@drawable/src_logo_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/button_middle_guide" app:layout_constraintTop_toTopOf="@id/pay_with_card_button" />
Link to section

Step 4: Import the SRC binaries

Add the SRC dependencies in the activity class where you're integrating SRC.

import sqip.SecureRemoteCommerce; import sqip.SecureRemoteCommerceParameters;
Link to section

Step 5: Update your activity class for SRC

Declare the following fields as a private Activity variable:

private Button startSecureRemoteCommerceButton;
Link to section

Step 6: Enable SRC in your activity onCreate method

Create a click listener that starts a Click to Pay activity. In the following example, a payment amount of $1 USD is requested. Note that the amount field is processed as the payment amount in cents. For example, passing a value of 100 asks for a payment of $1 USD.

startSecureRemoteCommerceButton = findViewById(R.id.pay_with_src_button); startSecureRemoteCommerce.setOnClickListener( (view) -> SecureRemoteCommerce.createPaymentDataRequest(this, new SecureRemoteCommerceParameters(100)) );
Link to section

Step 7: Get the SRC payment token in the onActivityresult method

The example compares the requestCode value to the SRC activity enumeration and if the values match, the token is obtained from the SDK by calling SecureRemoteCommerce.handleActivityResult and showing the token in a Toast message.

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == DEFAULT_SECURE_REMOTE_COMMERCE_REQUEST_CODE) { SecureRemoteCommerce.handleActivityResult(data, result -> { if (result.isSuccess()) { Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_LONG).show(); } else if (result.isError()) { Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_LONG).show(); } }); } }