> ## 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

## 1. Initialization

Initialize the SDK in your Application's `onCreate` method. This only needs to be done once when your application starts. The SDK uses a singleton pattern for all interactions.

```java theme={null}
import com.transactbridge.sdk.TransactBridge;
import android.app.Application;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the TransactBridge singleton
        TransactBridge.getInstance().initialize(this, TransactBridge.LogLevel.ERROR); // Or LogLevel.VERBOSE, LogLevel.NONE
    }
}
```

## 2. Configuration

You can configure the SDK instance after initialization.

### 2.1. Log Level

The SDK provides three log levels:

* `TransactBridge.LogLevel.VERBOSE`: Logs all messages.
* `TransactBridge.LogLevel.ERROR`: Logs only error messages. This is the default.
* `TransactBridge.LogLevel.NONE`: Disables all logging.

```java theme={null}
// Set the log level at any time
TransactBridge.getInstance().setLogLevel(TransactBridge.LogLevel.VERBOSE);
```

### 2.2. Auto Close

By default, the checkout view will close automatically when the flow is complete. You can disable this behavior globally:

```java theme={null}
TransactBridge.getInstance().setAutoClose(false);
```

You can also override this setting for a specific session using the `Builder`.

## 3. Usage

To start a checkout session, create a `TransactBridge.Builder` to configure listeners and session-specific settings. Then, call the `open()` method on the `TransactBridge` singleton instance.

```java theme={null}
import com.transactbridge.sdk.TransactBridge;
import com.transactbridge.sdk.listeners.*;
import android.os.Bundle;

// ... inside your Activity or Fragment

TransactBridge.Builder builder = new TransactBridge.Builder()
    .setTransactionListener(transactionData -> {
        // Handle transaction data
    })
    .setSessionListener(sessionData -> {
        // Handle session data
    })
    .setCloseListener(() -> {
        // Handle close event
    })
    .setErrorListener((errorCode, errorMessage, extras) -> {
        // Handle error
    })
    .setAutoClose(true); // Optional: Override global setting for this session

// Start the checkout session
TransactBridge.getInstance().open(this, "YOUR_CHECKOUT_URL", builder);
```

## 4. Event Handling

The SDK uses listeners to notify your application of events for a specific session.

### 4.1. TransactionListener

* `onTxnData(TransactionData transactionData)`: Called with transaction details.

**TransactionData**

| Method              | Description                                      |
| ------------------- | ------------------------------------------------ |
| `getTxnIds()`       | Returns a `List<String>` of transaction IDs.     |
| `getCheckoutData()` | Returns `CheckoutData` with payment method info. |

### 4.2. SessionListener

* `onSessionData(SessionData sessionData)`: Called for session-related events.

**SessionData**

| Method        | Description                                      |
| ------------- | ------------------------------------------------ |
| `getStatus()` | Returns the status of the session as a `String`. |
| `getTbId()`   | Returns the TransactBridge ID as a `String`.     |
| `getType()`   | Returns the type of session event as a `String`. |

### 4.3. CloseListener

* `onClose()`: Called when the sdk is closed.

### 4.4. TransactBridgeErrorListener

* `onError(int errorCode, String message, @Nullable Bundle extras)`: Called when an error occurs.

The `errorCode` provides a specific reason for the error.

| Error Code                   | Value | Description                                                                                                     |
| ---------------------------- | ----- | --------------------------------------------------------------------------------------------------------------- |
| `ERROR_INTENT_LAUNCH_FAILED` | 1001  | Failed to launch an external application, such as a UPI or other payment app.                                   |
| `ERROR_WEBVIEW_LOAD_FAILED`  | 1002  | The WebView failed to load the checkout page due to a network error, SSL issue, or other configuration problem. |
| `ERROR_INVALID_URL`          | 1003  | The URL provided when opening the checkout session was invalid.                                                 |

### 4.5. Advanced Event Handling

The SDK handles several types of events automatically to provide a smooth user experience.

* **URL Redirection**: When a user action in the checkout flow needs to navigate to an external webpage, the SDK automatically opens it in a secure Chrome Custom Tab. This keeps the user within the context of your app while providing a full browser experience.
* **Intent Redirection**: For payment methods that require invoking another app (like a UPI payment app), the SDK will automatically fire the necessary Android Intent to switch to that app.
* **Invoice Downloads**: If the checkout process provides an invoice for download, the SDK will handle the download intent to allow the user to save the invoice.

### 4.6. Deep Link Configuration

The SDK has built-in support for handling deep links. If your app's Activity that integrates the TransactBridge SDK uses a `launchMode` other than `standard` (e.g., `singleTop`, `singleTask`, or `singleInstance`), you must forward deep link intents to the SDK.

In your Activity, override the `onNewIntent` method and pass the `Intent` to the `TransactBridge.handleDeepLink()` method:

```java theme={null}
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    TransactBridge.handleDeepLink(intent);
}
```

## 5. API Reference

### TransactBridge Singleton

| Method                                          | Description                                                                                                                                                                                                                                                       |
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getInstance()`                                 | Returns the singleton instance of the SDK.                                                                                                                                                                                                                        |
| `initialize(Context, LogLevel)`                 | Initializes the SDK. Should be called once.                                                                                                                                                                                                                       |
| `setLogLevel(LogLevel)`                         | Sets the log level for the SDK.                                                                                                                                                                                                                                   |
| `setAutoClose(boolean)`                         | Enables or disables automatic closing globally.                                                                                                                                                                                                                   |
| `open(Context, String, TransactBridge.Builder)` | Opens the checkout flow with session-specific listeners and settings.                                                                                                                                                                                             |
| `close()`                                       | Manually closes the `sdk`. (Static method) **Note:** To prevent potential deadlocks, you should not call `TransactBridge.close()` from within the `SessionListener.onSessionData()` callback. The SDK will ignore any `close()` requests made from this callback. |

### TransactBridge.Builder

The builder is used to configure a single checkout session.

| Method                        | Description                                                        |
| ----------------------------- | ------------------------------------------------------------------ |
| `setTransactionListener(...)` | Sets the `TransactionListener` for the session.                    |
| `setSessionListener(...)`     | Sets the `SessionListener` for the session.                        |
| `setCloseListener(...)`       | Sets the `CloseListener` for the session.                          |
| `setErrorListener(...)`       | Sets the `TransactBridgeErrorListener` for the session.            |
| `setAutoClose(boolean)`       | Overrides the global auto-close setting for this specific session. |
