.NET ECR SDK
Purpose
The .NET ECR SDK uses P/Invoke to call the native ECR.dll for packing and parsing terminal messages. It provides a standardized API for Windows desktop POS applications, ensuring consistent request/response handling with Nami payment terminals.
Prerequisites
- Windows 10 or later
- .NET Framework 4.7.2+ or .NET 6+
ECR.dllplaced in the application output directory
InteroperableService Class
using System.Runtime.InteropServices;
public class InteroperableService
{
[DllImport("ECR.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int pack(
string inputReqData,
int transactionType,
string szSignature,
byte[] szEcrBuffer
);
[DllImport("ECR.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int parse(
byte[] respData,
byte[] szRespFields
);
}
TCP/IP Connection Example
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("192.168.0.102", 8888);
byte[] buffer = new byte[4096];
InteroperableService.pack(requestData, 17, signature, buffer); // Register (Legacy only)
socket.Send(buffer);
byte[] response = new byte[4096];
socket.Receive(response);
byte[] fields = new byte[8192];
InteroperableService.parse(response, fields);
string result = Encoding.UTF8.GetString(fields);
⚠️ 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
