Java ECR SDK
Purpose
The Java ECR SDK provides a JNI wrapper for Java SE desktop environments. It enables merchant POS applications to communicate with Nami payment terminals using standardized APIs, without requiring developers to implement raw socket handling manually.
Prerequisites
- JDK 8 or later
- Windows 10 or later
- Native ECR library (
ECR.dll) placed injava.library.path
Transaction Example
import java.net.Socket;
import java.io.*;
public class EcrClient {
public static native int pack(String reqData, int txnType, String signature, byte[] buffer);
public static native int parse(byte[] response, byte[] fields);
public static void main(String[] args) throws Exception {
Socket socket = new Socket("192.168.0.102", 8888);
byte[] buffer = new byte[4096];
pack(requestData, 17, signature, buffer); // Register (Legacy only)
socket.getOutputStream().write(buffer);
byte[] resp = new byte[4096];
socket.getInputStream().read(resp);
byte[] fields = new byte[8192];
parse(resp, fields);
System.out.println("Result: " + new String(fields));
socket.close();
}
}
⚠️ 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)
- Date (
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
