@mnpay/bonum 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/api.d.ts +225 -0
- package/@types/constants/apiUrls.d.ts +26 -0
- package/@types/constants/index.d.ts +1 -0
- package/@types/definitions/index.d.ts +1 -0
- package/@types/definitions/store.d.ts +11 -0
- package/@types/index.d.ts +6 -0
- package/@types/lib/api.d.ts +4 -0
- package/@types/lib/index.d.ts +1 -0
- package/@types/requests/auth.d.ts +11 -0
- package/@types/requests/card.d.ts +49 -0
- package/@types/requests/index.d.ts +6 -0
- package/@types/requests/invoice.d.ts +33 -0
- package/@types/requests/neo.d.ts +10 -0
- package/@types/requests/qr.d.ts +28 -0
- package/@types/requests/subscription.d.ts +96 -0
- package/@types/schemas/auth.d.ts +12 -0
- package/@types/schemas/card.d.ts +64 -0
- package/@types/schemas/common.d.ts +11 -0
- package/@types/schemas/config.d.ts +17 -0
- package/@types/schemas/index.d.ts +9 -0
- package/@types/schemas/invoice.d.ts +79 -0
- package/@types/schemas/neo.d.ts +5 -0
- package/@types/schemas/qr.d.ts +46 -0
- package/@types/schemas/subscription.d.ts +92 -0
- package/@types/schemas/webhook.d.ts +140 -0
- package/@types/test/_lib/liveTokenCache.d.ts +19 -0
- package/@types/test/_mocks/api.d.ts +241 -0
- package/@types/test/api.live.test.d.ts +1 -0
- package/@types/test/api.test.d.ts +1 -0
- package/@types/test/headers.test.d.ts +1 -0
- package/@types/test/setup.d.ts +1 -0
- package/@types/test/webhook.test.d.ts +1 -0
- package/@types/types/auth.d.ts +4 -0
- package/@types/types/card.d.ts +9 -0
- package/@types/types/common.d.ts +5 -0
- package/@types/types/config.d.ts +3 -0
- package/@types/types/index.d.ts +9 -0
- package/@types/types/invoice.d.ts +9 -0
- package/@types/types/neo.d.ts +3 -0
- package/@types/types/qr.d.ts +6 -0
- package/@types/types/subscription.d.ts +8 -0
- package/@types/types/webhook.d.ts +13 -0
- package/@types/utils/headers.d.ts +9 -0
- package/@types/utils/index.d.ts +2 -0
- package/@types/utils/webhook.d.ts +11 -0
- package/@types/vite.config.d.ts +2 -0
- package/@types/vitest.config.d.ts +2 -0
- package/CHANGELOG.md +57 -0
- package/README.md +486 -0
- package/dist/index.js +314 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PaymentProviderSchema, PaymentProviderItemSchema, InvoiceItemSchema, ExtraInputTypeSchema, InvoiceExtraSchema, CreateInvoiceRequestSchema, CreateInvoiceResponseSchema } from '../schemas/invoice.js';
|
|
3
|
+
export type PaymentProvider = z.infer<typeof PaymentProviderSchema>;
|
|
4
|
+
export type PaymentProviderItem = z.infer<typeof PaymentProviderItemSchema>;
|
|
5
|
+
export type InvoiceItem = z.infer<typeof InvoiceItemSchema>;
|
|
6
|
+
export type ExtraInputType = z.infer<typeof ExtraInputTypeSchema>;
|
|
7
|
+
export type InvoiceExtra = z.infer<typeof InvoiceExtraSchema>;
|
|
8
|
+
export type CreateInvoiceRequest = z.infer<typeof CreateInvoiceRequestSchema>;
|
|
9
|
+
export type CreateInvoiceResponse = z.infer<typeof CreateInvoiceResponseSchema>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CreateQrCodeRequestSchema, QrDeepLinkSchema, CreateQrCodeResponseSchema, PayByCardTokenQrRequestSchema } from '../schemas/qr.js';
|
|
3
|
+
export type CreateQrCodeRequest = z.infer<typeof CreateQrCodeRequestSchema>;
|
|
4
|
+
export type QrDeepLink = z.infer<typeof QrDeepLinkSchema>;
|
|
5
|
+
export type CreateQrCodeResponse = z.infer<typeof CreateQrCodeResponseSchema>;
|
|
6
|
+
export type PayByCardTokenQrRequest = z.infer<typeof PayByCardTokenQrRequestSchema>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { RecurringTypeSchema, PaymentPlanSchema, SubscribeRequestSchema, SubscriptionDataSchema, ChangeSubscriptionTokenRequestSchema, ListPaymentPlansResponseSchema } from '../schemas/subscription.js';
|
|
3
|
+
export type RecurringType = z.infer<typeof RecurringTypeSchema>;
|
|
4
|
+
export type PaymentPlan = z.infer<typeof PaymentPlanSchema>;
|
|
5
|
+
export type SubscribeRequest = z.infer<typeof SubscribeRequestSchema>;
|
|
6
|
+
export type SubscriptionData = z.infer<typeof SubscriptionDataSchema>;
|
|
7
|
+
export type ChangeSubscriptionTokenRequest = z.infer<typeof ChangeSubscriptionTokenRequestSchema>;
|
|
8
|
+
export type ListPaymentPlansResponse = z.infer<typeof ListPaymentPlansResponseSchema>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { WebhookTypeSchema, WebhookStatusSchema, WebhookMessageSchema, PaymentWebhookBodySchema, SubscriptionPaymentWebhookBodySchema, CardTokenWebhookBodySchema, WebhookBankInfoSchema, bonumWebhookSchema } from '../schemas/webhook.js';
|
|
3
|
+
export type WebhookType = z.infer<typeof WebhookTypeSchema>;
|
|
4
|
+
export type WebhookStatus = z.infer<typeof WebhookStatusSchema>;
|
|
5
|
+
export type WebhookMessage<T = unknown> = Omit<z.infer<typeof WebhookMessageSchema>, 'body'> & {
|
|
6
|
+
body: T;
|
|
7
|
+
};
|
|
8
|
+
export type PaymentWebhookBody = z.infer<typeof PaymentWebhookBodySchema>;
|
|
9
|
+
export type SubscriptionPaymentWebhookBody = z.infer<typeof SubscriptionPaymentWebhookBodySchema>;
|
|
10
|
+
export type CardTokenWebhookBody = z.infer<typeof CardTokenWebhookBodySchema>;
|
|
11
|
+
export type WebhookBankInfo = z.infer<typeof WebhookBankInfoSchema>;
|
|
12
|
+
/** Fully parsed Bonum webhook, discriminated on `type` (PDF §3.3, §4.1, §5.3). */
|
|
13
|
+
export type BonumWebhook = z.infer<typeof bonumWebhookSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Store } from '../definitions/index.js';
|
|
2
|
+
export declare const langHeader: (store: Store, language?: Store["language"]) => {
|
|
3
|
+
'Accept-Language': "mn" | "en";
|
|
4
|
+
} | {
|
|
5
|
+
'Accept-Language'?: never;
|
|
6
|
+
};
|
|
7
|
+
export declare const cardTokenHeader: (cardToken: string) => {
|
|
8
|
+
'X-CARD-TOKEN': string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates the Bonum webhook payload using HMAC-SHA256.
|
|
3
|
+
* The raw body must be the EXACT compact JSON string you received, without any modification or formatting.
|
|
4
|
+
* Uses a constant-time comparison so the check does not leak signature bytes through response timing.
|
|
5
|
+
*
|
|
6
|
+
* @param rawBody The unparsed raw JSON string of the webhook payload.
|
|
7
|
+
* @param checksumKey The MERCHANT_CHECKSUM_KEY from Bonum.
|
|
8
|
+
* @param headerChecksum The `x-checksum-v2` header value precisely.
|
|
9
|
+
* @returns boolean true if valid
|
|
10
|
+
*/
|
|
11
|
+
export declare const validateWebhookChecksum: (rawBody: string, checksumKey: string, headerChecksum: string) => boolean;
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.5.0](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.4.1...bonum-v1.5.0) (2026-09-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **release:** publish five packages to public npm, fix always-failing release job ([#72](https://github.com/mnpay/mn-payment-platforms/issues/72)) ([f352143](https://github.com/mnpay/mn-payment-platforms/commit/f352143fe60e49fc263f6d33a3fe91a55acfcca1))
|
|
9
|
+
|
|
10
|
+
## [1.4.1](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.4.0...bonum-v1.4.1) (2026-07-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **bonum:** SDK-owned webhook checksum verification (verifyWebhookChecksum) ([#65](https://github.com/mnpay/mn-payment-platforms/issues/65)) ([007a827](https://github.com/mnpay/mn-payment-platforms/commit/007a8274adce2abc9a39d6256e6ca97a1cbc197b))
|
|
16
|
+
|
|
17
|
+
## [1.4.0](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.3.0...bonum-v1.4.0) (2026-07-06)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* Bonum subscriptions, card tokenization & cancel/refund (SDK audit + payment-gateway) ([#63](https://github.com/mnpay/mn-payment-platforms/issues/63)) ([7d64dc4](https://github.com/mnpay/mn-payment-platforms/commit/7d64dc44e616746694a4cb01b6200d6a491be621))
|
|
23
|
+
|
|
24
|
+
## [1.3.0](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.2.0...bonum-v1.3.0) (2026-06-10)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* per-invoice language (Accept-Language) for Bonum + payment-gateway ([#61](https://github.com/mnpay/mn-payment-platforms/issues/61)) ([f3229ef](https://github.com/mnpay/mn-payment-platforms/commit/f3229eff961a523068be25ea5c37ccf24e057bdb))
|
|
30
|
+
|
|
31
|
+
## [1.2.0](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.1.2...bonum-v1.2.0) (2026-04-04)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* add @mnpay/provider package ([#53](https://github.com/mnpay/mn-payment-platforms/issues/53)) ([2478258](https://github.com/mnpay/mn-payment-platforms/commit/247825871c141b1c9dba2a624798da7949f56a0b))
|
|
37
|
+
|
|
38
|
+
## [1.1.2](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.1.1...bonum-v1.1.2) (2026-04-02)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* bug ([6923bcd](https://github.com/mnpay/mn-payment-platforms/commit/6923bcd3491948faa79c294659edcef67582d960))
|
|
44
|
+
|
|
45
|
+
## [1.1.1](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.1.0...bonum-v1.1.1) (2026-03-29)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* bonum ([97015d5](https://github.com/mnpay/mn-payment-platforms/commit/97015d52d29550564f64fb16b50fb25b94ffd553))
|
|
51
|
+
|
|
52
|
+
## [1.1.0](https://github.com/mnpay/mn-payment-platforms/compare/bonum-v1.0.0...bonum-v1.1.0) (2026-03-26)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* add bonum package ([#46](https://github.com/mnpay/mn-payment-platforms/issues/46)) ([bcfb62c](https://github.com/mnpay/mn-payment-platforms/commit/bcfb62cd4392e432f8b239d22142b96f4b3beb1c))
|
package/README.md
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
# @mnpay/bonum
|
|
2
|
+
|
|
3
|
+
Client library for the **Bonum** payment gateway. Supports invoices, QR-code payments, card tokenization, recurring subscriptions, and NEO digital wallet messaging.
|
|
4
|
+
|
|
5
|
+
- Production API: `https://apis.bonum.mn`
|
|
6
|
+
- Test API: `https://testapi.bonum.mn`
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @mnpay/bonum
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add @mnpay/bonum
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { useBonum } from '@mnpay/bonum'
|
|
22
|
+
|
|
23
|
+
const bonum = useBonum({
|
|
24
|
+
appSecret: 'your-app-secret',
|
|
25
|
+
terminalId: 'your-terminal-id',
|
|
26
|
+
isTestEnv: false, // set true to use test environment
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
|
|
32
|
+
| Field | Type | Required | Description |
|
|
33
|
+
|-------|------|----------|-------------|
|
|
34
|
+
| `appSecret` | `string` | Yes | Application secret key |
|
|
35
|
+
| `terminalId` | `string` | Yes | Terminal identifier |
|
|
36
|
+
| `baseUrl` | `string` | No | Override API base URL |
|
|
37
|
+
| `checksumKey` | `string` | No | MERCHANT_CHECKSUM_KEY issued out-of-band by Bonum (distinct from `appSecret`). Required to call `verifyWebhookChecksum` — it throws when unset. |
|
|
38
|
+
| `language` | `'mn' \| 'en'` | No | Default response language (`Accept-Language` header). When unset, no language header is sent. Override per request via `createInvoice({ language })`. |
|
|
39
|
+
| `isTestEnv` | `boolean` | No | Use test environment URL |
|
|
40
|
+
|
|
41
|
+
Access tokens are managed automatically — the client fetches and refreshes tokens via an interceptor before each request.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
### `getToken()`
|
|
48
|
+
|
|
49
|
+
Fetches a new access token using `appSecret` and `terminalId`. Called automatically by the interceptor; you rarely need to call this manually.
|
|
50
|
+
|
|
51
|
+
**Response:**
|
|
52
|
+
|
|
53
|
+
| Field | Type | Description |
|
|
54
|
+
|-------|------|-------------|
|
|
55
|
+
| `tokenType` | `'Bearer'` | Token type |
|
|
56
|
+
| `accessToken` | `string` | Access token |
|
|
57
|
+
| `expiresIn` | `number` | Token lifetime in seconds |
|
|
58
|
+
| `refreshToken` | `string` | Refresh token |
|
|
59
|
+
| `refreshExpiresIn` | `number` | Refresh token lifetime in seconds |
|
|
60
|
+
| `unit` | `'SECONDS'` | Unit for expiry values |
|
|
61
|
+
|
|
62
|
+
### `refreshToken()`
|
|
63
|
+
|
|
64
|
+
Refreshes the access token using the stored refresh token. Called automatically when the access token expires.
|
|
65
|
+
|
|
66
|
+
**Response:**
|
|
67
|
+
|
|
68
|
+
| Field | Type | Description |
|
|
69
|
+
|-------|------|-------------|
|
|
70
|
+
| `accessToken` | `string` | New access token |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Payment Providers
|
|
75
|
+
|
|
76
|
+
### `getPaymentProviders()`
|
|
77
|
+
|
|
78
|
+
Returns the list of payment providers and their enabled status.
|
|
79
|
+
|
|
80
|
+
**Response:** `PaymentProviderItem[]`
|
|
81
|
+
|
|
82
|
+
| Field | Type | Description |
|
|
83
|
+
|-------|------|-------------|
|
|
84
|
+
| `provider` | `'QPAY' \| 'E_COMMERCE' \| 'WE_CHAT' \| 'SONO_SHOP'` | Provider identifier |
|
|
85
|
+
| `enabled` | `boolean` | Whether the provider is currently active |
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Invoices
|
|
90
|
+
|
|
91
|
+
### `createInvoice(data)`
|
|
92
|
+
|
|
93
|
+
Creates a payment invoice and returns a `followUpLink` to redirect the customer to.
|
|
94
|
+
|
|
95
|
+
**Request:**
|
|
96
|
+
|
|
97
|
+
| Field | Type | Required | Description |
|
|
98
|
+
|-------|------|----------|-------------|
|
|
99
|
+
| `amount` | `number` | Yes | Invoice amount |
|
|
100
|
+
| `callback` | `string` | Yes | Webhook URL called when payment status changes |
|
|
101
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
102
|
+
| `expiresIn` | `number` | Yes | Invoice expiry duration in seconds |
|
|
103
|
+
| `providers` | `PaymentProvider[]` | No | Limit to specific payment providers |
|
|
104
|
+
| `items` | `InvoiceItem[]` | No | Line items to display on the invoice |
|
|
105
|
+
| `extras` | `InvoiceExtra[]` | No | Extra input fields shown to the customer |
|
|
106
|
+
| `language` | `'mn' \| 'en'` | No | Per-invoice display language, sent as the `Accept-Language` header. Falls back to the client-level `language`; when neither is set, no language header is sent. |
|
|
107
|
+
|
|
108
|
+
**`InvoiceItem`:**
|
|
109
|
+
|
|
110
|
+
| Field | Type | Required | Description |
|
|
111
|
+
|-------|------|----------|-------------|
|
|
112
|
+
| `title` | `string` | Yes | Item name |
|
|
113
|
+
| `amount` | `number` | Yes | Item price |
|
|
114
|
+
| `count` | `number` | Yes | Quantity |
|
|
115
|
+
| `image` | `string` | No | Item image URL |
|
|
116
|
+
| `remark` | `string` | No | Additional note |
|
|
117
|
+
|
|
118
|
+
**Response:**
|
|
119
|
+
|
|
120
|
+
| Field | Type | Description |
|
|
121
|
+
|-------|------|-------------|
|
|
122
|
+
| `invoiceId` | `string` | Created invoice ID |
|
|
123
|
+
| `followUpLink` | `string` | URL to redirect the customer to for payment |
|
|
124
|
+
|
|
125
|
+
**Example:**
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const { data } = await bonum.createInvoice({
|
|
129
|
+
amount: 19900,
|
|
130
|
+
callback: 'https://yoursite.com/webhook/bonum',
|
|
131
|
+
transactionId: 'TXN-001',
|
|
132
|
+
expiresIn: 300,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
// Redirect customer to:
|
|
136
|
+
console.log(data.followUpLink)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `getInvoiceStatus({ invoiceId })`
|
|
140
|
+
|
|
141
|
+
> ⚠️ **Test environment only — do NOT use in production.** Bonum only exposes invoice
|
|
142
|
+
> status polling in the test environment. In production, track payment outcomes via the
|
|
143
|
+
> `PAYMENT` webhook (see [Webhooks](#webhooks)) rather than polling this endpoint.
|
|
144
|
+
|
|
145
|
+
Returns the current status of an invoice.
|
|
146
|
+
|
|
147
|
+
| Parameter | Type | Required | Description |
|
|
148
|
+
|-----------|------|----------|-------------|
|
|
149
|
+
| `invoiceId` | `string` | Yes | Invoice ID from `createInvoice` |
|
|
150
|
+
|
|
151
|
+
### `setInvoicePaid({ invoiceId })`
|
|
152
|
+
|
|
153
|
+
Marks an invoice as paid. Typically called from a webhook handler after confirming payment.
|
|
154
|
+
|
|
155
|
+
| Parameter | Type | Required | Description |
|
|
156
|
+
|-----------|------|----------|-------------|
|
|
157
|
+
| `invoiceId` | `string` | Yes | Invoice ID to mark as paid |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## QR Code Payments
|
|
162
|
+
|
|
163
|
+
### `createQrCode(data)`
|
|
164
|
+
|
|
165
|
+
Creates a QR code for payment. The customer scans the QR with a supported banking app.
|
|
166
|
+
|
|
167
|
+
**Request:**
|
|
168
|
+
|
|
169
|
+
| Field | Type | Required | Description |
|
|
170
|
+
|-------|------|----------|-------------|
|
|
171
|
+
| `amount` | `number` | Yes | Payment amount |
|
|
172
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
173
|
+
| `expiresIn` | `number` | Yes | QR code expiry in seconds |
|
|
174
|
+
|
|
175
|
+
**Response:**
|
|
176
|
+
|
|
177
|
+
| Field | Type | Description |
|
|
178
|
+
|-------|------|-------------|
|
|
179
|
+
| `invoiceId` | `string` | Invoice ID for this QR payment |
|
|
180
|
+
| `qrCode` | `string` | Raw QR code string |
|
|
181
|
+
| `qrImage` | `string` | Base64-encoded QR code image |
|
|
182
|
+
| `links` | `QrDeepLink[]` | Deep links for supported banking apps |
|
|
183
|
+
|
|
184
|
+
**`QrDeepLink`:**
|
|
185
|
+
|
|
186
|
+
| Field | Type | Description |
|
|
187
|
+
|-------|------|-------------|
|
|
188
|
+
| `name` | `string` | Bank/app name |
|
|
189
|
+
| `description` | `string` | Description |
|
|
190
|
+
| `logo` | `string` | Logo URL |
|
|
191
|
+
| `link` | `string` | Deep link URL |
|
|
192
|
+
| `appStoreId` | `string` | iOS App Store ID |
|
|
193
|
+
| `androidPackageName` | `string` | Android package name |
|
|
194
|
+
|
|
195
|
+
### `invoiceByQrCode({ qrCode })`
|
|
196
|
+
|
|
197
|
+
Creates an invoice using data from a scanned QR code.
|
|
198
|
+
|
|
199
|
+
| Parameter | Type | Required | Description |
|
|
200
|
+
|-----------|------|----------|-------------|
|
|
201
|
+
| `qrCode` | `string` | Yes | Raw QR code string scanned by the customer |
|
|
202
|
+
|
|
203
|
+
### `payByCardTokenQr({ qrCode, transactionId, cardToken })`
|
|
204
|
+
|
|
205
|
+
Pays a QR code invoice using a stored card token.
|
|
206
|
+
|
|
207
|
+
| Parameter | Type | Required | Description |
|
|
208
|
+
|-----------|------|----------|-------------|
|
|
209
|
+
| `qrCode` | `string` | Yes | QR code to pay |
|
|
210
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
211
|
+
| `cardToken` | `string` | Yes | Card token from `createCardToken` |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Card Tokenization
|
|
216
|
+
|
|
217
|
+
### `createCardToken(data)`
|
|
218
|
+
|
|
219
|
+
Initiates card tokenization. Returns a `followUpLink` to redirect the customer to for card entry.
|
|
220
|
+
|
|
221
|
+
**Request:**
|
|
222
|
+
|
|
223
|
+
| Field | Type | Required | Description |
|
|
224
|
+
|-------|------|----------|-------------|
|
|
225
|
+
| `callback` | `string` | Yes | Webhook URL called after tokenization completes |
|
|
226
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
227
|
+
| `payment` | `{ amount: number }` | No | Charge the card immediately on tokenization |
|
|
228
|
+
| `subscription` | `CardTokenSubscription` | No | Attach the token to a subscription plan |
|
|
229
|
+
| `items` | `InvoiceItem[]` | No | Line items to display |
|
|
230
|
+
|
|
231
|
+
**`CardTokenSubscription`:**
|
|
232
|
+
|
|
233
|
+
| Field | Type | Required | Description |
|
|
234
|
+
|-------|------|----------|-------------|
|
|
235
|
+
| `planId` | `number` | Yes | Subscription plan ID |
|
|
236
|
+
| `cycleValue` | `string` | Yes | Billing cycle value (e.g. day of month) |
|
|
237
|
+
| `cycles` | `number \| null` | No | Total billing cycles (`null` = unlimited) |
|
|
238
|
+
| `payNow` | `boolean` | No | Charge on tokenization |
|
|
239
|
+
| `custEmail` | `string` | No | Customer email for receipts |
|
|
240
|
+
|
|
241
|
+
**Response:**
|
|
242
|
+
|
|
243
|
+
| Field | Type | Description |
|
|
244
|
+
|-------|------|-------------|
|
|
245
|
+
| `followUpLink` | `string` | URL to redirect the customer to for card entry |
|
|
246
|
+
| `id` | `string` | Token request ID |
|
|
247
|
+
|
|
248
|
+
### `purchaseWithCardToken({ cardToken, amount, currency, transactionId })`
|
|
249
|
+
|
|
250
|
+
Makes a purchase using a stored card token.
|
|
251
|
+
|
|
252
|
+
| Parameter | Type | Required | Description |
|
|
253
|
+
|-----------|------|----------|-------------|
|
|
254
|
+
| `cardToken` | `string` | Yes | Stored card token |
|
|
255
|
+
| `amount` | `number` | Yes | Charge amount |
|
|
256
|
+
| `currency` | `string` | Yes | Currency code |
|
|
257
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
258
|
+
|
|
259
|
+
**Response:**
|
|
260
|
+
|
|
261
|
+
| Field | Type | Description |
|
|
262
|
+
|-------|------|-------------|
|
|
263
|
+
| `id` | `number` | Transaction ID |
|
|
264
|
+
| `status` | `'SUCCESS' \| 'FAILED' \| 'QUEUED'` | Transaction status |
|
|
265
|
+
| `completedAt` | `string` | Completion timestamp |
|
|
266
|
+
| `description` | `string` | Result description |
|
|
267
|
+
| `cardStatus` | `'ACTIVE' \| 'INACTIVE' \| null` | Card status |
|
|
268
|
+
| `respCode` | `string \| null` | Response code |
|
|
269
|
+
|
|
270
|
+
### `rollbackPurchase({ id, cardToken })`
|
|
271
|
+
|
|
272
|
+
Refunds an already-completed card-token purchase in full (PDF §4.3:
|
|
273
|
+
`GET /mpay-service/merchant/transaction/rollback/{id}`). The refund always applies
|
|
274
|
+
to the full amount of the original purchase identified by `id`, so no `amount` is sent.
|
|
275
|
+
|
|
276
|
+
| Parameter | Type | Required | Description |
|
|
277
|
+
|-----------|------|----------|-------------|
|
|
278
|
+
| `id` | `string` | Yes | Transaction ID of the original purchase to roll back |
|
|
279
|
+
| `cardToken` | `string` | Yes | Card token used in the original purchase (sent as `X-CARD-TOKEN`) |
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Subscriptions
|
|
284
|
+
|
|
285
|
+
### `listPaymentPlans()`
|
|
286
|
+
|
|
287
|
+
Returns all available subscription plans.
|
|
288
|
+
|
|
289
|
+
**Response:** `PaymentPlan[]`
|
|
290
|
+
|
|
291
|
+
| Field | Type | Description |
|
|
292
|
+
|-------|------|-------------|
|
|
293
|
+
| `planId` | `number` | Plan ID |
|
|
294
|
+
| `name` | `string` | Plan name |
|
|
295
|
+
| `remark` | `string` | Plan description |
|
|
296
|
+
| `recurringType` | `'WEEKLY' \| 'MONTHLY' \| 'YEARLY'` | Billing frequency |
|
|
297
|
+
| `amount` | `number` | Recurring charge amount |
|
|
298
|
+
| `status` | `'ACTIVE' \| 'INACTIVE'` | Plan availability |
|
|
299
|
+
| `cardCount` | `number` | Number of cards enrolled |
|
|
300
|
+
| `retryCount` | `number` | Payment retry count on failure |
|
|
301
|
+
| `createdAt` | `string` | Plan creation timestamp |
|
|
302
|
+
|
|
303
|
+
### `subscribe({ cardToken, planId, cycleValue, cycles?, payNow?, custEmail? })`
|
|
304
|
+
|
|
305
|
+
Subscribes a card to a payment plan.
|
|
306
|
+
|
|
307
|
+
| Parameter | Type | Required | Description |
|
|
308
|
+
|-----------|------|----------|-------------|
|
|
309
|
+
| `cardToken` | `string` | Yes | Card token to subscribe |
|
|
310
|
+
| `planId` | `number` | Yes | Subscription plan ID |
|
|
311
|
+
| `cycleValue` | `number \| string` | Yes | Billing cycle value |
|
|
312
|
+
| `cycles` | `number \| null` | No | Total cycles (`null` = unlimited) |
|
|
313
|
+
| `payNow` | `boolean` | No | Charge immediately on subscription |
|
|
314
|
+
| `custEmail` | `string` | No | Customer email for receipts |
|
|
315
|
+
|
|
316
|
+
**Response:** `SubscriptionData` (see below)
|
|
317
|
+
|
|
318
|
+
### `getSubscriptions({ cardToken })`
|
|
319
|
+
|
|
320
|
+
Returns all subscriptions associated with a card token.
|
|
321
|
+
|
|
322
|
+
**Response:** `SubscriptionData[]`
|
|
323
|
+
|
|
324
|
+
**`SubscriptionData`:**
|
|
325
|
+
|
|
326
|
+
| Field | Type | Description |
|
|
327
|
+
|-------|------|-------------|
|
|
328
|
+
| `subscriptionId` | `number` | Subscription ID |
|
|
329
|
+
| `subscribedAt` | `string` | Subscription creation timestamp |
|
|
330
|
+
| `cardMask` | `string` | Masked card number |
|
|
331
|
+
| `plan` | `PaymentPlan` | The associated plan |
|
|
332
|
+
| `nextBillAt` | `string` | Next billing date |
|
|
333
|
+
| `lastBilledAt` | `string` | Last billing date |
|
|
334
|
+
| `status` | `'ACTIVE' \| 'INACTIVE' \| 'CANCELLED'` | Subscription status |
|
|
335
|
+
|
|
336
|
+
### `unsubscribe({ subscriptionId, planId? })`
|
|
337
|
+
|
|
338
|
+
Cancels a subscription.
|
|
339
|
+
|
|
340
|
+
| Parameter | Type | Required | Description |
|
|
341
|
+
|-----------|------|----------|-------------|
|
|
342
|
+
| `subscriptionId` | `string` | Yes | Subscription ID to cancel |
|
|
343
|
+
| `planId` | `string` | No | Plan ID (if required by the plan) |
|
|
344
|
+
|
|
345
|
+
### `deleteSubscription({ subscriptionId, planId? })`
|
|
346
|
+
|
|
347
|
+
Permanently deletes a subscription record.
|
|
348
|
+
|
|
349
|
+
| Parameter | Type | Required | Description |
|
|
350
|
+
|-----------|------|----------|-------------|
|
|
351
|
+
| `subscriptionId` | `string` | Yes | Subscription ID to delete |
|
|
352
|
+
| `planId` | `string` | No | Plan ID (if required) |
|
|
353
|
+
|
|
354
|
+
### `changeSubscriptionTokenNewCard({ subscriptionId, callback, transactionId, items? })`
|
|
355
|
+
|
|
356
|
+
Updates a subscription with a new card — initiates a new tokenization flow.
|
|
357
|
+
|
|
358
|
+
| Parameter | Type | Required | Description |
|
|
359
|
+
|-----------|------|----------|-------------|
|
|
360
|
+
| `subscriptionId` | `string` | Yes | Subscription to update |
|
|
361
|
+
| `callback` | `string` | Yes | Webhook URL after new card is tokenized |
|
|
362
|
+
| `transactionId` | `string` | Yes | Unique merchant-side transaction ID |
|
|
363
|
+
| `items` | `InvoiceItem[]` | No | Line items to display |
|
|
364
|
+
|
|
365
|
+
**Response:**
|
|
366
|
+
|
|
367
|
+
| Field | Type | Description |
|
|
368
|
+
|-------|------|-------------|
|
|
369
|
+
| `followUpLink` | `string` | URL to redirect customer to for new card entry |
|
|
370
|
+
|
|
371
|
+
### `changeSubscriptionTokenExisting({ subscriptionId, newCardToken })`
|
|
372
|
+
|
|
373
|
+
Updates a subscription with an already-tokenized card.
|
|
374
|
+
|
|
375
|
+
| Parameter | Type | Required | Description |
|
|
376
|
+
|-----------|------|----------|-------------|
|
|
377
|
+
| `subscriptionId` | `string` | Yes | Subscription to update |
|
|
378
|
+
| `newCardToken` | `string` | Yes | Existing card token to use |
|
|
379
|
+
|
|
380
|
+
> **Note:** `executeSubscriptionPayment` is `@internal` and intentionally undocumented.
|
|
381
|
+
> Subscription charges are automatic — Bonum fires the `SUBSCRIPTION-PAYMENT` webhook on
|
|
382
|
+
> each recurring charge. Do not call it directly; rely on the webhook instead.
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## NEO (Digital Wallet)
|
|
387
|
+
|
|
388
|
+
The NEO methods communicate with a separate NEO / M-Chat base URL, passed per-request.
|
|
389
|
+
|
|
390
|
+
### `getNeoUserData({ requestId, mChatBaseUrl })`
|
|
391
|
+
|
|
392
|
+
Retrieves NEO user account data for a given share request.
|
|
393
|
+
|
|
394
|
+
| Parameter | Type | Required | Description |
|
|
395
|
+
|-----------|------|----------|-------------|
|
|
396
|
+
| `requestId` | `string` | Yes | Share request ID |
|
|
397
|
+
| `mChatBaseUrl` | `string` | Yes | M-Chat service base URL |
|
|
398
|
+
|
|
399
|
+
### `sendNeoMessage({ phoneNumber, message, neoBaseUrl })`
|
|
400
|
+
|
|
401
|
+
Sends a message to a user through the NEO messaging service.
|
|
402
|
+
|
|
403
|
+
| Parameter | Type | Required | Description |
|
|
404
|
+
|-----------|------|----------|-------------|
|
|
405
|
+
| `phoneNumber` | `string` | Yes | Recipient phone number |
|
|
406
|
+
| `message` | `string` | Yes | Message content |
|
|
407
|
+
| `neoBaseUrl` | `string` | Yes | NEO service base URL |
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Webhook Verification
|
|
412
|
+
|
|
413
|
+
### `verifyWebhookChecksum(rawBody, headerChecksum)`
|
|
414
|
+
|
|
415
|
+
Verifies the `x-checksum-v2` webhook signature using the configured `checksumKey`.
|
|
416
|
+
Synchronous — no API call. **Throws** when `checksumKey` is not configured.
|
|
417
|
+
|
|
418
|
+
| Parameter | Type | Required | Description |
|
|
419
|
+
|-----------|------|----------|-------------|
|
|
420
|
+
| `rawBody` | `string` | Yes | Exact raw request body as received on the wire |
|
|
421
|
+
| `headerChecksum` | `string` | Yes | The `x-checksum-v2` header value |
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
## Webhooks
|
|
426
|
+
|
|
427
|
+
Bonum delivers status updates as signed webhooks. In production this is the **authoritative**
|
|
428
|
+
way to learn the outcome of a payment, card tokenization, or recurring charge — prefer it over
|
|
429
|
+
polling `getInvoiceStatus` (which is test-environment only).
|
|
430
|
+
|
|
431
|
+
### Verifying the signature
|
|
432
|
+
|
|
433
|
+
Each webhook carries an `x-checksum-v2` header (HmacSHA256 over the raw request body). When the
|
|
434
|
+
client is configured with `checksumKey` (the MERCHANT_CHECKSUM_KEY Bonum issues out-of-band —
|
|
435
|
+
**not** your `appSecret`), verify with the SDK method:
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
const bonum = useBonum({ terminalId, appSecret, checksumKey })
|
|
439
|
+
|
|
440
|
+
const ok = bonum.verifyWebhookChecksum(rawBody, req.headers['x-checksum-v2'])
|
|
441
|
+
if (!ok) throw new Error('Invalid Bonum webhook checksum')
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
`verifyWebhookChecksum` **throws** when `checksumKey` is not configured, so a misconfiguration
|
|
445
|
+
never masquerades as an invalid signature.
|
|
446
|
+
|
|
447
|
+
The underlying pure function is also exported if you manage the key yourself:
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
import { validateWebhookChecksum } from '@mnpay/bonum'
|
|
451
|
+
|
|
452
|
+
const ok = validateWebhookChecksum(rawBody, checksumKey, req.headers['x-checksum-v2'])
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
> **Important:** `rawBody` must be the exact bytes received on the wire — capture it *before* any
|
|
456
|
+
> JSON parsing (`readRawBody` in h3/Nitro, `express.raw`, `req.text()` in Next.js). Re-serializing
|
|
457
|
+
> a parsed body changes key order/escaping and the HMAC will never match.
|
|
458
|
+
|
|
459
|
+
### Parsing the payload
|
|
460
|
+
|
|
461
|
+
`bonumWebhookSchema` is a Zod discriminated union (discriminated on `type`) covering all three
|
|
462
|
+
documented webhook kinds, each in a `SUCCESS` / `FAILED` variant. The parsed type is exported as
|
|
463
|
+
`BonumWebhook`.
|
|
464
|
+
|
|
465
|
+
| `type` | When it fires | Body |
|
|
466
|
+
|--------|---------------|------|
|
|
467
|
+
| `PAYMENT` | A regular invoice was paid / failed (PDF §3.3) | Transaction detail (`invoiceId`, `amount`, `currency`, `transactionId`, `terminalId`, …) |
|
|
468
|
+
| `CARD-TOKEN` | A card tokenization completed / failed (PDF §4.1) | Token + bank info |
|
|
469
|
+
| `SUBSCRIPTION-PAYMENT` | An automatic recurring charge ran (PDF §5.3) | `subscriptionId`, `invoiceId`, `planId`, `transactionId`, `amount`, `currency`, `completedAt` |
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
import { bonumWebhookSchema } from '@mnpay/bonum'
|
|
473
|
+
|
|
474
|
+
const event = bonumWebhookSchema.parse(req.body)
|
|
475
|
+
switch (event.type) {
|
|
476
|
+
case 'PAYMENT':
|
|
477
|
+
// reconcile invoice payment
|
|
478
|
+
break
|
|
479
|
+
case 'CARD-TOKEN':
|
|
480
|
+
// store the card token from the tokenization result
|
|
481
|
+
break
|
|
482
|
+
case 'SUBSCRIPTION-PAYMENT':
|
|
483
|
+
// record the recurring charge
|
|
484
|
+
break
|
|
485
|
+
}
|
|
486
|
+
```
|