Web SDK (TypeScript)
Full contract reference: see clients/CONTRACT.md in the backend repo.
Installation
npm install @onemyposmate/sdkQuick Start
const client = new OneMyPosMateClient({
baseUrl: 'https://payus.co.nz',
system: 'pos',
});
const resp = await client.payments.payNow({
grandTotal: '10.00',
referenceId: 'REF-001',
branchId: 17,
configId: 123,
channel: 'WECHAT',
});Authentication Flow
// 1. Activate (one-time)
await client.auth.activate('ABC123');
// 2. Token is cached in TokenStore (localStorage by default)
// Every subsequent call auto-refreshes if within 60s of expiry
const token = await client.auth.currentToken();
// 3. Single-flight Promise cache prevents concurrent refreshesError Handling
try {
await client.payments.payNow(request);
} catch (e) {
if (e instanceof OneMyPosMateError) {
switch (e.errorCode) {
case 'ERR_GATEWAY_NOT_FOUND': // Terminal not configured
case 'ERR_DUPLICATE_TRANSACTION': // referenceId reused
case 'ERR_UNAUTHORIZED': // Token expired, SDK auto-retried
}
}
}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) |