Android Package
Installation
To use the Paylink SDK in your Android project, follow these steps:
- In settings.gradle , put the following repository:
maven { url 'https://jitpack.io' }
For example:
dependencyResolutionManagement {
repositories {
....
....
maven { url 'https://jitpack.io' }
...
}
}
- Add the following to your build.gradle file:
dependencies {
...
implementation 'com.github.Paylink-sa:Paylink-mobile-android-sdk:1.1.1'
...
}
- Add the following required dependencies to your build.gradle
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.guava:guava:31.1-jre'
- Make sure the viewBinding feature is enabled in the build.gradle file.
buildFeatures {
viewBinding true
}
Usage
Initialization
Initialize the SDK with the environment.
import sa.paylink.sdk.android.plpaymentgateway.PaylinkGateway;
PLPaymentGateway paymentGateway = new PLPaymentGateway(Environment.TEST);
// Environment can be: Environment.TEST, Environment.DEV, or Environment.PRODUCTION
Generating an Invoice transaction no
An invoice should be created on the application's server-side by calling the addInvoice endpoint and then passing transactionNo to the client.
Parameters
transactionNo: this is same value of transactionNo received from calling addInvoice endpoint.
Opening Payment Form
Call openPaymentForm of the SDK to open the payment form:
// transactionNo is received from the backend server of the merchant.
paylinkGateway.openPaymentForm(transactionNo, context, new Callback<PLPaylinkCallbackData, APIError>() {
@Override
public void onSuccess(PLPaylinkCallbackData plPaylinkCallbackData) {
// this code will be called after the payment completed.
// PLPaylinkCallbackData has two properties:
// - getTransactionNo(): return transactionNo of the payment (Paylink unique #)
// - getOrderNumber(): return the order num of the payment (Merchant unique #)
System.out.println("Transaction No is: " + response.getTransactionNo());
System.out.println("Order Number is: " + response.getOrderNumber());
}
@Override
public void onError(APIError apiError) {
// this code will be called if there is any error during the payment.
}
});
Check order status
Pass the received transactionNo to your server side to check the order status using getInvoice endpoint (here).
Customized Payment Form URL:
Paylink usually opens the payment form based on Paylink's branding and look and feel. But what if the merchant or the developer using Paylink's SDK wants to design their payment form?
Here in Paylink, we enable developers to fully control the payment form using the initializing parameter "paymentFormUrl." Developers can set their payment form and pass their URL to the constructor of the class PaylinkGateway in the parameter "paymentFormUrl."
String paymentFormUrl = "https://merchant-website.com/mobile-payment-form.php";
this.paylinkGateway = new PaylinkGateway(this.environment, paymentFormUrl, "android");
Then, Paylink, during payment, will open the merchant's customized payment form instead of the default one.
Customized Payment Form Parameters:
During opening payment form, Paylink will pass two parameters to the customized payment form which are:
Field name Type Description transactionNo String A transaction no of the payment. platform String the platform of the device "android" or "ios" Example:
https://merchant-website.com/mobile-payment-form.php?transactionNo=123123123&platform=android
Sample of code
To download a sample of the code, click here
Updated 15 days ago