@payriff-sdk/node 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +267 -2
- package/dist/client.d.ts +25 -0
- package/dist/client.js +49 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +66 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +31 -0
- package/dist/resources/cards.d.ts +10 -0
- package/dist/resources/cards.js +41 -0
- package/dist/resources/invoices.d.ts +9 -0
- package/dist/resources/invoices.js +57 -0
- package/dist/resources/orders.d.ts +15 -0
- package/dist/resources/orders.js +87 -0
- package/dist/resources/paging.d.ts +6 -0
- package/dist/resources/paging.js +14 -0
- package/dist/resources/payments.d.ts +8 -0
- package/dist/resources/payments.js +31 -0
- package/dist/resources/payouts.d.ts +11 -0
- package/dist/resources/payouts.js +72 -0
- package/dist/resources/transactions.d.ts +7 -0
- package/dist/resources/transactions.js +45 -0
- package/dist/transport.d.ts +27 -0
- package/dist/transport.js +115 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.js +2 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.js +52 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/webhooks.d.ts +2 -0
- package/dist/webhooks.js +23 -0
- package/package.json +33 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Payriff
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,268 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Payriff Node.js SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js client for the Payriff merchant API: orders, saved-card payments, saved cards,
|
|
4
|
+
transactions, payouts and invoices.
|
|
5
|
+
|
|
6
|
+
- Node.js 20 or newer
|
|
7
|
+
- No runtime dependencies
|
|
8
|
+
- TypeScript types included
|
|
9
|
+
- Talks to `https://api.payriff.com` (Azerbaijan) or `https://api.gccpay.sa` (Saudi Arabia)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @payriff-sdk/node
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Works with any Node.js framework (Express, NestJS, Fastify, Next.js).
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { Payriff } from '@payriff-sdk/node';
|
|
23
|
+
|
|
24
|
+
const payriff = new Payriff({ secretKey: process.env.PAYRIFF_SECRET_KEY! });
|
|
25
|
+
|
|
26
|
+
const order = await payriff.orders.create({
|
|
27
|
+
amount: 10,
|
|
28
|
+
description: 'Order #1001',
|
|
29
|
+
callbackUrl: 'https://shop.example/payriff/callback',
|
|
30
|
+
requestRrn: 'order-1001',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Send the customer to the hosted payment page
|
|
34
|
+
const paymentUrl = order.paymentUrl;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
CommonJS works too: `const { Payriff } = require('@payriff-sdk/node');`
|
|
38
|
+
|
|
39
|
+
Create one `Payriff` instance and reuse it.
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
| Option | Required | Default | Notes |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| `secretKey` | yes | — | Secret key from the Payriff dashboard. |
|
|
46
|
+
| `merchantId` | for payouts and invoices | — | Merchant ID (e.g. `ES1000000`). |
|
|
47
|
+
| `timeout` | no | `60000` | Request timeout in milliseconds. Bank operations can take tens of seconds. |
|
|
48
|
+
| `region` | no | `'azerbaijan'` | API region: `'azerbaijan'` or `'ksa'`. Sets the base URL and the default currency. |
|
|
49
|
+
| `baseUrl` | no | from `region` | Override the API URL, e.g. for testing. The currency still comes from `region`. |
|
|
50
|
+
|
|
51
|
+
Keep the secret key in an environment variable or secret store. Never commit it.
|
|
52
|
+
Versions before 0.3.0 called it the app key; the `appKey` option still works but is deprecated.
|
|
53
|
+
|
|
54
|
+
### Saudi Arabia (KSA)
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const payriff = new Payriff({ secretKey: process.env.PAYRIFF_SECRET_KEY!, region: 'ksa' });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
| Region | API | Default currency |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `'azerbaijan'` | `https://api.payriff.com` | `AZN` |
|
|
63
|
+
| `'ksa'` | `https://api.gccpay.sa` | `SAR` |
|
|
64
|
+
|
|
65
|
+
Use the secret key from the dashboard of the same region (`dashboard.gccpay.sa` for KSA).
|
|
66
|
+
`'saudi'` still works but is deprecated; use `'ksa'`.
|
|
67
|
+
A `currency` passed on a request always wins over the region default.
|
|
68
|
+
|
|
69
|
+
## Orders
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const created = await payriff.orders.create({
|
|
73
|
+
amount: 25,
|
|
74
|
+
currency: 'AZN', // default: the region currency
|
|
75
|
+
operation: 'PRE_AUTH', // default PURCHASE
|
|
76
|
+
language: 'AZ',
|
|
77
|
+
description: 'Booking #77',
|
|
78
|
+
callbackUrl: 'https://shop.example/payriff/callback',
|
|
79
|
+
metadata: { bookingId: '77' },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const info = await payriff.orders.get(created.orderId);
|
|
83
|
+
const byRef = await payriff.orders.getByRequestRrn('order-1001'); // the requestRrn you sent on create
|
|
84
|
+
|
|
85
|
+
await payriff.orders.complete({ orderId: created.orderId, amount: 25 });
|
|
86
|
+
await payriff.orders.refund({ orderId: created.orderId, amount: 5, refundReason: 'Partial return' });
|
|
87
|
+
await payriff.orders.expire(created.orderId); // cancel an unpaid order
|
|
88
|
+
|
|
89
|
+
const receiptPdf: Buffer = await payriff.orders.downloadReceipt(created.orderId);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`created.clientSecret` is set only when the application has an active publishable key; otherwise it
|
|
93
|
+
is `undefined`. Pass it with the order ID to the Payriff web or mobile SDK, which takes the payment in
|
|
94
|
+
the customer's browser or app. Treat it as a secret: don't log it or put it in URLs.
|
|
95
|
+
|
|
96
|
+
`paymentStatus` is a string such as `APPROVED`, `DECLINED`, `PREAUTH_APPROVED` or `REFUNDED`. Values that
|
|
97
|
+
this SDK version does not know yet are passed through unchanged.
|
|
98
|
+
|
|
99
|
+
Amounts are JavaScript numbers in major units (`10.5` = 10.50 AZN or SAR).
|
|
100
|
+
|
|
101
|
+
## Charging a saved card
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const charge = await payriff.payments.autoPay({
|
|
105
|
+
cardUuid: savedCardUuid,
|
|
106
|
+
amount: 9.99,
|
|
107
|
+
description: 'Monthly subscription',
|
|
108
|
+
requestRrn: 'sub-2026-10',
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Saved cards
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { randomUUID } from 'node:crypto';
|
|
116
|
+
|
|
117
|
+
const session = await payriff.cards.save({
|
|
118
|
+
customerRef: 'customer-42',
|
|
119
|
+
callbackUrl: 'https://shop.example/payriff/card-saved',
|
|
120
|
+
idempotencyKey: randomUUID(),
|
|
121
|
+
});
|
|
122
|
+
// Redirect the customer to session.paymentUrl to verify the card.
|
|
123
|
+
|
|
124
|
+
const details = await payriff.cards.getSave(session.cardSaveId);
|
|
125
|
+
if (details.status === 'VERIFIED') {
|
|
126
|
+
const cardUuid = details.cardUuid; // store it; use with autoPay
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const cards = await payriff.cards.list('customer-42');
|
|
130
|
+
await payriff.cards.delete(cards[0].cardUuid);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Transactions
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const page = await payriff.transactions.list({
|
|
137
|
+
status: 'APPROVED',
|
|
138
|
+
from: '2026-09-01', // Date or YYYY-MM-DD
|
|
139
|
+
to: '2026-09-30',
|
|
140
|
+
page: 0,
|
|
141
|
+
size: 20, // server maximum is 20
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
for (const tx of page.content) {
|
|
145
|
+
console.log(tx.orderId, tx.amount);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Payouts
|
|
150
|
+
|
|
151
|
+
Payouts require `merchantId` on the client.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const payriff = new Payriff({
|
|
155
|
+
secretKey: process.env.PAYRIFF_SECRET_KEY!,
|
|
156
|
+
merchantId: process.env.PAYRIFF_MERCHANT_ID,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const maskedName = await payriff.payouts.checkCardholder('4169741330151979'); // e.g. "J*** D**"
|
|
160
|
+
|
|
161
|
+
const payout = await payriff.payouts.create({
|
|
162
|
+
transferAmount: 50, // minimum 1
|
|
163
|
+
description: 'Refund for order #1001',
|
|
164
|
+
fullName: 'JOHN DOE',
|
|
165
|
+
finCode: '1AB2C3D',
|
|
166
|
+
cardPan: '4169741330151979',
|
|
167
|
+
requestRrn: 'payout-1001',
|
|
168
|
+
idempotencyKey: 'payout-1001',
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const status = await payriff.payouts.getByRequestRrn('payout-1001');
|
|
172
|
+
const history = await payriff.payouts.list({ status: 'SUCCESS' });
|
|
173
|
+
const receipt = await payriff.payouts.downloadReceipt('payout-1001');
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Invoices
|
|
177
|
+
|
|
178
|
+
Invoices require `merchantId` on the client.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const invoice = await payriff.invoices.create({
|
|
182
|
+
amount: 15,
|
|
183
|
+
fullName: 'JOHN DOE',
|
|
184
|
+
phoneNumber: '+994501234567',
|
|
185
|
+
description: 'Consultation',
|
|
186
|
+
expireDate: new Date(Date.now() + 7 * 24 * 3600 * 1000),
|
|
187
|
+
sendSms: true,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const link = invoice.paymentUrl; // share with the customer
|
|
191
|
+
const details = await payriff.invoices.get(invoice.invoiceUuid);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Callbacks
|
|
195
|
+
|
|
196
|
+
When an order changes state, Payriff POSTs JSON to the `callbackUrl` you set on the order.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import express from 'express';
|
|
200
|
+
import { parseOrderCallback } from '@payriff-sdk/node';
|
|
201
|
+
|
|
202
|
+
app.post('/payriff/callback', express.json(), async (req, res) => {
|
|
203
|
+
const notified = parseOrderCallback(req.body); // also accepts the raw string or Buffer
|
|
204
|
+
|
|
205
|
+
// Callbacks are not signed: confirm the state with Payriff before fulfilling.
|
|
206
|
+
const confirmed = await payriff.orders.get(notified.orderId);
|
|
207
|
+
if (confirmed.paymentStatus === 'APPROVED') {
|
|
208
|
+
// fulfil the order (make this idempotent: the same callback can arrive more than once)
|
|
209
|
+
}
|
|
210
|
+
res.sendStatus(200);
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Errors
|
|
215
|
+
|
|
216
|
+
Every SDK error extends `PayriffError`, which carries `httpStatus`, `code` (Payriff result code)
|
|
217
|
+
and `responseId` (quote it when contacting support).
|
|
218
|
+
|
|
219
|
+
| Error | When |
|
|
220
|
+
|---|---|
|
|
221
|
+
| `AuthenticationError` | Secret key rejected (`14010`, `14013`, `14014`, `14015`) |
|
|
222
|
+
| `ValidationError` | Invalid request (`15400` or HTTP 400) |
|
|
223
|
+
| `RequestRejectedError` | Business refusal (`01000`), e.g. application under review |
|
|
224
|
+
| `InsufficientBalanceError` | Not enough wallet balance for a payout (`01200`) |
|
|
225
|
+
| `PayoutLimitError` | Payout limit reached (`01300`, `01400`, `01500`) |
|
|
226
|
+
| `ApiError` | Any other failure reported by Payriff |
|
|
227
|
+
| `PayriffConnectionError` | No response: network error or timeout |
|
|
228
|
+
|
|
229
|
+
Payriff can report a failure with HTTP 200. The SDK checks the result code in the body, so you
|
|
230
|
+
only need to catch errors. Invalid arguments are rejected with a `TypeError` or `RangeError` before
|
|
231
|
+
any request is sent.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { PayriffConnectionError, PayriffError, ValidationError } from '@payriff-sdk/node';
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
await payriff.orders.refund({ orderId });
|
|
238
|
+
} catch (e) {
|
|
239
|
+
if (e instanceof ValidationError) {
|
|
240
|
+
console.warn(`Refund rejected: ${e.message} (${e.code})`);
|
|
241
|
+
} else if (e instanceof PayriffConnectionError) {
|
|
242
|
+
// Outcome unknown: check payriff.orders.get(orderId) before retrying
|
|
243
|
+
} else if (e instanceof PayriffError) {
|
|
244
|
+
console.error(`Payriff error ${e.code} responseId=${e.responseId}`);
|
|
245
|
+
} else {
|
|
246
|
+
throw e;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Retries
|
|
252
|
+
|
|
253
|
+
The SDK never retries on its own, because payment calls are not safe to repeat blindly. After a
|
|
254
|
+
`PayriffConnectionError`, look the operation up first (`orders.getByRequestRrn(...)`,
|
|
255
|
+
`payouts.getByRequestRrn(...)`) and retry only if it does not exist. Set `requestRrn` /
|
|
256
|
+
`idempotencyKey` on every request so that this lookup is possible.
|
|
257
|
+
|
|
258
|
+
## Building from source
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npm install
|
|
262
|
+
npm test
|
|
263
|
+
npm run build
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CardsApi } from './resources/cards';
|
|
2
|
+
import { InvoicesApi } from './resources/invoices';
|
|
3
|
+
import { OrdersApi } from './resources/orders';
|
|
4
|
+
import { PaymentsApi } from './resources/payments';
|
|
5
|
+
import { PayoutsApi } from './resources/payouts';
|
|
6
|
+
import { TransactionsApi } from './resources/transactions';
|
|
7
|
+
import type { Region } from './types';
|
|
8
|
+
export interface PayriffOptions {
|
|
9
|
+
secretKey?: string;
|
|
10
|
+
/** @deprecated Use secretKey. */
|
|
11
|
+
appKey?: string;
|
|
12
|
+
merchantId?: string;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
region?: Region;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class Payriff {
|
|
18
|
+
readonly orders: OrdersApi;
|
|
19
|
+
readonly payments: PaymentsApi;
|
|
20
|
+
readonly cards: CardsApi;
|
|
21
|
+
readonly transactions: TransactionsApi;
|
|
22
|
+
readonly payouts: PayoutsApi;
|
|
23
|
+
readonly invoices: InvoicesApi;
|
|
24
|
+
constructor(options: PayriffOptions);
|
|
25
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payriff = void 0;
|
|
4
|
+
const cards_1 = require("./resources/cards");
|
|
5
|
+
const invoices_1 = require("./resources/invoices");
|
|
6
|
+
const orders_1 = require("./resources/orders");
|
|
7
|
+
const payments_1 = require("./resources/payments");
|
|
8
|
+
const payouts_1 = require("./resources/payouts");
|
|
9
|
+
const transactions_1 = require("./resources/transactions");
|
|
10
|
+
const transport_1 = require("./transport");
|
|
11
|
+
const REGIONS = {
|
|
12
|
+
azerbaijan: { baseUrl: 'https://api.payriff.com', currency: 'AZN' },
|
|
13
|
+
ksa: { baseUrl: 'https://api.gccpay.sa', currency: 'SAR' },
|
|
14
|
+
saudi: { baseUrl: 'https://api.gccpay.sa', currency: 'SAR' },
|
|
15
|
+
};
|
|
16
|
+
class Payriff {
|
|
17
|
+
orders;
|
|
18
|
+
payments;
|
|
19
|
+
cards;
|
|
20
|
+
transactions;
|
|
21
|
+
payouts;
|
|
22
|
+
invoices;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
const secretKey = options?.secretKey ?? options?.appKey;
|
|
25
|
+
if (typeof secretKey !== 'string' || secretKey.trim() === '') {
|
|
26
|
+
throw new TypeError('secretKey is required');
|
|
27
|
+
}
|
|
28
|
+
const timeout = options.timeout ?? 60_000;
|
|
29
|
+
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
30
|
+
throw new RangeError('timeout must be a positive number of milliseconds');
|
|
31
|
+
const regionName = options.region ?? 'azerbaijan';
|
|
32
|
+
if (!Object.hasOwn(REGIONS, regionName))
|
|
33
|
+
throw new RangeError(`unknown region: ${regionName}`);
|
|
34
|
+
const region = REGIONS[regionName];
|
|
35
|
+
const transport = new transport_1.Transport({
|
|
36
|
+
baseUrl: options.baseUrl ?? region.baseUrl,
|
|
37
|
+
secretKey,
|
|
38
|
+
merchantId: options.merchantId,
|
|
39
|
+
timeout,
|
|
40
|
+
});
|
|
41
|
+
this.orders = new orders_1.OrdersApi(transport, region.currency);
|
|
42
|
+
this.payments = new payments_1.PaymentsApi(transport, region.currency);
|
|
43
|
+
this.cards = new cards_1.CardsApi(transport);
|
|
44
|
+
this.transactions = new transactions_1.TransactionsApi(transport);
|
|
45
|
+
this.payouts = new payouts_1.PayoutsApi(transport);
|
|
46
|
+
this.invoices = new invoices_1.InvoicesApi(transport, region.currency);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Payriff = Payriff;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class PayriffError extends Error {
|
|
2
|
+
readonly httpStatus: number;
|
|
3
|
+
readonly code: string | undefined;
|
|
4
|
+
readonly responseId: string | undefined;
|
|
5
|
+
constructor(message: string, httpStatus: number, code?: string, responseId?: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export declare class ApiError extends PayriffError {
|
|
10
|
+
}
|
|
11
|
+
export declare class AuthenticationError extends ApiError {
|
|
12
|
+
}
|
|
13
|
+
export declare class ValidationError extends ApiError {
|
|
14
|
+
}
|
|
15
|
+
export declare class RequestRejectedError extends ApiError {
|
|
16
|
+
}
|
|
17
|
+
export declare class InsufficientBalanceError extends ApiError {
|
|
18
|
+
}
|
|
19
|
+
export declare class PayoutLimitError extends ApiError {
|
|
20
|
+
}
|
|
21
|
+
export declare class PayriffConnectionError extends PayriffError {
|
|
22
|
+
constructor(message: string, options?: {
|
|
23
|
+
cause?: unknown;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export declare const SUCCESS_CODE = "00000";
|
|
27
|
+
export declare function toApiError(message: string | undefined, httpStatus: number, code?: string, responseId?: string): ApiError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUCCESS_CODE = exports.PayriffConnectionError = exports.PayoutLimitError = exports.InsufficientBalanceError = exports.RequestRejectedError = exports.ValidationError = exports.AuthenticationError = exports.ApiError = exports.PayriffError = void 0;
|
|
4
|
+
exports.toApiError = toApiError;
|
|
5
|
+
class PayriffError extends Error {
|
|
6
|
+
httpStatus;
|
|
7
|
+
code;
|
|
8
|
+
responseId;
|
|
9
|
+
constructor(message, httpStatus, code, responseId, options) {
|
|
10
|
+
super(message, options);
|
|
11
|
+
this.name = new.target.name;
|
|
12
|
+
this.httpStatus = httpStatus;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.responseId = responseId;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PayriffError = PayriffError;
|
|
18
|
+
class ApiError extends PayriffError {
|
|
19
|
+
}
|
|
20
|
+
exports.ApiError = ApiError;
|
|
21
|
+
class AuthenticationError extends ApiError {
|
|
22
|
+
}
|
|
23
|
+
exports.AuthenticationError = AuthenticationError;
|
|
24
|
+
class ValidationError extends ApiError {
|
|
25
|
+
}
|
|
26
|
+
exports.ValidationError = ValidationError;
|
|
27
|
+
class RequestRejectedError extends ApiError {
|
|
28
|
+
}
|
|
29
|
+
exports.RequestRejectedError = RequestRejectedError;
|
|
30
|
+
class InsufficientBalanceError extends ApiError {
|
|
31
|
+
}
|
|
32
|
+
exports.InsufficientBalanceError = InsufficientBalanceError;
|
|
33
|
+
class PayoutLimitError extends ApiError {
|
|
34
|
+
}
|
|
35
|
+
exports.PayoutLimitError = PayoutLimitError;
|
|
36
|
+
class PayriffConnectionError extends PayriffError {
|
|
37
|
+
constructor(message, options) {
|
|
38
|
+
super(message, 0, undefined, undefined, options);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.PayriffConnectionError = PayriffConnectionError;
|
|
42
|
+
exports.SUCCESS_CODE = '00000';
|
|
43
|
+
const AUTH_CODES = new Set(['14010', '14013', '14014', '14015']);
|
|
44
|
+
const PAYOUT_LIMIT_CODES = new Set(['01300', '01400', '01500']);
|
|
45
|
+
function toApiError(message, httpStatus, code, responseId) {
|
|
46
|
+
const msg = message ? message : `Payriff request failed (HTTP ${httpStatus})`;
|
|
47
|
+
if (code !== undefined) {
|
|
48
|
+
if (AUTH_CODES.has(code))
|
|
49
|
+
return new AuthenticationError(msg, httpStatus, code, responseId);
|
|
50
|
+
if (PAYOUT_LIMIT_CODES.has(code))
|
|
51
|
+
return new PayoutLimitError(msg, httpStatus, code, responseId);
|
|
52
|
+
switch (code) {
|
|
53
|
+
case '01200':
|
|
54
|
+
return new InsufficientBalanceError(msg, httpStatus, code, responseId);
|
|
55
|
+
case '01000':
|
|
56
|
+
return new RequestRejectedError(msg, httpStatus, code, responseId);
|
|
57
|
+
case '15400':
|
|
58
|
+
return new ValidationError(msg, httpStatus, code, responseId);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (httpStatus === 401 || httpStatus === 403)
|
|
62
|
+
return new AuthenticationError(msg, httpStatus, code, responseId);
|
|
63
|
+
if (httpStatus === 400)
|
|
64
|
+
return new ValidationError(msg, httpStatus, code, responseId);
|
|
65
|
+
return new ApiError(msg, httpStatus, code, responseId);
|
|
66
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Payriff, type PayriffOptions } from './client';
|
|
2
|
+
export { PayriffError, ApiError, AuthenticationError, ValidationError, RequestRejectedError, InsufficientBalanceError, PayoutLimitError, PayriffConnectionError, } from './errors';
|
|
3
|
+
export { parseOrderCallback } from './webhooks';
|
|
4
|
+
export type { OrdersApi } from './resources/orders';
|
|
5
|
+
export type { PaymentsApi } from './resources/payments';
|
|
6
|
+
export type { CardsApi } from './resources/cards';
|
|
7
|
+
export type { TransactionsApi } from './resources/transactions';
|
|
8
|
+
export type { PayoutsApi } from './resources/payouts';
|
|
9
|
+
export type { InvoicesApi } from './resources/invoices';
|
|
10
|
+
export * from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.parseOrderCallback = exports.PayriffConnectionError = exports.PayoutLimitError = exports.InsufficientBalanceError = exports.RequestRejectedError = exports.ValidationError = exports.AuthenticationError = exports.ApiError = exports.PayriffError = exports.Payriff = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "Payriff", { enumerable: true, get: function () { return client_1.Payriff; } });
|
|
20
|
+
var errors_1 = require("./errors");
|
|
21
|
+
Object.defineProperty(exports, "PayriffError", { enumerable: true, get: function () { return errors_1.PayriffError; } });
|
|
22
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return errors_1.ApiError; } });
|
|
23
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
24
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
25
|
+
Object.defineProperty(exports, "RequestRejectedError", { enumerable: true, get: function () { return errors_1.RequestRejectedError; } });
|
|
26
|
+
Object.defineProperty(exports, "InsufficientBalanceError", { enumerable: true, get: function () { return errors_1.InsufficientBalanceError; } });
|
|
27
|
+
Object.defineProperty(exports, "PayoutLimitError", { enumerable: true, get: function () { return errors_1.PayoutLimitError; } });
|
|
28
|
+
Object.defineProperty(exports, "PayriffConnectionError", { enumerable: true, get: function () { return errors_1.PayriffConnectionError; } });
|
|
29
|
+
var webhooks_1 = require("./webhooks");
|
|
30
|
+
Object.defineProperty(exports, "parseOrderCallback", { enumerable: true, get: function () { return webhooks_1.parseOrderCallback; } });
|
|
31
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Transport } from '../transport';
|
|
2
|
+
import type { CardSaveDetails, CardSaveParams, CardSaveResponse, SavedCard } from '../types';
|
|
3
|
+
export declare class CardsApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: Transport);
|
|
6
|
+
save(params: CardSaveParams): Promise<CardSaveResponse>;
|
|
7
|
+
getSave(cardSaveId: string): Promise<CardSaveDetails>;
|
|
8
|
+
list(customerRef: string): Promise<SavedCard[]>;
|
|
9
|
+
delete(cardUuid: string): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CardsApi = void 0;
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
class CardsApi {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
async save(params) {
|
|
11
|
+
(0, util_1.required)(params, 'params');
|
|
12
|
+
return this.transport.execute({
|
|
13
|
+
method: 'POST',
|
|
14
|
+
path: '/api/v3/cards/save',
|
|
15
|
+
headers: { 'X-Idempotency-Key': params.idempotencyKey },
|
|
16
|
+
body: (0, util_1.compact)({
|
|
17
|
+
customerRef: (0, util_1.required)(params.customerRef, 'customerRef'),
|
|
18
|
+
callbackUrl: (0, util_1.required)(params.callbackUrl, 'callbackUrl'),
|
|
19
|
+
description: params.description,
|
|
20
|
+
language: params.language,
|
|
21
|
+
metadata: (0, util_1.nonEmpty)(params.metadata),
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async getSave(cardSaveId) {
|
|
26
|
+
return this.transport.execute({ method: 'GET', path: `/api/v3/cards/save/${(0, util_1.pathSegment)(cardSaveId, 'cardSaveId')}` });
|
|
27
|
+
}
|
|
28
|
+
async list(customerRef) {
|
|
29
|
+
(0, util_1.pathSegment)(customerRef, 'customerRef');
|
|
30
|
+
const cards = await this.transport.execute({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
path: '/api/v3/cards/save',
|
|
33
|
+
query: { customerRef },
|
|
34
|
+
});
|
|
35
|
+
return cards ?? [];
|
|
36
|
+
}
|
|
37
|
+
async delete(cardUuid) {
|
|
38
|
+
await this.transport.execute({ method: 'DELETE', path: `/api/v3/cards/${(0, util_1.pathSegment)(cardUuid, 'cardUuid')}` });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.CardsApi = CardsApi;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Transport } from '../transport';
|
|
2
|
+
import type { Currency, Invoice, InvoiceCreateParams, InvoiceDetails } from '../types';
|
|
3
|
+
export declare class InvoicesApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
private readonly defaultCurrency;
|
|
6
|
+
constructor(transport: Transport, defaultCurrency: Currency);
|
|
7
|
+
create(params: InvoiceCreateParams): Promise<Invoice>;
|
|
8
|
+
get(invoiceUuid: string): Promise<InvoiceDetails>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvoicesApi = void 0;
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
class InvoicesApi {
|
|
6
|
+
transport;
|
|
7
|
+
defaultCurrency;
|
|
8
|
+
constructor(transport, defaultCurrency) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
this.defaultCurrency = defaultCurrency;
|
|
11
|
+
}
|
|
12
|
+
async create(params) {
|
|
13
|
+
(0, util_1.required)(params, 'params');
|
|
14
|
+
if (params.amountDynamic !== true && (params.amount === undefined || params.amount === null)) {
|
|
15
|
+
throw new TypeError('amount is required');
|
|
16
|
+
}
|
|
17
|
+
return this.transport.execute({
|
|
18
|
+
method: 'POST',
|
|
19
|
+
path: '/api/v2/invoices',
|
|
20
|
+
merchantEnvelope: true,
|
|
21
|
+
body: (0, util_1.compact)({
|
|
22
|
+
amount: params.amount,
|
|
23
|
+
amountDynamic: params.amountDynamic,
|
|
24
|
+
currencyType: params.currency ?? this.defaultCurrency,
|
|
25
|
+
languageType: params.language,
|
|
26
|
+
fullName: params.fullName,
|
|
27
|
+
email: params.email,
|
|
28
|
+
phoneNumber: params.phoneNumber,
|
|
29
|
+
description: params.description,
|
|
30
|
+
customMessage: params.customMessage,
|
|
31
|
+
expireDate: (0, util_1.formatDateTime)(params.expireDate),
|
|
32
|
+
approveURL: params.approveUrl,
|
|
33
|
+
cancelURL: params.cancelUrl,
|
|
34
|
+
declineURL: params.declineUrl,
|
|
35
|
+
redirectURL: params.redirectUrl,
|
|
36
|
+
installmentProductType: params.installmentProductType,
|
|
37
|
+
installmentPeriod: params.installmentPeriod,
|
|
38
|
+
directPay: params.directPay,
|
|
39
|
+
sendSms: params.sendSms,
|
|
40
|
+
sendWhatsapp: params.sendWhatsapp,
|
|
41
|
+
sendEmail: params.sendEmail,
|
|
42
|
+
metadata: (0, util_1.nonEmpty)(params.metadata),
|
|
43
|
+
externalTransactionId: params.externalTransactionId,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async get(invoiceUuid) {
|
|
48
|
+
(0, util_1.pathSegment)(invoiceUuid, 'invoiceUuid');
|
|
49
|
+
return this.transport.execute({
|
|
50
|
+
method: 'POST',
|
|
51
|
+
path: '/api/v2/get-invoice',
|
|
52
|
+
merchantEnvelope: true,
|
|
53
|
+
body: { uuid: invoiceUuid },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.InvoicesApi = InvoicesApi;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Transport } from '../transport';
|
|
2
|
+
import type { CompleteParams, CreateOrderParams, CreateOrderResponse, Currency, OrderInfo, RefundParams } from '../types';
|
|
3
|
+
export declare class OrdersApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
private readonly defaultCurrency;
|
|
6
|
+
constructor(transport: Transport, defaultCurrency: Currency);
|
|
7
|
+
create(params: CreateOrderParams): Promise<CreateOrderResponse>;
|
|
8
|
+
get(orderId: string): Promise<OrderInfo>;
|
|
9
|
+
getStatus(orderId: string): Promise<OrderInfo>;
|
|
10
|
+
getByRequestRrn(requestRrn: string): Promise<OrderInfo>;
|
|
11
|
+
expire(orderId: string): Promise<void>;
|
|
12
|
+
refund(params: RefundParams): Promise<void>;
|
|
13
|
+
complete(params: CompleteParams): Promise<void>;
|
|
14
|
+
downloadReceipt(orderIdOrRrn: string): Promise<Buffer>;
|
|
15
|
+
}
|