App‑to‑App Integration
The Android App‑to‑App integration uses Intent‑based communication between your ECR application and the mada app installed on the same device. This allows transactions to be initiated and results returned without direct socket programming.
For integration steps, refer to App-to-App Integration.
Prerequisites
- Android 8.0 (API level 26) or higher
- mada app installed on the same device
- Valid ECR Reference Number
- Proper Android permissions configured (
INTERNET,BROADCAST, etc.) - Your app registered to send and receive broadcast intents
Library Import
Add the App‑to‑App integration dependency and import the required classes.
Kotlin
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.IntentFilter
Core Components
Use the SDK’s broadcast‑based integration to build and parse transaction data.
- Intent (TRANSACTION) – Send transaction request to mada app.
- BroadcastReceiver – Capture transaction response from mada app.
- Request Fields –
txnType,amount,ecrRefNo. - Response Fields –
responseCode,approvalCode,rrn. - Transaction Codes – Numeric codes for Purchase, Refund, Advice, etc.
Permissions (Manifest Example)
Add the following entries to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Integration Example
Kotlin
// Send transaction via broadcast
val intent = Intent("com.nami.payment.TRANSACTION")
intent.putExtra("txnType", 0) // Purchase
intent.putExtra("amount", "100")
intent.putExtra("ecrRefNo", "REF001")
// Add signature for security
val signature = EncryptionUtil.getSha256Hash(ecrUnique, terminalId)
intent.putExtra("signature", signature)
sendBroadcast(intent)
// Register receiver for response
val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val response = TransactionResponse(
responseCode = intent.getStringExtra("responseCode"),
approvalCode = intent.getStringExtra("approvalCode"),
rrn = intent.getStringExtra("rrn")
)
// Handle response object here
}
}
registerReceiver(receiver, IntentFilter("com.nami.payment.RESPONSE"))
Response Parsing Example
Kotlin Data Class
data class TransactionResponse(
val responseCode: String?,
val approvalCode: String?,
val rrn: String?
)
Error Handling
- mada app not installed → Broadcast fails silently. Prompt user to install mada app.
- Timeouts → If no RESPONSE intent within expected time, retry or fall back to TCP/IP.
- Missing fields → Validate response before processing; abort if null.
Security & Signatures
- Always generate a SHA‑256 signature using CRN and terminal ID before sending requests.
- Validate CRN and transaction reference numbers to prevent replay or tampering.
Configuration Persistence
- Connection parameters (CRN, transaction type, amount) are defined at runtime in the client code.
- No external JSON configuration file is required.
- App‑to‑App requires mada app installed and a broadcast receiver registered to capture responses.
Runtime Behaviors
- The SDK manages communication through Android broadcast intents.
- Establish session by sending a TRANSACTION Intent.
- mada app processes the payment.
- Receive terminal response via RESPONSE Intent.
- Parse response fields in your app.
- Unregister the broadcast receiver after transaction completion.
Transaction Flow
Initialize App → Configure POS → Register Broadcast Receiver → Send TRANSACTION Intent → mada app processes card payment → RESPONSE Intent returned → Your App receives transaction result → Parse Response
Updated about 1 month ago
