Skip to main content

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.
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.
// 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:
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.
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
MethodDescription
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
MethodDescription
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 CodeValueDescription
ERROR_INTENT_LAUNCH_FAILED1001Failed to launch an external application, such as a UPI or other payment app.
ERROR_WEBVIEW_LOAD_FAILED1002The WebView failed to load the checkout page due to a network error, SSL issue, or other configuration problem.
ERROR_INVALID_URL1003The 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.
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:
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    TransactBridge.handleDeepLink(intent);
}

5. API Reference

TransactBridge Singleton

MethodDescription
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.
MethodDescription
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.