---
agentTools:
  projectIndex: https://aamarpay.readme.io/llms.txt
---

# Android Library

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:

```xml build.gradle
allprojects {  
  repositories {  
    ...  
    maven { url '<https://jitpack.io'> }  
  }  
}
```

* Add the following line to your "android" section of your build script:

```java Android
compileOptions {  
  sourceCompatibility JavaVersion.VERSION_1_8  
  targetCompatibility JavaVersion.VERSION_1_8  
}
```

* Add the following line to your "*dependencies*" section of your build script:

```java Dependencies
dependencies {  
  implementation 'com.github.aamarpay-dev:aamarPay-Android-Library:1.1'  
}
```

# Permission

* Add this permission into your "*AndroidManifest.xml*" file:

```xml
<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.

```java
 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**

```java

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

```java
 aamarPay.autoGenerateTransactionID(true);
```

If you set the "*autoGenerateTransactionID(false)*" then you need to set the transaction ID manually by "*setTransactionID(String)*"

```java
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)*"

```java
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.

```java
aamarPay.setTransactionParameter("Transaction Amount", "Transaction Currency", "Payment Description");
```

Call "*setCustomerDetails(String, String, String, String, String, String)*" to set the customer details.

```java
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)*"

```java
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

```java
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.

```java
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

1. Create Instance of aamarPay.
2. Set the test mode option.
3. Set the transaction id preference.
4. Set the transaction parameter.
5. Set the customer details.
6. Init PGW.

# Dialog Builder

You can use the dialog builder to generate loading or error message popup as below.

[block:html]
{
  "html": "<table>\n  <tr style=\"border: none;\">\n    <td style=\"border: none;\"><img src=\"https://files.readme.io/471cf93-PGW_LOADING.jpeg\"/></td>\n    <td style=\"border: none;\"><img src=\"https://files.readme.io/0f193ad-PGW_ERROR.jpeg\"/></td>\n    \n  </tr>\n</table>"
}
[/block]

To use this, create an instance first, then call the popup as required.

```java
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.
>
> #### <b>Base URL :</b> <https://sandbox.aamarpay.com>
>
> #### <b>Store ID :</b> aamarpaytest
>
> #### <b>Signature Key :</b> dbb74894e82415a2f7ff0ec3a97e4183

> ℹ️ Obtain Live Credentials
>
> For acquiring the necessary live credentials to process payments, please don't hesitate to contact our Support Team at <support@aamarpay.com.> 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](mailto:integration@aamarpay.com) for assistance.