Skip to main content

Terminal H2H SDK for Android (Kotlin)

The Xendit’s Payment Terminal H2H Android SDK enables you to integrate secure payment processing into your Android applications. Connect to physical payment terminals and process transactions seamlessly using our Kotlin-based SDK.
This SDK works alongside the Terminal API to provide complete in-person payment functionality. You’ll use the Terminal API to create payment sessions and this SDK to interact with physical payment devices.

Version information

What’s new:
  • BRI payment method mapping: Fixed case sensitivity in BRI mapping logic. BRI payment methods (such as QRIS) now map correctly regardless of string casing.
What’s new:
  • Activity Lifecycle Management: Introduced TerminalActivityLifecycleObserver interface for reusable activity lifecycle tracking, intent queuing, and dispatch logic
  • Enhanced Provider App Launching: Refactored Atom and SHC provider app launchers with improved background app launch handling
  • Launch Failure Notifications: Added notification mechanism to prompt users when provider app launch fails while app is in background
  • Callback Interface: New TerminalAppLauncherCallback interface for custom handling of provider app launch failures
  • Improved Maintainability: Centralized lifecycle and launcher logic for better extensibility across different application contexts
What’s new:
  • Core Stability: Fixed activity tracking bug in TerminalApplication where paused activities were not properly removed from internal tracking list
What’s new:
  • Fixed casting issue on C2C request payload to improve compatibility and prevent runtime errors.
What’s new:
  • Added Cashup provider support for Indonesian terminals
What’s new:
  • Renamed class name TerminalGateway to TerminalH2H for better consistency
Breaking Change: Class name changed from TerminalGateway to TerminalH2H. Update your imports and references accordingly.
What’s new:
  • Fixed NTT payment method value maping to ensure correct provider selection
  • Updated BRI payment flow to validate transaction data before executing terminal actions
  • Added timeout configuration for card and QR transactions to auto-cancel and retry stalled requests
  • Added support to handle retry requests via /v1/terminal/sessions/{id}/retry endpoint
What’s new:
  • Added support for multiple concurrent device connections, enabling simultaneous transactions across different terminals
  • [BRI] Fixed status value handling in void and cancel API responses for improved transaction status accuracy
What’s new:
  • Introduced command ID handling for settlement operations
  • Enhanced retry logic with configurable attempt counts
  • Improved error handling and logging throughout the gateway service
Bug fixes and improvements:
  • Fix data mapping for terminal responses
  • [BRI] Enhanced status verification after transaction timeout for improved reliability
XenTerminal is the companion SDK to In-Person Payment Sessions API. This version provides core functionality for connecting to payment terminals and processing transactions.
The SDK follows semantic versioning. Breaking changes will bump the major version number.

Installation

Follow these steps to add the Terminal H2H Android SDK to your project.
1

Configure Gradle settings

Add mavenCentral() to your Gradle configuration so Gradle can resolve the SDK artifacts.
Verify mavenCentral() is available in the repository list used by your app module.
2

Add dependencies

Add the required dependencies to your build.gradle.kts or build.gradle file:
Provider-specific dependencies are optional and enable convenient helper methods for creating TerminalDevice instances. Include only the dependencies for providers you plan to use.
Sync your project to download the dependencies.

Getting Started

Before you begin, ensure you have the following:
  • Client key: Request an In-Person Payment CLIENT_KEY from the Xendit team
  • Terminal device information: Obtain the Terminal ID and IP address for each device
  • Android project: Set up with minimum SDK version 21 (Android 5.0)
Keep your client key secure and never commit it to version control. Use environment variables or secure storage for production applications.

Step 1: Initialize the SDK

Initialize the Terminal H2H SDK in your Application class:
MyApp.kt
Use TerminalMode.INTEGRATION for development and testing. Switch to TerminalMode.LIVE for production with a live client key.

Step 2: Add Terminal Providers

Add the specific terminal providers you need for your integration:
For Share Commerce (SHC), Cashup, and Atom terminals, you do not need to add a Terminal H2H provider. Those devices run terminal logic through the Gateway app installed on the hardware. If the app is missing, install it from the Gateway download page or contact inpersonpayments@xendit.co for assistance.
Required dependency:
BRI provider supports timeout configuration for card and QR transactions, and provides enhanced transaction retry capabilities.
After adding providers, they will be available for use when registering terminal devices in the next step.

Step 3: Register Terminal Devices

Create TerminalDevice entries for each terminal and register them with the gateway:
For steps to locate each terminal’s Terminal ID and IP address, review the Finding Terminal Information guide.
Set active = true for terminals that should be available immediately. You can keep an entry with active = false to stage devices without establishing a connection.
After successful registration, your terminal devices will be available for payment processing.

Step 4: Calling Terminal API

With Terminal H2H SDK configured, you can now process payments using the Terminal API. The SDK handles communication with physical terminals through the local gateway service.
For complete API documentation including request/response formats, error handling, and advanced features, see the Terminal API (H2H) documentation.
The Terminal H2H SDK automatically manages the connection to your registered terminal devices and handles communication protocols for different providers.
You’re now ready to process payments using the Terminal H2H SDK integrated with Terminal API.

Configuring App for Terminal Device

When running your application on a Terminal device, additional configuration is required to enable the terminal to communicate with the Cashup payment system. Follow these steps:
1

Configure AndroidManifest.xml

Add the Cashup result activity to your AndroidManifest.xml file:
AndroidManifest.xml
The android:exported="true" attribute is required to allow the Cashup system to return results to your application.
2

Configure Application Class

Choose one of the following approaches to configure your Application class:
Make your Application class extend TerminalApplication and configure the Cashup provider launcher:
Application.kt
Don’t forget to register your custom Application class in the AndroidManifest.xml:
AndroidManifest.xml
Your app is now configured to run on Cashup Terminal devices and can communicate with the Cashup payment system.
3

Configure Receipt Printing

Control whether the terminal prints a receipt after a transaction:
This setting allows you to control the default receipt printing behavior for Cashup terminals.

Configuration and Management

Set Operation Timeout

Configure the timeout for terminal operations:
The default timeout is 5 minutes. Use the type-specific methods to override card vs QR timeouts when needed.
This timeout configuration is only available for the BRI provider. Other terminal providers use their own internal timeout settings.

Restart Terminal Connection

Manage and restart terminal service connections:
Call the method without parameters to restart all connections and tasks:

Monitor Connection State

Observe terminal connection states in real-time:
Use the observeConnection method with a coroutine scope:

Connection States

Monitor Error States

Observe and handle errors across all terminal devices:

Error Handling

Error Data Structure

All errors returned by the Terminal H2H SDK follow this structure:

Error Codes Reference

Error Handling Best Practices

Implement comprehensive error handling for robust payment processing:
Always implement retry logic for transient errors like TERMINAL_BUSY and FAILED_TO_CONNECT. Use exponential backoff to avoid overwhelming the terminal.

Troubleshooting

For more recovery scenarios across H2H and C2C terminal flows, see the SDK Troubleshooting Guide.

Common Issues and Solutions

Problem: The EDC (Electronic Data Capture) machine becomes unresponsive or stops processing transactions.Solution:
  1. Restart the EDC machine by holding the power button and selecting “Restart”
  2. Wait for the device to fully boot up and reconnect
  3. Verify the terminal is back online using the connection monitoring features
Always ensure the EDC is properly restarted before attempting new transactions to avoid data corruption.
Problem: Unexpected behaviors or unauthorized access to terminal functions.Solution:
  1. Ensure all transactions are initiated only through the SDK
  2. Contact the Xendit EDC team to enable POS-only mode for your Terminal IDs
  3. Configure terminal settings to disable manual transaction entry
POS-only mode prevents manual transaction entry and ensures all operations go through your application.
Problem: EDC fails to send transaction results to the SDK after payment completion.Solution:
  1. Query the Payment Session using the Terminal API to retrieve the latest status
  2. Check network connectivity between the EDC and your application
  3. Verify the callback URL configuration in your payment session
  4. Implement retry logic for failed status updates
Problem: Transaction appears stuck or you don’t receive a callback after the terminal prints a receipt, indicating the transaction may be incomplete.
This troubleshooting section applies only to BRI terminals.
Solution: Call the Terminal API retry endpoint to request the app check the transaction status and redo the transaction if it’s incomplete:
The retry endpoint /v1/terminal/sessions/{id}/retry instructs the app to verify the current transaction status with the terminal and automatically redo the transaction if it’s found to be incomplete.
Use this retry mechanism when you see a receipt printed but haven’t received a callback, as it may indicate the transaction didn’t complete successfully on the terminal side.
Problem: Unable to establish or maintain connection with terminal devices.Solutions:
  • Check network connectivity: Ensure both devices are on the same network
  • Verify IP addresses: Confirm terminal IP addresses are correct and accessible
  • Firewall settings: Check if firewall is blocking the connection ports
  • Terminal status: Ensure the terminal is powered on and in ready state
  • SDK initialization: Verify client key and terminal configuration
Use the connection monitoring features to diagnose specific connection issues.

Finding Terminal Information

1

Find Terminal ID (TID)

Open the BRI FMS app on the terminal device and locate the Terminal ID in the device information section.
BRI terminal showing Terminal ID in FMS app
2

Find IP Address

Open the ECRLink app on the terminal and check the network settings for the IP address.
BRI terminal showing IP address in ECRLink app
Screenshots and UI layouts may vary by firmware or app version. Refer to the latest vendor documentation if the interface differs from these instructions.