@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 +21 -0
- package/README.md +88 -2
- package/dist/index.cjs +1358 -0
- package/dist/index.d.cts +351 -0
- package/dist/index.d.ts +351 -0
- package/dist/index.js +1313 -0
- package/package.json +58 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
type Currency = 'AZN' | 'USD' | 'EUR' | 'RUB' | 'TRY' | 'GBP';
|
|
2
|
+
/** Integer amount in minor units: 2550 = 25.50 AZN. */
|
|
3
|
+
interface Money {
|
|
4
|
+
amount: number;
|
|
5
|
+
currency: Currency;
|
|
6
|
+
}
|
|
7
|
+
type PaymentStatus = 'pending' | 'authorized' | 'paid' | 'failed' | 'cancelled' | 'refunded' | 'partially_refunded';
|
|
8
|
+
type Language = 'az' | 'en' | 'ru';
|
|
9
|
+
interface CreatePaymentRequest {
|
|
10
|
+
orderId: string;
|
|
11
|
+
amount: Money;
|
|
12
|
+
returnUrl: string;
|
|
13
|
+
callbackUrl?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
language?: Language;
|
|
16
|
+
intent?: 'purchase' | 'authorize';
|
|
17
|
+
customer?: {
|
|
18
|
+
email?: string;
|
|
19
|
+
phone?: string;
|
|
20
|
+
};
|
|
21
|
+
metadata?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
type NextAction = {
|
|
24
|
+
type: 'redirect';
|
|
25
|
+
url: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'form';
|
|
28
|
+
url: string;
|
|
29
|
+
method: 'POST';
|
|
30
|
+
fields: Record<string, string>;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'none';
|
|
33
|
+
};
|
|
34
|
+
interface CreatePaymentResult {
|
|
35
|
+
paymentId: string;
|
|
36
|
+
status: PaymentStatus;
|
|
37
|
+
next: NextAction;
|
|
38
|
+
raw: unknown;
|
|
39
|
+
}
|
|
40
|
+
interface IncomingCallback {
|
|
41
|
+
method: string;
|
|
42
|
+
query?: Record<string, string | string[] | undefined>;
|
|
43
|
+
body?: Record<string, unknown> | string;
|
|
44
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
45
|
+
}
|
|
46
|
+
interface PaymentEvent {
|
|
47
|
+
paymentId: string;
|
|
48
|
+
orderId?: string;
|
|
49
|
+
status: PaymentStatus;
|
|
50
|
+
amount?: Money;
|
|
51
|
+
/**
|
|
52
|
+
* Opaque provider data needed for later operations (e.g. Azericard's RRN and INT_REF).
|
|
53
|
+
* Store it with the order and pass it back to refund/capture/cancel unchanged.
|
|
54
|
+
*/
|
|
55
|
+
providerRef?: string;
|
|
56
|
+
raw: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface PaymentState {
|
|
59
|
+
paymentId: string;
|
|
60
|
+
status: PaymentStatus;
|
|
61
|
+
amount?: Money;
|
|
62
|
+
refundedAmount?: Money;
|
|
63
|
+
providerRef?: string;
|
|
64
|
+
raw: unknown;
|
|
65
|
+
}
|
|
66
|
+
/** Input for capture/cancel. */
|
|
67
|
+
interface PaymentAction {
|
|
68
|
+
paymentId: string;
|
|
69
|
+
/** From PaymentEvent.providerRef, for providers that need it. */
|
|
70
|
+
providerRef?: string;
|
|
71
|
+
amount?: Money;
|
|
72
|
+
}
|
|
73
|
+
interface RefundRequest {
|
|
74
|
+
paymentId: string;
|
|
75
|
+
/** From PaymentEvent.providerRef, for providers that need it. */
|
|
76
|
+
providerRef?: string;
|
|
77
|
+
/** Omit for a full refund. */
|
|
78
|
+
amount?: Money;
|
|
79
|
+
}
|
|
80
|
+
interface RefundResult {
|
|
81
|
+
paymentId: string;
|
|
82
|
+
refundId?: string;
|
|
83
|
+
status: PaymentStatus;
|
|
84
|
+
raw: unknown;
|
|
85
|
+
}
|
|
86
|
+
type Capability = 'createPayment' | 'verifyCallback' | 'getStatus' | 'refund' | 'capture' | 'cancel';
|
|
87
|
+
/** What every provider adapter implements. Optional operations may be absent. */
|
|
88
|
+
interface PaymentProvider {
|
|
89
|
+
readonly name: string;
|
|
90
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
91
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
92
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
93
|
+
getStatus?(input: {
|
|
94
|
+
paymentId: string;
|
|
95
|
+
}): Promise<PaymentState>;
|
|
96
|
+
refund?(request: RefundRequest): Promise<RefundResult>;
|
|
97
|
+
capture?(input: PaymentAction): Promise<PaymentState>;
|
|
98
|
+
cancel?(input: PaymentAction): Promise<PaymentState>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Provider-neutral facade. Validates input once, then delegates to the adapter,
|
|
103
|
+
* so every provider gets the same checks and the same errors.
|
|
104
|
+
*/
|
|
105
|
+
declare class Manat {
|
|
106
|
+
readonly provider: PaymentProvider;
|
|
107
|
+
constructor(provider: PaymentProvider);
|
|
108
|
+
get capabilities(): ReadonlySet<Capability>;
|
|
109
|
+
supports(capability: Capability): boolean;
|
|
110
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
111
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
112
|
+
getStatus(input: {
|
|
113
|
+
paymentId: string;
|
|
114
|
+
}): Promise<PaymentState>;
|
|
115
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
116
|
+
capture(input: PaymentAction): Promise<PaymentState>;
|
|
117
|
+
cancel(input: PaymentAction): Promise<PaymentState>;
|
|
118
|
+
private call;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type ManatErrorCode = 'invalid_request' | 'invalid_signature' | 'provider_error' | 'network_error' | 'unsupported_operation';
|
|
122
|
+
declare class ManatError extends Error {
|
|
123
|
+
readonly code: ManatErrorCode;
|
|
124
|
+
readonly provider: string | undefined;
|
|
125
|
+
readonly providerCode: string | undefined;
|
|
126
|
+
readonly providerMessage: string | undefined;
|
|
127
|
+
readonly raw: unknown;
|
|
128
|
+
constructor(code: ManatErrorCode, message: string, details?: {
|
|
129
|
+
provider?: string;
|
|
130
|
+
providerCode?: string;
|
|
131
|
+
providerMessage?: string;
|
|
132
|
+
raw?: unknown;
|
|
133
|
+
cause?: unknown;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
declare function isManatError(error: unknown, code?: ManatErrorCode): error is ManatError;
|
|
137
|
+
|
|
138
|
+
/** 2550 AZN → "25.50" (no floats involved). */
|
|
139
|
+
declare function toDecimalString(money: Money): string;
|
|
140
|
+
/** "25.5" / "25.50" / 25.5 → 2550. Rejects more decimals than the currency has. */
|
|
141
|
+
declare function fromDecimal(value: string | number, currency: Currency): Money;
|
|
142
|
+
/** Convenience for callers: Manat.azn(25.5) → { amount: 2550, currency: 'AZN' }. */
|
|
143
|
+
declare function azn(value: string | number): Money;
|
|
144
|
+
|
|
145
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
146
|
+
interface HttpOptions {
|
|
147
|
+
fetch?: FetchLike;
|
|
148
|
+
/** Per-request timeout in milliseconds. Default 30 000. */
|
|
149
|
+
timeoutMs?: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface KapitalBankConfig {
|
|
153
|
+
/** API user issued by the bank, e.g. "TerminalSys/xxxx". */
|
|
154
|
+
username: string;
|
|
155
|
+
password: string;
|
|
156
|
+
environment?: 'test' | 'production';
|
|
157
|
+
/** Override the API base URL (ends with /api). */
|
|
158
|
+
baseUrl?: string;
|
|
159
|
+
}
|
|
160
|
+
declare class KapitalBankProvider implements PaymentProvider {
|
|
161
|
+
readonly name = "kapitalbank";
|
|
162
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
163
|
+
private readonly http;
|
|
164
|
+
private readonly baseUrl;
|
|
165
|
+
private readonly authHeader;
|
|
166
|
+
constructor(config: KapitalBankConfig, options?: HttpOptions);
|
|
167
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
168
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
169
|
+
getStatus({ paymentId }: {
|
|
170
|
+
paymentId: string;
|
|
171
|
+
}): Promise<PaymentState>;
|
|
172
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
173
|
+
capture({ paymentId, amount }: PaymentAction): Promise<PaymentState>;
|
|
174
|
+
cancel({ paymentId }: PaymentAction): Promise<PaymentState>;
|
|
175
|
+
private remainingRefundable;
|
|
176
|
+
private fetchOrder;
|
|
177
|
+
private toState;
|
|
178
|
+
private exec;
|
|
179
|
+
private call;
|
|
180
|
+
}
|
|
181
|
+
declare function kapitalBank(config: KapitalBankConfig, options?: HttpOptions): KapitalBankProvider;
|
|
182
|
+
|
|
183
|
+
type AzericardMessage = 'purchase' | 'completion' | 'reversal' | 'callback' | 'status';
|
|
184
|
+
interface AzericardConfig {
|
|
185
|
+
/** TERMINAL id assigned by the bank (8 characters). */
|
|
186
|
+
terminal: string;
|
|
187
|
+
/** Merchant RSA private key (PEM, at least 2048-bit) used to sign requests. */
|
|
188
|
+
privateKey: string;
|
|
189
|
+
/** Gateway (MPI) public key (PEM) used to verify callbacks. Required for verifyCallback. */
|
|
190
|
+
gatewayPublicKey?: string;
|
|
191
|
+
/** MERCH_NAME shown to the cardholder (1–50 chars). */
|
|
192
|
+
merchantName: string;
|
|
193
|
+
/** MERCH_URL: the shop's main website. */
|
|
194
|
+
merchantUrl: string;
|
|
195
|
+
environment?: 'test' | 'production';
|
|
196
|
+
/** Override the cgi_link URL. */
|
|
197
|
+
gatewayUrl?: string;
|
|
198
|
+
/** EMAIL: where the gateway may send result notifications. */
|
|
199
|
+
email?: string;
|
|
200
|
+
/** COUNTRY: only if the shop is outside Azerbaijan. */
|
|
201
|
+
country?: string;
|
|
202
|
+
/** MERCH_GMT: only if the shop's time zone differs from the gateway's (e.g. "+4"). */
|
|
203
|
+
merchantGmt?: string;
|
|
204
|
+
/** Override MAC field orders if your terminal was configured differently. */
|
|
205
|
+
macFields?: Partial<Record<AzericardMessage, string[]>>;
|
|
206
|
+
/** Testing hooks: fixed clock and nonce. */
|
|
207
|
+
clock?: () => Date;
|
|
208
|
+
nonce?: () => string;
|
|
209
|
+
}
|
|
210
|
+
/** MAC field orders per message type. */
|
|
211
|
+
declare const AZERICARD_MAC_FIELDS: Readonly<Record<AzericardMessage, readonly string[]>>;
|
|
212
|
+
declare class AzericardProvider implements PaymentProvider {
|
|
213
|
+
private readonly config;
|
|
214
|
+
readonly name = "azericard";
|
|
215
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
216
|
+
private readonly http;
|
|
217
|
+
private readonly url;
|
|
218
|
+
private readonly privateKey;
|
|
219
|
+
private readonly gatewayKey;
|
|
220
|
+
private readonly macFields;
|
|
221
|
+
private readonly clock;
|
|
222
|
+
private readonly makeNonce;
|
|
223
|
+
constructor(config: AzericardConfig, options?: HttpOptions);
|
|
224
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
225
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
226
|
+
/** TRTYPE 90 answers for one transaction type, so the purchase (or pre-auth), completion and reversals are each queried. */
|
|
227
|
+
getStatus({ paymentId }: {
|
|
228
|
+
paymentId: string;
|
|
229
|
+
}): Promise<PaymentState>;
|
|
230
|
+
private relatedTransactions;
|
|
231
|
+
private queryStatus;
|
|
232
|
+
capture(input: PaymentAction): Promise<PaymentState>;
|
|
233
|
+
cancel(input: PaymentAction): Promise<PaymentState>;
|
|
234
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
235
|
+
private send;
|
|
236
|
+
private sign;
|
|
237
|
+
}
|
|
238
|
+
declare function azericard(config: AzericardConfig, options?: HttpOptions): AzericardProvider;
|
|
239
|
+
|
|
240
|
+
interface PayriffConfig {
|
|
241
|
+
/** Application secret key from the Payriff dashboard. */
|
|
242
|
+
secretKey: string;
|
|
243
|
+
/** Override the API host (default https://api.payriff.com). */
|
|
244
|
+
baseUrl?: string;
|
|
245
|
+
}
|
|
246
|
+
declare class PayriffProvider implements PaymentProvider {
|
|
247
|
+
private readonly config;
|
|
248
|
+
readonly name = "payriff";
|
|
249
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
250
|
+
private readonly http;
|
|
251
|
+
private readonly baseUrl;
|
|
252
|
+
constructor(config: PayriffConfig, options?: HttpOptions);
|
|
253
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
254
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
255
|
+
getStatus({ paymentId }: {
|
|
256
|
+
paymentId: string;
|
|
257
|
+
}): Promise<PaymentState>;
|
|
258
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
259
|
+
capture({ paymentId, amount }: PaymentAction): Promise<PaymentState>;
|
|
260
|
+
private call;
|
|
261
|
+
private callEnvelope;
|
|
262
|
+
}
|
|
263
|
+
declare function payriff(config: PayriffConfig, options?: HttpOptions): PayriffProvider;
|
|
264
|
+
|
|
265
|
+
interface EpointConfig {
|
|
266
|
+
/** Merchant public key, e.g. "i000000001". */
|
|
267
|
+
publicKey: string;
|
|
268
|
+
/** Merchant private key from the Epoint panel; signs requests and verifies callbacks. */
|
|
269
|
+
privateKey: string;
|
|
270
|
+
/** Override the API base (default https://epoint.az/api/1). */
|
|
271
|
+
baseUrl?: string;
|
|
272
|
+
}
|
|
273
|
+
declare class EpointProvider implements PaymentProvider {
|
|
274
|
+
private readonly config;
|
|
275
|
+
readonly name = "epoint";
|
|
276
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
277
|
+
private readonly http;
|
|
278
|
+
private readonly baseUrl;
|
|
279
|
+
constructor(config: EpointConfig, options?: HttpOptions);
|
|
280
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
281
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
282
|
+
getStatus({ paymentId }: {
|
|
283
|
+
paymentId: string;
|
|
284
|
+
}): Promise<PaymentState>;
|
|
285
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
286
|
+
private call;
|
|
287
|
+
private error;
|
|
288
|
+
}
|
|
289
|
+
declare function epoint(config: EpointConfig, options?: HttpOptions): EpointProvider;
|
|
290
|
+
|
|
291
|
+
interface GoldenPayConfig {
|
|
292
|
+
/** Auth key from the GoldenPay merchant panel; signs every request. */
|
|
293
|
+
authKey: string;
|
|
294
|
+
/** Merchant name issued by GoldenPay. */
|
|
295
|
+
merchantName: string;
|
|
296
|
+
environment?: 'test' | 'production';
|
|
297
|
+
/** Override the API host (also used for the payment page). */
|
|
298
|
+
baseUrl?: string;
|
|
299
|
+
}
|
|
300
|
+
declare class GoldenPayProvider implements PaymentProvider {
|
|
301
|
+
private readonly config;
|
|
302
|
+
readonly name = "goldenpay";
|
|
303
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
304
|
+
private readonly http;
|
|
305
|
+
private readonly baseUrl;
|
|
306
|
+
constructor(config: GoldenPayConfig, options?: HttpOptions);
|
|
307
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
308
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
309
|
+
getStatus({ paymentId }: {
|
|
310
|
+
paymentId: string;
|
|
311
|
+
}): Promise<PaymentState>;
|
|
312
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
313
|
+
private call;
|
|
314
|
+
private error;
|
|
315
|
+
}
|
|
316
|
+
declare function goldenPay(config: GoldenPayConfig, options?: HttpOptions): GoldenPayProvider;
|
|
317
|
+
|
|
318
|
+
interface YigimConfig {
|
|
319
|
+
/** Merchant name issued by Yığım (`X-Merchant`). */
|
|
320
|
+
merchant: string;
|
|
321
|
+
/** API key issued by Yığım (`X-API-Key`). */
|
|
322
|
+
apiKey: string;
|
|
323
|
+
/** Biller name provided by the acquirer. */
|
|
324
|
+
biller: string;
|
|
325
|
+
/** Payment page template; default `TPL0001`. */
|
|
326
|
+
template?: string;
|
|
327
|
+
environment?: 'test' | 'production';
|
|
328
|
+
/** Override the API host. */
|
|
329
|
+
baseUrl?: string;
|
|
330
|
+
}
|
|
331
|
+
declare class YigimProvider implements PaymentProvider {
|
|
332
|
+
private readonly config;
|
|
333
|
+
readonly name = "yigim";
|
|
334
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
335
|
+
private readonly http;
|
|
336
|
+
private readonly baseUrl;
|
|
337
|
+
constructor(config: YigimConfig, options?: HttpOptions);
|
|
338
|
+
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResult>;
|
|
339
|
+
verifyCallback(callback: IncomingCallback): Promise<PaymentEvent>;
|
|
340
|
+
getStatus({ paymentId }: {
|
|
341
|
+
paymentId: string;
|
|
342
|
+
}): Promise<PaymentState>;
|
|
343
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
344
|
+
capture({ paymentId, amount }: PaymentAction): Promise<PaymentState>;
|
|
345
|
+
cancel({ paymentId }: PaymentAction): Promise<PaymentState>;
|
|
346
|
+
private call;
|
|
347
|
+
private error;
|
|
348
|
+
}
|
|
349
|
+
declare function yigim(config: YigimConfig, options?: HttpOptions): YigimProvider;
|
|
350
|
+
|
|
351
|
+
export { AZERICARD_MAC_FIELDS, type AzericardConfig, type AzericardMessage, AzericardProvider, type Capability, type CreatePaymentRequest, type CreatePaymentResult, type Currency, type EpointConfig, EpointProvider, type FetchLike, type GoldenPayConfig, GoldenPayProvider, type HttpOptions, type IncomingCallback, type KapitalBankConfig, KapitalBankProvider, type Language, Manat, ManatError, type ManatErrorCode, type Money, type NextAction, type PaymentAction, type PaymentEvent, type PaymentProvider, type PaymentState, type PaymentStatus, type PayriffConfig, PayriffProvider, type RefundRequest, type RefundResult, type YigimConfig, YigimProvider, azericard, azn, epoint, fromDecimal, goldenPay, isManatError, kapitalBank, payriff, toDecimalString, yigim };
|