An Android library for integrating aamarpay payment gateway
This guide provides step-by-step instructions for integrate the aamarPay payment module for Android. The aamarPay module allows you to integrate aamarPay payment gateway into your android system.
Installation
- Add the JitPack repository to your build file. Add it in your root "build.gradle" at the end of repositories:
allprojects {
repositories {
...
maven { url '<https://jitpack.io'> }
}
}
- Add the following line to your "android" section of your build script:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- Add the following line to your "dependencies" section of your build script:
dependencies {
implementation 'com.github.aamarpay-dev:aamarPay-Android-Library:1.1'
}
Permission
- Add this permission into your "AndroidManifest.xml" file:
<uses-permission android:name="android.permission.INTERNET"/>
Usage
aamarPay android library includes aamarPay payment gateway and custom dialog builder. First you need to create the instance of aamarPay Payment Gateway with store id and signature key.
AamarPay aamarPay = new AamarPay(this, STORE_ID, SIGNATURE_KEY);
To use the library in sandbox mode, you need to set "testMode(Boolean)" to true.
If you make it false, gateway will be inititalized in Live Mode
aamarPay.testMode(true);
For testing purposer, you need to provide SANDBOX store id and signature key. For live mode you need to provide the store id and signature key provided by your KAM (Key Account Manager).
If you want the to auto generate the transaction id, you can set the parameter "aamarPay.autoGenerateTransactionID(Boolean)" to true. Then the transaction id will be generated by aamarPay
aamarPay.autoGenerateTransactionID(true);
If you set the "autoGenerateTransactionID(false)" then you need to set the transaction ID manually by "setTransactionID(String)"
aamarPay.setTransactionID("TRXUHDU");
You can also get an unique transaction id by calling "generate_trx_id()" and then you can pass it to "setTransactionID(String)"
aamarPay.generate_trx_id()
This will return an unique id every time.
Next step is to set the transaction parameter and customer details. Call "setTransactionParameter(String, String, String)" to set the transaction parameter.
aamarPay.setTransactionParameter("Transaction Amount", "Transaction Currency", "Payment Description");
Call "setCustomerDetails(String, String, String, String, String, String)" to set the customer details.
aamarPay.setCustomerDetails("Customer Name", "Customer Email", "Customer Phone", "Customer Address", "Customer City", "Customer Country");
After setting up all the required parameter, you need to call "initPGW(Listener)"
aamarPay.initPGW(new AamarPay.onInitListener() {
@Override
public void onInitFailure(Boolean error, String message) {
// You will get the response, if payment gateway initialization is failed.
}
@Override
public void onPaymentSuccess(JSONObject jsonObject) {
// You will get the payment success response as a JSON callback
}
@Override
public void onPaymentFailure(JSONObject jsonObject) {
// You will get the payment failed response as a JSON callback
}
@Override
public void onPaymentProcessingFailed(JSONObject jsonObject) {
// You will get the payment processing failed response as a JSON callback
}
@Override
public void onPaymentCancel(JSONObject jsonObject) {
// You will get the payment cancel response as a JSON callback
}
});
To access the data from jsonobject, you can call the following method
try {
jsonObject.getString("trx_id");
} catch (JSONException e) {
e.printStackTrace();
}
If somehow you miss the JSON Response, then you can call the transaction verification API to get the transaction data. You need to pass the trx id with the method.
aamarPay.getTransactionInfo("TRANSACTION_ID", new AamarPay.TransactionInfoListener() {
@Override
public void onSuccess(JSONObject jsonObject) {
// You will get the json response here.
}
@Override
public void onFailure(Boolean error, String message) {
// You will get the error message here, if request fails.
}
});
Mandatory Steps
- Create Instance of aamarPay.
- Set the test mode option.
- Set the transaction id preference.
- Set the transaction parameter.
- Set the customer details.
- Init PGW.
Dialog Builder
You can use the dialog builder to generate loading or error message popup as below.
To use this, create an instance first, then call the popup as required.
AlertDialog alertDialog;
DialogBuilder dialogBuilder = new DialogBuilder(this, alertDialog);
// Show loading
dialogBuilder.showLoading();
// Error popup
dialogBuilder.errorPopUp("Error Message");
// To dismiss popup
dialogBuilder.dismissDialog();
Sandbox Environment
All operations conducted in this environment are considered as trial transaction.
Base URL : https://sandbox.aamarpay.com
Store ID : aamarpaytest
Signature Key : dbb74894e82415a2f7ff0ec3a97e4183
Obtain Live Credentials
For acquiring the necessary live credentials to process payments, please don't hesitate to contact our Support Team at [email protected]. They are readily available to guide you throughout the procedure and provide the essential credentials to facilitate live payment transactions on your platform.
Congratulations! You have successfully integrate the aamarPay payment module for your Android system.Your customers can now make payments using the aamarPay payment gateway.
If you encounter any issues during the installation or configuration process, please reach out to integration support team for assistance.