Skip to main content

Android SDK

Initialization

To integrate the Android SDK into your application, you first need to initialize it in your Application class or main Activity. This is usually done once:

import com.gini.rtp.androidsdk.RequestToPaySDK;

public class MyApp extends Application {

@Override
public void onCreate() {
super.onCreate();

// Initialize the SDK
RequestToPaySDK.initialize(getApplicationContext());
}
}

Configuration

After you initialize it, the SDK needs to be configured before is rendered on the screen. The reason for this, is that you need to have the bearer token as explained on the recipe:

RequestToPaySDK.Config config = new RequestToPaySDK.Config();
config.setBearerToken("BearerToken"); //Obtained in the authentication step
config.setEnvironment(RequestToPaySDK.Environment.PRODUCTION); // This is for testing purposes only

RequestToPaySDK.configure(config);

Displaying and Using the Request To Pay Button

First, you need to add and configure the button to your layout file. Here's a sample XML layout:

<com.gini.rtp.androidsdk.RequestToPayButton
android:id="@+id/requestToPayButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/red"
android:text="Request Payment"/>

Merchants must set up the code that the button must run once the customer clicks on the button in order to start the payment. It's needed to communicate with the Merchant's server in order to initiate the payment via an Api to Api call due to security reasons, as explained on the mobile recipe. For this, you can grab your button from your Activity or Fragment, and set the listener's code as follows:

RequestToPayButton button = findViewById(R.id.requestToPayButton);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// It's needed to call merchant's API in order
// to initiate the backend to backend RTP payment

// Once the paymentRequestId is returned, the
// payment can be initiated via our SDK method
// as follows
button.initPayment(paymentRequestId);
// Your clients bank application will be opened via deeplink
}
});