React Native ECR SDK
Purpose
The React Native ECR SDK provides cross‑platform integration for Android and iOS applications. It wraps the native ECR SDKs to expose JavaScript APIs, enabling developers to build POS apps in React Native without directly handling native socket communication.
Prerequisites
- React Native 0.64+
react-native-ecr-sdkpackage installed- Native Android/iOS SDKs configured in the project
Installation
NPM
npm install react-native-ecr-sdk
TCP/IP Connection Example
JavaScript
import { TransactionManager } from 'react-native-ecr-sdk';
const tcp = TransactionManager();
let status = await tcp.connectTCP("192.168.0.102", 8888, "ECR001");
tcp.doTransaction({
reqData: requestString,
txnType: 0, // Purchase
signature: signatureData,
listener: {
onEvent: (event) => console.log("Event:", event),
onSuccess: (response) => console.log("Success:", response),
onFailure: (error, code) => console.log("Error:", error, code),
}
});
tcp.disconnect();
App‑to‑App Connection Example (Android Only)
JavaScript
const a2a = TransactionManager();
let status = await a2a.connect("ECR001");
a2a.doTransaction({
reqData: requestString,
txnType: 0, // Purchase
signature: signatureData,
listener: {
onEvent: (event) => console.log("Event:", event),
onSuccess: (response) => console.log("Success:", response),
onFailure: (error, code) => console.log("Error:", error, code),
}
});
Transaction Flow
connectTCP() / connect()
→ Register (17)
→ Start Session (18)
→ doTransaction()
→ Listener
⚠️ Legacy vs Adapter Separation
- Legacy ECR integrations require Register (17) and Start Session (18).
- Adapter/Middleware integrations (Local REST API, Cloud REST API) do not require these steps.
Request and Response Details
When performing a transaction, include:
Request Fields
- Date (
ddMMyyHHmmss) - ECR Reference Number
- Amount (Integer in halalas, e.g.,
100 = SAR 1.00) - Signature (
SHA‑256 hash)
Response Fields
- Response Code (Approved/Failed\
- Approval Code
- Receipt Data
- Transaction Metadata (RRN, Auth Code, TID, MID, Batch No, Scheme Label, Merchant Info in English + Arabic, ECR Reference, Signature)
Transaction Type Codes
| Code | Transaction Type |
|---|---|
| 0 | Purchase |
| 1 | Purchase with Naqd/Cashback |
| 2 | Refund |
| 3 | Authorization |
| 4 | Purchase Advice (Full) |
| 5 | Purchase Advice (Partial) |
| 6 | Auth Extension |
| 7 | Auth Void |
| 9 | Cash Advance |
| 10 | Reconciliation |
| 11 | Reversal |
| 15 | Bill Payment |
| 17 | Register (Legacy only) |
| 18 | Start Session (Legacy only) |
| 19 | End Session |
| 23 | Duplicate / Previous Txn |
| 24 | Check Status |
| 25 | Health Check |
Updated 10 days ago
