.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.dll placed 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)
  • 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