Xen BRI SDK to Terminal Gateway SDK
This comprehensive guide walks you through migrating your Android application from the standalone Xen BRI SDK (version 0.3.1) to the new Terminal Gateway SDK (version 0.4.0) and Terminal API (version 0.4.1). The new architecture provides better integration with the Xendit In-Person Payment platform and supports multiple terminal providers.This migration involves significant architectural changes. We recommend testing thoroughly in your development environment before deploying to production.
Overview of Changes
The new architecture separates the concerns of direct terminal communication (handled by the Terminal Gateway SDK) and payment session management (handled by the Terminal API). This provides a more unified approach for different terminal providers and better integration with the Xendit In-Person Payment platform. Key Changes:- SDK Consolidation: The
XenBriTerminalSDK is replaced by theTerminal Gateway SDK, which acts as a common interface for various terminal providers (e.g.,TerminalBRI). - API for Payment Sessions: Instead of direct
saleIntentcalls from the SDK, payment sessions are now managed via the Terminal API. - Simplified Connection Management: Device registration and connection state observation are now handled more uniformly through the
TerminalGateway. - Unified Error Handling: Error codes are standardized across the Terminal Gateway SDK.
Migration Steps
1
Update SDK Dependencies
Remove the old New Dependencies (to add):Also, ensure your project’s
Xen BRI SDK dependency and add the new Terminal Gateway SDK dependencies in your module’s build.gradle file.Old Dependency (to remove):build.gradle or settings.gradle has the maven local repository:2
Initialize the SDK
The initialization process changes from New Initialization:
XenBriTerminal.initialize() to TerminalApp.initialize() and TerminalGateway.addProvider().Old Initialization:Client Key: Note that for the Terminal API, you will need an
API_KEY from the Xendit In-Person Payment team, which is different from the CLIENT_KEY used in the SDK initialization. The TerminalApp.initialize still uses a CLIENT_KEY.TerminalMode: The
XenTerminalMode enum is replaced by TerminalMode. Use TerminalMode.INTEGRATION for testing with physical terminals and TerminalMode.LIVE for production. TerminalMode.SIMULATION is no longer available directly in the TerminalApp.initialize method; instead, you would create payment sessions with appropriate simulation parameters via the Terminal API if needed.3
Register Terminal Devices
Instead of New Device Registration:The new
XenBriTerminal.useWifi() or XenBriTerminal.useBluetooth(), you now register devices using TerminalGateway.registerDevice().Old Device Connection (Example for WiFi):registerDevice method allows you to register multiple terminals at once and provides error feedback for invalid device details. For obtaining TID and IP address for BRI terminals, the process remains the same (BRI FMS App for TID, ECRLink app for IP address).4
Create Payment Transactions
The New Payment Creation (High-Level Flow):
saleIntent method is replaced by a two-step process:- Create a Payment Session via Terminal API: Your backend (or a direct API call from your app if applicable) initiates a payment session with the Xendit’s Payment Terminal API.
- The SDK will then handle the interaction with the physical terminal to process the payment based on the created session.
- Your Application/Backend (using Terminal API):
- Make a POST request to
/v1/terminal/sessionsto create a payment session. - Endpoint:
https://terminal-dev.xendit.co(Development) orhttps://terminal.xendit.co(Live) - Headers:
Content-Type: application/jsonAuthorization: Basic <Base64Encode(API_KEY:)>Idempotency-key: A unique key for preventing duplicate requests.
- Request Body Example:
- Make a POST request to
- The API will return a
payment_session_id. The Terminal Gateway SDK on the terminal device, observing the commands from the API, will then initiate the payment process on the physical terminal.
- Terminal Gateway SDK (Observing Connection and Error States):
The Terminal Gateway SDK will automatically process the payment command received from the API for the registered terminal. Your app can observe the connection and error states to react to the payment flow.
5
Handle Optional Methods
The New (using Terminal API’s Push Operation Command - only supported for Indonesia’s BRI terminals):Your application/backend would make a POST request to The Terminal Gateway SDK would then receive this command and execute the print operation.New (using Terminal API’s Push Operation Command - only supported for Indonesia’s BRI terminals):Your application/backend would make a POST request to New (using Terminal API’s Void a Payment):Your application/backend would make a POST request to
Method: POST
Headers:
Terminal Gateway SDK provides new methods for these operations, often correlating with the Terminal API’s “Push Operation Command” functionality.Reprint Receipt
Old:/v1/terminal/commands.Settlement
Old:/v1/terminal/commands.Cancel Payment (Void Transaction)
Old:/v1/terminal/payments/:payment_id/void.Path: /v1/terminal/payments/:payment_id/voidMethod: POST
Headers:
Content-Type: application/jsonAuthorization: Basic <Base64Encode(API_KEY:)>
payment_id would be obtained from the response of the “Create Payment Session” or “Get Payment Session Detail” API calls.6
Observe Connection and Error States
The methods for observing connection and error states have been updated in the Terminal Gateway SDK.New:The connection states (The
Observing Connection State
Old:CONNECTED, DISCONNECTED, UNKNOWN, CONNECTING, CONNECTING_FAILED, UNSUPPORTED) are similar but are now part of the TerminalGateway and tied to a specific TerminalDevice.Observing Error State
Old: Error handling was integrated into thesaleIntent callback.New: A dedicated observeError method is available.Error Data Structure and Error Codes have been standardized and are detailed in the Terminal Gateway SDK for Android (Kotlin) documentation. Review these to update your error handling logic accordingly.7
Troubleshooting and Kiosk Mode
The troubleshooting section regarding “Unresponsive EDC Machine” and “No Response from SDK on EDC payment completion” remains relevant and similar in concept.For Kiosk mode, the recommendation to enable “POS only mode” by providing Terminal IDs to the Xendit EDC team remains valid. This ensures transactions are initiated via the SDK/API and not directly on the terminal.
Summary of Key Changes for BRI Terminals
| Feature / Method | Old Xen BRI SDK (0.3.1) | New Terminal Gateway SDK (0.4.0) + Terminal API (0.4.1) |
|---|---|---|
| SDK Dependency | implementation("co.xendit:xen_edc_sdk-android:0.3.0") | implementation("co.xendit.terminal:core:0.4.0")implementation("co.xendit.terminal:gateway:0.4.0")implementation("co.xendit.terminal:id-bri:0.4.0") |
| SDK Initialization | XenBriTerminal.initialize(context, CLIENT_KEY, XenTerminalMode.MODE) | TerminalApp.initialize(context, CLIENT_KEY, TerminalMode.MODE)TerminalGateway.addProvider(TerminalBRI) |
| Device Connection | XenBriTerminal.useWifi(TID, IP)XenBriTerminal.useBluetooth(context, TID) | TerminalGateway.registerDevice(listOf(TerminalDevice(TID, IP))) |
| Create Payment | XenBriTerminal.saleIntent(...) | API Call: POST /v1/terminal/sessions to create a payment session.SDK: Handles the initiated session automatically. |
| Void Payment | XenBriTerminal.cancelPaymentIntent(...) | API Call: POST /v1/terminal/payments/:payment_id/void |
| Reprint Receipt | XenBriTerminal.printReceiptIntent(...) | API Call: POST /v1/terminal/commands with command: PRINT_RECEIPT (Indonesia only) |
| Settlement | XenBriTerminal.settlementIntent(...) | API Call: POST /v1/terminal/commands with command: SETTLE (Indonesia only) |
| Observe Connection State | XenBriTerminal.observeConnection(...) | TerminalGateway.observeConnection(..., terminalDevice) |
| Observe Error State | Part of saleIntent callback | TerminalGateway.observeError(...) |
| Simulation Mode | XenTerminalMode.SIMULATION | Not directly in initialize. Use Terminal API for testing with real terminals in test mode. |