C/C++ ECR SDK
Purpose
The C/C++ ECR SDK provides the lowest‑level integration with two headers: SBCoreECR.h and EcrApi.h. It is intended for embedded or native Windows applications requiring direct control over terminal communication with Nami payment terminals.
Core Functions (SBCoreECR.h)
int pack(const char* inputReqData, int transactionType, const char* szSignature, unsigned char* szEcrBuffer);
int parse(const unsigned char* respData, unsigned char* szRespFields);
High-Level API (EcrApi.h)
int doTCPIPTransaction(char* ip, int port, char* request, int txnType, char* signature, char* response);
int doCOMTransaction(char* port, int baud, int parity, int databit, int stopbit, char* request, int txnType, char* signature, char* response);
int doBluetoothTransaction(char* btaddr, char* request, int txnType, char* signature, char* response);
Usage Example
#include "EcrApi.h"
int main() {
char response[4096] = {0};
int status = doTCPIPConnection("192.168.0.102", 8888);
if (status != 0) return -1;
doTCPIPTransaction("192.168.0.102", 8888, requestData, 17, signature, response); // Register (Legacy only)
doTCPIPTransaction("192.168.0.102", 8888, requestData, 18, signature, response); // Start Session (Legacy only)
doTCPIPTransaction("192.168.0.102", 8888, requestData, 0, signature, response); // Purchase
printf("Response: %s\n", response);
doDisConnection();
return 0;
}
Transaction Flow
doTCPIPTransaction() → doCOMTransaction() → doBluetoothTransaction()
⚠️ Legacy vs Adapter Separation
- Legacy ECR integrations require:
- Register Terminal (
txnType = 17) - Start Session (
txnType = 18)
- Register Terminal (
- Adapter/Middleware integrations (Local REST API, Cloud REST API) do not require registration or session steps.
Request and Response Details
When performing a transaction, include:
- Date (
ddMMyyHHmmss) - ECR Reference Number (String)
- Amount (Integer in halalas, e.g.,
100 = SAR 1.00)
Responses return:
- Response Code (Approved/Failed)
- Approval Code
- Receipt Data
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 11 days ago
