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 in java.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)
  • 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

CodeTransaction Type
0Purchase
1Purchase with Naqd/Cashback
2Refund
3Authorization
4Purchase Advice (Full)
5Purchase Advice (Partial)
6Auth Extension
7Auth Void
9Cash Advance
10Reconciliation
11Reversal
15Bill Payment
17Register (Legacy only)
18Start Session (Legacy only)
19End Session
23Duplicate / Previous Txn
24Check Status
25Health Check