iOS ECR SDK

Purpose

The NamiECRSDK framework provides native Swift/Objective‑C integration for iOS and iPadOS applications. It enables secure communication with Nami payment terminals over TCP/IP (Wi‑Fi) or Bluetooth, using callback‑based communication rather than raw socket handling.

Prerequisites

  • macOS with Xcode 14+
  • Swift 5.7+
  • iOS 13.0 or later
  • Nami terminal connected via Wi‑Fi

Connection Example

import NamiECRSDK

class PaymentManager: SocketConnectionDelegate {
    func connectToTerminal() {
        ECRDataManager.shared.connectionMode = .tcpip
        ECRDataManager.shared.cashRegisterNumber = "ECR001"
        ECRTransactionManager.shared.connectTCP(
            ip: "192.168.0.102",
            port: 8888,
            delegate: self
        )
    }
    
    func didConnect() { print("Connected") }
    func didDisconnect() { print("Disconnected") }
    func didFailToConnect(error: Error) { print("Error: \(error)") }
}

Performing Transactions

ECRTransactionManager.shared.doTransaction(
    dataArray: [date, ecrRefNo, amount] as NSArray,
    selectedTransactionType: 0, // Purchase
    onCompletion: { success, response in
        print(success ? "Approved" : "Declined")
    }
)

Transaction Flow

connectTCP() → Register (17) → Start Session (18) → doTransaction() → onCompletion

⚠️ Legacy vs Adapter Separation

  • Legacy ECR integrations require Register (17) and Start Session (18).
  • Adapter/Middleware integrations (Local REST API, Cloud REST API) do not require these steps.

Request and Response Details

  • Date (ddMMyyHHmmss)
  • ECR Reference Number
  • Amount (Integer in halalas, e.g., 100 = SAR 1.00)

Responses return:

  • Response Code (Approved/Failed)
  • Approval Code
  • Receipt Data

⚠️ Bluetooth Limitations

  • Supported only on iOS 13+
  • Requires successful device pairing before SDK connection
  • Only one terminal can be paired per iOS device at a time
  • Sessions may drop under poor signal conditions; TCP/IP is recommended for production
  • Advanced flows (refunds, reversals) are not supported over Bluetooth
  • Some terminals require updated firmware for stable Bluetooth sessions

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