iOS SDK (Swift)
Full contract reference: see clients/CONTRACT.md in the backend repo.
Installation
// Package.swift
.package(path: "../clients/ios")
// Then depend on the "OneMyPosMate" productQuick Start
let client = OneMyPosMateClient(
baseUrl: "https://payus.co.nz",
system: "pos"
)
let resp = try await client.payments.payNow(
PayNowRequest(
grandTotal: "10.00",
referenceId: "REF-001",
branchId: 17,
configId: 123,
channel: "WECHAT"
)
)Authentication Flow
// 1. Activate (one-time)
try await client.auth.activate(activationCode: "ABC123")
// 2. Token cached in Keychain (KeychainTokenStore)
// Every call auto-refreshes if within 60s of expiry
let token = try await client.auth.currentToken()
// 3. Actor-isolated single-flight Task prevents concurrent refreshesError Handling
do {
try await client.payments.payNow(request)
} catch let error as OneMyPosMateError {
switch error.errorCode {
case .ERR_GATEWAY_NOT_FOUND: // Terminal not configured
case .ERR_DUPLICATE_TRANSACTION: // referenceId reused
case .ERR_UNAUTHORIZED: // Token expired, SDK auto-retried
default: break
}
}Common Error Codes
| Code | HTTP | Meaning |
|---|---|---|
| ERR_GATEWAY_NOT_FOUND | 422 | Terminal gateway not configured |
| ERR_DUPLICATE_TRANSACTION | 409 | referenceId already used |
| ERR_REFUND_EXCEEDED | 400 | Refund amount > remaining balance |
| ERR_UNAUTHORIZED | 401 | Token expired (SDK auto-retries once) |
| ERR_FORBIDDEN | 403 | Tenant isolation violation |
| ERR_RATE_LIMITED | 429 | Too many requests |
| ERR_SYSTEM_ERROR | 500 | Server error (SDK retries 3x) |