@keytd/manat 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KeyTD
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,89 @@
1
- # Temporary Holding Version
1
+ # Manat for TypeScript / JavaScript
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ One API for Azerbaijani online payment providers: Kapital Bank, Azericard, Payriff, Epoint, GoldenPay and Yığım.
4
+ Node.js 18+, ESM and CommonJS, no runtime dependencies.
5
+
6
+ ```bash
7
+ npm i @keytd/manat
8
+ ```
9
+
10
+ ```ts
11
+ import {Manat, azn, kapitalBank} from '@keytd/manat';
12
+
13
+ const pay = new Manat(kapitalBank({username: process.env.KB_USER!, password: process.env.KB_PASSWORD!}));
14
+
15
+ const {paymentId, next} = await pay.createPayment({
16
+ orderId: 'A-1001',
17
+ amount: azn('25.50'), // {amount: 2550, currency: 'AZN'}; floats are never accepted
18
+ returnUrl: 'https://shop.az/payment/return',
19
+ });
20
+
21
+ // Send the customer on: a redirect, or (Azericard) an auto-submitted form.
22
+ if (next.type === 'redirect') res.redirect(next.url);
23
+ ```
24
+
25
+ Store `paymentId` with the order. It is what `getStatus`, `refund`, `capture` and `cancel` take.
26
+
27
+ ## Providers
28
+
29
+ ```ts
30
+ import {azericard, epoint, goldenPay, kapitalBank, payriff, yigim} from '@keytd/manat';
31
+
32
+ kapitalBank({username, password, environment: 'test'});
33
+ azericard({terminal, privateKey, gatewayPublicKey, merchantName, merchantUrl, environment: 'test'});
34
+ payriff({secretKey});
35
+ epoint({publicKey, privateKey});
36
+ goldenPay({authKey, merchantName, environment: 'test'});
37
+ yigim({merchant, apiKey, biller, environment: 'test'});
38
+ ```
39
+
40
+ | Provider | createPayment | verifyCallback | getStatus | refund | capture | cancel |
41
+ |--------------|:-:|:-:|:-:|:-:|:-:|:-:|
42
+ | Kapital Bank | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
43
+ | Azericard | ✓ (form POST) | ✓ | ✓ | ✓ | ✓ | ✓ |
44
+ | Payriff | ✓ | ✓ | ✓ | ✓ | ✓ | — |
45
+ | Epoint | ✓ | ✓ | ✓ | ✓ | — | — |
46
+ | GoldenPay | ✓ | ✓ | ✓ | ✓ | — | — |
47
+ | Yığım | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
48
+
49
+ `pay.supports('capture')` tells you at runtime; an unsupported call throws `unsupported_operation`.
50
+
51
+ ## Callbacks
52
+
53
+ Pass what your handler received. Signed callbacks are verified in constant time; unsigned redirects and
54
+ webhooks are never trusted: the adapter re-reads the payment from the provider's API.
55
+
56
+ ```ts
57
+ const event = await pay.verifyCallback({method: req.method, query: req.query, body: req.body, headers: req.headers});
58
+
59
+ if (event.status === 'paid') {
60
+ // fulfil order event.paymentId; for Azericard store event.providerRef for refunds
61
+ }
62
+ ```
63
+
64
+ Statuses: `pending`, `authorized`, `paid`, `failed`, `cancelled`, `refunded`, `partially_refunded`.
65
+
66
+ ## Refunds, capture, cancel
67
+
68
+ ```ts
69
+ await pay.refund({paymentId}); // full refund
70
+ await pay.refund({paymentId, amount: azn('10.00')}); // partial
71
+ await pay.capture({paymentId}); // after intent: 'authorize'
72
+ await pay.refund({paymentId, providerRef}); // Azericard needs the callback's providerRef
73
+ ```
74
+
75
+ ## Errors
76
+
77
+ Everything throws `ManatError`. `error.code` is one of `invalid_request`, `invalid_signature`, `provider_error`,
78
+ `network_error`, `unsupported_operation`; for provider errors `error.providerCode` and `error.providerMessage`
79
+ hold what the provider said and `error.raw` its whole reply. `isManatError(error, 'provider_error')` narrows the type.
80
+
81
+ ## HTTP
82
+
83
+ Requests use the global `fetch` with a 30-second timeout. To change either, pass options as the second argument:
84
+
85
+ ```ts
86
+ payriff({secretKey}, {timeoutMs: 10_000, fetch: myFetch});
87
+ ```
88
+
89
+ MIT licensed. Not affiliated with any bank or payment provider: test against your provider's sandbox before going live.