> For the complete documentation index, see [llms.txt](https://docs.foloosi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.foloosi.com/mobile-sdk-integrations/android-sdk/initiate-payment.md).

# Initiate Payment

This Section briefs about how to initiate a payment !

Foloosi's Android SDK provides easy payment collections.

You can use it on the front-end to open payment page or use the actual flow to create Payment Token

#### Step - 1 - Add Dependency

We distribute our SDK from the Maven Central Repository. To begin with this SDK opens your build.gradle file of Module:app and adds the following dependency.

```
implementation 'com.foloosi:FoloosiSDK:2.0.28'
```

#### Step - 2 - Initialize SDK

To initialize the SDK add the codes below with the merchant key (Taken from foloosi merchant panel). If you do not have a merchant key create a new one and customize the checkout page to your liking.

{% code lineNumbers="true" %}

```java
 InitData initData = new InitData();
 initData.setMerchantKey(merchantKey); //YOUR MERCHANT KEY
 initData.setCustomColor(customColor); // SDK CUSTOM COLOR

 FoloosiPay.init(this, initData);
```

{% endcode %}

#### Step - **3** - Implement Payment Listener

Set and Implement our payment listener to receive payment results for every payment.

{% code lineNumbers="true" %}

```java
//Setting payment listener (paste this line after init() method)
FoloosiPay.setPaymentListener(this);
```

{% endcode %}

**Important Note** - You can Follow any one of the methods below to initiate payment widget.

### a. Make Payments via order object

#### &#x20;Create Order Data Object with Necessary Inputs

You can create the OrderData or payment input with our OrderData Model class. Here you need to provide order id, title, description, currency code, order amount and customer details like name, email and mobile number.

{% code lineNumbers="true" %}

```java
OrderData orderData = new OrderData(); // Foloosi Order Data Model Class Instance
orderData.setOrderAmount(Double.parseDouble(amount)); // in double format ##,###.##
Random rand = new Random();
int orderId = rand.nextInt(100000);
orderData.setOrderId(String.valueOf(orderId)); // unique order id. 
orderData.setOrderDescription("Mobile Phone");  // any description.
orderData.setCurrencyCode(currencyCode);
orderData.setCustomerUniqueReference(""); //Customer Unique Reference value should be email/mobile no/uniqueCustomer id from your DB
Customer customer = new Customer();
customer.setName("name");
customer.setEmail("email@gmail.com");
customer.setMobile("1234567890");
orderData.setCustomer(customer);
```

{% endcode %}

#### \*Important Note\*

orderData.setCustomerUniqueReference("") value **MUST** be customer id/email/mobile number for saved card feature.

Now make payments with order data you created above.

```
 FoloosiPay.makePayment(orderData);
```

### &#x20;b.Make Payments with reference token

#### Initialize api <a href="#initialize-api" id="initialize-api"></a>

## Get Reference Token

<mark style="color:green;">`POST`</mark> `https://api.foloosi.com/aggregatorapi/web/initialize-setup`

#### Headers

| Name                                          | Type   | Description                              |
| --------------------------------------------- | ------ | ---------------------------------------- |
| secret\_key<mark style="color:red;">\*</mark> | String | Your Merchant Key get from Foloosi Panel |

#### Request Body

| Name                                                  | Type   | Description                    |
| ----------------------------------------------------- | ------ | ------------------------------ |
| transaction\_amount<mark style="color:red;">\*</mark> | Double |                                |
| currency<mark style="color:red;">\*</mark>            | String |                                |
| customer\_unique\_identifier                          | String |                                |
| customer\_mobile                                      | String |                                |
| customer\_email                                       | String |                                |
| customer\_name                                        | String |                                |
| customer\_city                                        | String |                                |
| customer\_address                                     | String |                                |
| billing\_state                                        | String |                                |
| billing\_country                                      | String |                                |
| billing\_postal\_code                                 | String |                                |
| description                                           | String | Product or order information   |
| optional1                                             | String | You can pass additional fields |
| optional2                                             | String | You can pass additional fields |
| optional3                                             | String | You can pass additional fields |

{% tabs %}
{% tab title="200: OK success response" %}

```javascript
{
 "message": "Application setup successfully",
 "data": {
   "reference_token":
   "U0sjdGVzdF8kMnkkMTAkM21LRi0xZGliVDhldTV4NHlZSm9tZXZobnZxWTNEVnZmay1MdHNndTNFenNBTDU0clhWYkccVE4jRkxTQVBJNWM3Njk2ZDkwOWIzNxxSVCMkMnkkMTAkQXZ4ay9wdjlpTFlYLzRSZ2FjSkxpZWhHb2o0U0wvTFpZNXAyVjRGOVFycWNQZ2lHQ3VEZ08="
  }
 }
```

{% endtab %}

{% tab title="401: Unauthorized Invalid Api mode" %}

```javascript
{
    "message": "Invalid Integration settings! Kindly check both foloosi merchant application settings and your integration keys"
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid Header response" %}

```javascript
{
    "message": "Invalid secret key"
}
```

{% endtab %}

{% tab title="404: Not Found Invalid request type" %}

```javascript
{
    "message": "No routes found"
}
```

{% endtab %}
{% endtabs %}

Make the payment with order reference token.

```java
String referenceToken = "Your Reference Token";
FoloosiPay.makePaymentWithReferenceToken(referenceToken);
```

#### Api Specification <a href="#api-specification" id="api-specification"></a>

* Request call must be on **POST.**
* This Api will be used to confirm the feature you are about to Use.
* For **Saved Card Payment** Method, You need to pass your customer unique details like email,etc. to **customer\_unique\_identifier**.

**Post Request Body**

|                              |                                                                                                                                              |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| customer\_unique\_identifier | <ol><li>This is mandatory when you are using saved card payment.</li><li>This data must be Unique like email id,customer id, etc.,</li></ol> |

### Support

Visit <https://www.foloosi.com> for support requests or email to <tech@foloosi.com>.

## Developed by

Foloosi Technologies Pvt Ltd.

## License

Copyrights (c) 2025 Foloosi
