> ## Documentation Index
> Fetch the complete documentation index at: https://developer.transactbridge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# v1.0

This guide walks you through integrating the **TransactBridge Drop-in SDK** into your Android app using an AAR file.

## 1. Download the AAR

Download dropin.aar file by clicking on the link below

[Download dropin.aar](https://cdn.transactbridge.com/sdk/android/v1.0/dropin.aar)

## 2. Add the AAR to Your Project

1. **Create a `libs` directory:** In your Android project's `app` module, create a new folder named `libs` if it doesn't already exist. The path should be `app/libs/`.
2. **Place the AAR file:** Copy the `dropin.aar` file into the `app/libs/` directory.
3. **Update `build.gradle` (Module: app):**

   ```gradle theme={null}
   repositories {
       flatDir {
           dirs 'libs'
       }
   }
   dependencies {
       implementation fileTree(dir: 'libs', include: ['*.jar'])
       implementation(name: 'dropin', ext: 'aar')
   }
   ```

## 3. Declare Required Dependencies

Our SDK relies on `Gson` for JSON serialization/deserialization, `OkHttp` and `Volley` for network requests. It's crucial to include these as dependencies in your `app/build.gradle` to ensure compatibility and prevent runtime issues. Please use the exact versions specified by the SDK to avoid dependency conflicts.

```gradle theme={null}
dependencies {
    // ... other dependencies

    // TransactBridge SDK dependencies
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
}
```

## 4. Initialize the SDK

Initialize the SDK in your Application class or main Activity:

```java theme={null}
import com.transactbridge.sdk.PaymentSDK;
import com.transactbridge.sdk.Environment;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        PaymentSDK.initialize(this, "YOUR_PUBLISH_KEY", Environment.UAT); // Choose PRODUCTION, SANDBOX, or UAT
    }
}
```

## 5. Add Terms & Conditions View

In your layout XML:

```xml theme={null}
<com.transactbridge.sdk.view.TermsAndConditionsView
    android:id="@+id/upi_terms_and_conditions"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp" />
```

In your Activity or Fragment, obtain the unique ID:

```java theme={null}
TermsAndConditionsView termsAndConditionsView = findViewById(R.id.upi_terms_and_conditions);
String termsId = termsAndConditionsView.getUniqueId();
```

## 6. List Available UPI Apps

```java theme={null}
List<UpiApp> upiApps = PaymentSDK.getUpiApps(this);
if (upiApps.isEmpty()) {
    // Handle case where no UPI apps are found
} else {
    // Display the list of upiApps to the user
}
```

## 7. Generate Billing Session (Backend)

**Important:** The generation of the billing session, including the `billingSessionId` and `token`, involves sensitive API keys (`x-api-key`, `x-signature`) that **must not be exposed in your mobile application**. This process should be handled securely on your backend server. Your mobile application should call your backend, which then communicates with TransactBridge to obtain these details.

Your backend should make an API call to TransactBridge's `/billingSession/v1.0/generateBillingSession` endpoint. The response from this endpoint will contain the `billingSessionId` and `token` which your backend should then securely relay to your mobile application.

## 8. Launch UPI Payment

```java theme={null}
UpiPaymentRequest request = new UpiPaymentRequest(
        currentBillingSessionId,
        currentToken,
        termsId, // Obtained from TermsAndConditionsView.getUniqueId()
        0, // Sequence number (if applicable, otherwise 0)
        selectedUpiApp,
        1000L // Timeout in milliseconds
);

PaymentSDK.payUpi(this, request, new PaymentResultListener() {
    @Override
    public void onSuccess(PaymentResult result) {
        // Payment successful
        Toast.makeText(YourActivity.this, "Payment Success: " + result.getTransactionId(), Toast.LENGTH_LONG).show();
        // Further actions like verifying payment status with your backend
    }

    @Override
    public void onFailure(PaymentResult result) {
        // Payment failed
        String error = result.getError() != null ? result.getError().getMessage() : "Unknown error";
        Toast.makeText(YourActivity.this, "Payment Failed: " + error, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onCancel() {
        // User cancelled the payment
        Toast.makeText(YourActivity.this, "Payment Cancelled", Toast.LENGTH_LONG).show();
    }
});
```

## 9. Handling Payment Results

The `PaymentResultListener` provides callbacks for `onSuccess`, `onFailure`, and `onCancel`. Handle these outcomes appropriately:

* **onSuccess(PaymentResult result):** The payment was successful. You should typically verify this status with your backend before confirming the order or service to the user. The `result` object contains details like `transactionId`.
* **onFailure(PaymentResult result):** The payment failed. The `result` object will contain error details if available. Inform the user and guide them on next steps.
* **onCancel():** The user cancelled the payment flow. Inform the user that the payment was not completed.
