1. Initialization
Initialize the SDK in your Application’sonCreate method. This only needs to be done once when your application starts. The SDK uses a singleton pattern for all interactions.
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.
2.2. Auto Close
By default, the checkout view will close automatically when the flow is complete. You can disable this behavior globally:Builder.
3. Usage
To start a checkout session, create aTransactBridge.Builder to configure listeners and session-specific settings. Then, call the open() method on the TransactBridge singleton instance.
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.
| 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.
| 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.
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 alaunchMode 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:
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. |