@dpayglobal/dpay-node-sdk 0.1.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.
@@ -0,0 +1,876 @@
1
+ import { H as HttpClient, A as ApiResponse, a as ApiRequest } from './types-CGcSNriz.cjs';
2
+ import { inspect } from 'node:util';
3
+
4
+ type BaseUrlKey = 'apiPayments' | 'panel' | 'gateway';
5
+ declare class BaseUrls {
6
+ private readonly urls;
7
+ constructor(overrides?: Readonly<Record<string, string>>);
8
+ resolve(host: BaseUrlKey): string;
9
+ }
10
+
11
+ /** Default HTTP timeout in milliseconds. */
12
+ declare const DEFAULT_TIMEOUT = 30000;
13
+ /** Per-call overrides accepted as the last argument of every service method. */
14
+ interface RequestOptions {
15
+ /** Cancels the call. Combined with the configured timeout. */
16
+ signal?: AbortSignal;
17
+ /** Timeout for this call only, in milliseconds. */
18
+ timeout?: number;
19
+ }
20
+ /** What `onRequest` receives. Sensitive values are already redacted. */
21
+ interface RequestHookContext {
22
+ readonly method: string;
23
+ readonly url: string;
24
+ readonly headers: Readonly<Record<string, string>>;
25
+ readonly body: string | null;
26
+ }
27
+ /** What `onResponse` receives. */
28
+ interface ResponseHookContext {
29
+ readonly status: number;
30
+ readonly url: string;
31
+ readonly body: string;
32
+ }
33
+ /** Options accepted by `new DPayClient(...)`. */
34
+ interface DPayClientOptions {
35
+ /** Payment point name from panel.dpay.pl. */
36
+ service: string;
37
+ /** Secret Hash key from panel.dpay.pl. Never expose it to a browser. */
38
+ secretHash: string;
39
+ /** HTTP timeout in milliseconds. Defaults to 30000. */
40
+ timeout?: number;
41
+ /** Custom transport for proxying, retries or tests. */
42
+ httpClient?: HttpClient;
43
+ /** Overrides for the `apiPayments`, `panel` and `gateway` hosts. */
44
+ baseUrls?: Record<string, string>;
45
+ /** Called before every request, with the checksum and card data redacted. */
46
+ onRequest?: (context: RequestHookContext) => void;
47
+ /** Called after every response that reached the SDK. */
48
+ onResponse?: (context: ResponseHookContext) => void;
49
+ }
50
+ declare class Config {
51
+ readonly service: string;
52
+ readonly secretHash: string;
53
+ readonly timeout: number;
54
+ readonly httpClient: HttpClient | null;
55
+ readonly baseUrls: BaseUrls;
56
+ readonly onRequest: ((context: RequestHookContext) => void) | null;
57
+ readonly onResponse: ((context: ResponseHookContext) => void) | null;
58
+ private constructor();
59
+ static fromOptions(options: DPayClientOptions): Config;
60
+ }
61
+
62
+ declare class ChecksumCalculator {
63
+ private readonly secretHash;
64
+ constructor(secretHash: string);
65
+ secretSecond(service: string, fields: readonly unknown[]): string;
66
+ orderedBody(values: readonly unknown[]): string;
67
+ }
68
+
69
+ interface Operation<T> {
70
+ readonly method: 'GET' | 'POST';
71
+ readonly host: BaseUrlKey;
72
+ readonly path: string;
73
+ readonly parse: (response: ApiResponse) => T;
74
+ readonly body?: Record<string, unknown>;
75
+ readonly raiseForStatus?: boolean;
76
+ }
77
+
78
+ declare class ApiRequestor {
79
+ readonly service: string;
80
+ readonly checksum: ChecksumCalculator;
81
+ private readonly config;
82
+ private readonly httpClient;
83
+ constructor(config: Config, httpClient: HttpClient);
84
+ execute<T>(operation: Operation<T>, options?: RequestOptions): Promise<T>;
85
+ private buildRequest;
86
+ private resolveSignal;
87
+ private notify;
88
+ }
89
+
90
+ /** A bank offered on the transfer payment page. */
91
+ interface Bank {
92
+ readonly id: string;
93
+ readonly name: string;
94
+ /** Logo file name, when the API provides one. */
95
+ readonly image: string | null;
96
+ /** First hour of the day the bank accepts transfers. */
97
+ readonly onFrom: number;
98
+ /** Last hour of the day the bank accepts transfers. */
99
+ readonly onTo: number;
100
+ readonly iterator: number | null;
101
+ readonly isTest: boolean;
102
+ readonly type: string | null;
103
+ readonly raw: Record<string, unknown>;
104
+ }
105
+
106
+ /** Lists the banks dpay supports for transfer payments. */
107
+ declare class BankService {
108
+ private readonly api;
109
+ constructor(api: ApiRequestor);
110
+ /** Every bank dpay supports. */
111
+ all(options?: RequestOptions): Promise<Bank[]>;
112
+ /** Banks enabled for this payment point. Defaults `timestamp` to the current clock. */
113
+ forService(params?: {
114
+ timestamp?: number;
115
+ }, options?: RequestOptions): Promise<Bank[]>;
116
+ }
117
+
118
+ /** BLIK alias namespace. */
119
+ declare const BlikAliasType: {
120
+ readonly UID: "UID";
121
+ readonly PAYID: "PAYID";
122
+ };
123
+ type BlikAliasType = (typeof BlikAliasType)[keyof typeof BlikAliasType];
124
+
125
+ /** A banking app that accepted the alias. */
126
+ interface BlikApp {
127
+ readonly key: string | null;
128
+ readonly label: string | null;
129
+ }
130
+ /** A registered BLIK alias. */
131
+ interface BlikAlias {
132
+ readonly aliasValue: string;
133
+ readonly aliasType: BlikAliasType | (string & {});
134
+ readonly status: string | null;
135
+ readonly expirationDate: string | null;
136
+ readonly apps: readonly BlikApp[];
137
+ readonly isActive: boolean;
138
+ readonly raw: Record<string, unknown>;
139
+ }
140
+ /** Mandate parameters attached to a recurring alias. */
141
+ interface BlikRecurringRegistrationInfo {
142
+ readonly model: string | null;
143
+ readonly frequency: string | null;
144
+ /** Single charge limit in minor units. */
145
+ readonly limitAmt: number | null;
146
+ /** Total limit in minor units. */
147
+ readonly totLimitAmt: number | null;
148
+ readonly isLimitAmtFixed: boolean | null;
149
+ readonly initDate: string | null;
150
+ readonly label: string | null;
151
+ readonly registeredAt: string | null;
152
+ readonly raw: Record<string, unknown>;
153
+ }
154
+ /** State of a recurring BLIK mandate. */
155
+ interface BlikRecurringStatus {
156
+ readonly aliasValue: string;
157
+ readonly aliasType: BlikAliasType | (string & {});
158
+ readonly status: string | null;
159
+ readonly expirationDate: string | null;
160
+ readonly registration: BlikRecurringRegistrationInfo | null;
161
+ readonly isActive: boolean;
162
+ readonly raw: Record<string, unknown>;
163
+ }
164
+
165
+ interface BlikAliasParams {
166
+ aliasValue: string;
167
+ aliasType?: BlikAliasType | (string & {});
168
+ }
169
+ interface BlikUnregisterAliasParams extends BlikAliasParams {
170
+ reason?: string;
171
+ }
172
+
173
+ /** Registers, reads and unregisters BLIK aliases, and reads recurring mandate status. */
174
+ declare class BlikService {
175
+ private readonly api;
176
+ constructor(api: ApiRequestor);
177
+ /** Registers a BLIK alias so the payer can pay without a code next time. */
178
+ alias(params: BlikAliasParams, options?: RequestOptions): Promise<BlikAlias>;
179
+ /** Removes a BLIK alias. */
180
+ unregisterAlias(params: BlikUnregisterAliasParams, options?: RequestOptions): Promise<void>;
181
+ /** Reads the state of a recurring BLIK mandate. */
182
+ recurringStatus(params: {
183
+ aliasValue: string;
184
+ }, options?: RequestOptions): Promise<BlikRecurringStatus>;
185
+ }
186
+
187
+ /** A monetary amount held in minor units, never as a float. */
188
+ declare class Money {
189
+ /** Amount in minor units, for example 1050 for 10.50 PLN. */
190
+ readonly minor: number;
191
+ /** Three-letter currency code. */
192
+ readonly currency: string;
193
+ private constructor();
194
+ /** Amount in Polish grosz, for example `Money.pln(1050)` is 10.50 PLN. */
195
+ static pln(minor: number): Money;
196
+ /** Amount in minor units of an arbitrary currency. */
197
+ static of(minor: number, currency: string): Money;
198
+ /** Parses a decimal string with at most two fraction digits. */
199
+ static fromDecimal(decimal: string, currency: string): Money;
200
+ /** Parses whatever shape the API used for this field. Throws on anything unparsable. */
201
+ static fromApiNumber(value: unknown, currency: string): Money;
202
+ /** Same as `fromApiNumber`, but returns null instead of throwing. */
203
+ static tryFromApiNumber(value: unknown, currency: string): Money | null;
204
+ /** Renders the amount as a decimal string with exactly two fraction digits. */
205
+ toDecimal(): string;
206
+ get isNegative(): boolean;
207
+ equals(other: Money): boolean;
208
+ toString(): string;
209
+ toJSON(): {
210
+ minor: number;
211
+ currency: string;
212
+ };
213
+ }
214
+
215
+ /** What the merchant must do next after a card operation. */
216
+ declare const RedirectType: {
217
+ readonly SUCCESS: "SUCCESS";
218
+ readonly FORM: "FORM";
219
+ readonly URL: "URL";
220
+ readonly DCC_OFFER: "DCC_OFFER";
221
+ };
222
+ type RedirectType = (typeof RedirectType)[keyof typeof RedirectType];
223
+ /** Payer's answer to a dynamic currency conversion offer. */
224
+ declare const DccDecision: {
225
+ readonly ACCEPT: "accept";
226
+ readonly REJECT: "reject";
227
+ };
228
+ type DccDecision = (typeof DccDecision)[keyof typeof DccDecision];
229
+ /** Card-on-file operation requested at registration time. */
230
+ declare const CardRecurringOperation: {
231
+ readonly ADD_CARD: "add_card";
232
+ readonly COF_INITIAL: "cof_initial";
233
+ readonly CHARGE: "charge";
234
+ };
235
+ type CardRecurringOperation = (typeof CardRecurringOperation)[keyof typeof CardRecurringOperation];
236
+ /** Charge cadence of a card mandate. */
237
+ declare const CardRecurringFrequency: {
238
+ readonly DAILY: "DAILY";
239
+ readonly WEEKLY: "WEEKLY";
240
+ readonly BIWEEKLY: "BIWEEKLY";
241
+ readonly MONTHLY: "MONTHLY";
242
+ readonly QUARTERLY: "QUARTERLY";
243
+ readonly SEMIANNUAL: "SEMIANNUAL";
244
+ readonly ANNUAL: "ANNUAL";
245
+ };
246
+ type CardRecurringFrequency = (typeof CardRecurringFrequency)[keyof typeof CardRecurringFrequency];
247
+
248
+ /** One markup component of a DCC offer. */
249
+ interface DccMarkup {
250
+ readonly rate: number;
251
+ readonly additionalInfo: string | null;
252
+ }
253
+ /** Dynamic currency conversion offer the payer must accept or reject. */
254
+ interface DccOffer {
255
+ readonly currencyConversionId: string;
256
+ readonly originalAmount: Money;
257
+ readonly convertedAmount: Money;
258
+ readonly exchangeRate: number;
259
+ readonly validUntil: string;
260
+ /** PSD2 declaration text that must be shown to the payer verbatim. */
261
+ readonly declarationText: string;
262
+ readonly isEuropeanEconomicArea: boolean;
263
+ readonly markup: readonly DccMarkup[];
264
+ readonly raw: Record<string, unknown>;
265
+ }
266
+ /** Outcome of a card operation. */
267
+ interface CardPaymentResult {
268
+ readonly redirectType: RedirectType | (string & {}) | null;
269
+ readonly redirectText: string | null;
270
+ readonly isSuccess: boolean;
271
+ readonly requiresThreeDsForm: boolean;
272
+ readonly requiresRedirect: boolean;
273
+ readonly hasDccOffer: boolean;
274
+ /** Decoded 3-D Secure form to render, when `requiresThreeDsForm`. */
275
+ readonly threeDsFormHtml: string | null;
276
+ /** Decoded URL to send the payer to, when `requiresRedirect`. */
277
+ readonly redirectUrl: string | null;
278
+ readonly dccOffer: DccOffer | null;
279
+ readonly raw: Record<string, unknown>;
280
+ }
281
+
282
+ /** Payment flow requested at registration time. */
283
+ declare const TransactionType: {
284
+ readonly TRANSFERS: "transfers";
285
+ readonly DCB_GATEWAY: "dcb_gateway";
286
+ readonly CARD_AUTH: "card_auth";
287
+ readonly MB_WAY_DIRECT: "mb_way_direct";
288
+ readonly BIZUM_DIRECT: "bizum_direct";
289
+ readonly BLIK_RECURRING: "blik_recurring";
290
+ readonly CARD_RECURRING: "card_recurring";
291
+ };
292
+ type TransactionType = (typeof TransactionType)[keyof typeof TransactionType];
293
+ /** Lifecycle state of a transaction. The API may return values outside this list. */
294
+ declare const TransactionStatus: {
295
+ readonly PAID: "paid";
296
+ readonly CREATED: "created";
297
+ readonly PROCESSING: "processing";
298
+ readonly EXPIRED: "expired";
299
+ readonly CAPTURED: "captured";
300
+ };
301
+ type TransactionStatus = (typeof TransactionStatus)[keyof typeof TransactionStatus];
302
+ /** Who absorbs the payout fee. */
303
+ declare const PayoutFeeMode: {
304
+ readonly NET: "net";
305
+ readonly GROSS: "gross";
306
+ };
307
+ type PayoutFeeMode = (typeof PayoutFeeMode)[keyof typeof PayoutFeeMode];
308
+
309
+ /** Where dpay sends the payer back, and where it posts the IPN. */
310
+ interface ReturnUrls {
311
+ /** Payer returns here after a successful payment. */
312
+ success: string;
313
+ /** Payer returns here after a failed payment. */
314
+ fail: string;
315
+ /** dpay posts the IPN here. Must be reachable from the internet. */
316
+ ipn: string;
317
+ }
318
+ /** Optional payer identity, prefilled on the payment page. */
319
+ interface PayerParams {
320
+ email?: string;
321
+ firstName?: string;
322
+ lastName?: string;
323
+ }
324
+ /** 3-D Secure device fingerprint, required for card payments. */
325
+ interface DeviceInfoParams {
326
+ browserAcceptHeader: string;
327
+ browserLanguage: string;
328
+ browserColorDepth: number;
329
+ browserScreenHeight: number;
330
+ browserScreenWidth: number;
331
+ /** Timezone offset in minutes, as reported by `Date.prototype.getTimezoneOffset`. */
332
+ browserTz: number;
333
+ browserUserAgent: string;
334
+ systemFamily: string;
335
+ geoLocalization: string;
336
+ /** 1 to 64 characters. */
337
+ deviceId: string;
338
+ /** 1 to 64 characters. */
339
+ applicationName: string;
340
+ browserJavaEnabled?: boolean | undefined;
341
+ }
342
+ /** KSeF invoice details, only valid together with `efaktura`. */
343
+ interface InvoiceParams {
344
+ payerNip?: string;
345
+ payerName?: string;
346
+ invoiceNumber?: string;
347
+ /** YYYY-MM-DD. */
348
+ paymentDueDate?: string;
349
+ vatAmount?: Money;
350
+ }
351
+ /** One leg of a 1:1 payout attached to a payment. */
352
+ interface PayoutPositionParams {
353
+ iban: string;
354
+ /** 1 to 255 characters. */
355
+ title: string;
356
+ amount: Money;
357
+ }
358
+ /** Payout instruction attached to a payment. */
359
+ interface PayoutInstructionParams {
360
+ positions: readonly PayoutPositionParams[];
361
+ /** Defaults to `net`. */
362
+ feeMode?: PayoutFeeMode | (string & {});
363
+ }
364
+
365
+ /** Server-to-server card payment. */
366
+ interface CardPaymentParams {
367
+ /** 3-D Secure device fingerprint. Required. */
368
+ deviceInfo: DeviceInfoParams;
369
+ email?: string;
370
+ channelId?: number;
371
+ cardHolderFirstName?: string;
372
+ cardHolderLastName?: string;
373
+ /** Base64 payload produced by `CardEncryptor`. */
374
+ encryptedCardData?: string;
375
+ threeDsConfirmed?: boolean;
376
+ /** Answer to a pending dynamic currency conversion offer. */
377
+ dccDecision?: DccDecision | (string & {});
378
+ }
379
+ /** Google Pay payment. */
380
+ interface GooglePayParams {
381
+ token: string;
382
+ deviceInfo: DeviceInfoParams;
383
+ email?: string;
384
+ channelId?: number;
385
+ }
386
+ /** Apple Pay. Omit `token` to initialise a session. */
387
+ interface ApplePayParams {
388
+ deviceInfo: DeviceInfoParams;
389
+ token?: string;
390
+ channelId?: number;
391
+ }
392
+
393
+ /** Charges, authorizes, captures and cancels card payments, including Google Pay and Apple Pay wallets. */
394
+ declare class CardService {
395
+ private readonly api;
396
+ constructor(api: ApiRequestor);
397
+ /** Current RSA public key. dpay rotates it, so fetch it before every attempt. */
398
+ publicKey(options?: RequestOptions): Promise<string>;
399
+ /** Charges a card immediately. */
400
+ payOtp(transactionId: string, params: CardPaymentParams, options?: RequestOptions): Promise<CardPaymentResult>;
401
+ /** Authorizes a card without capturing the funds. */
402
+ preAuth(transactionId: string, params: CardPaymentParams, options?: RequestOptions): Promise<CardPaymentResult>;
403
+ /** Captures a pre-authorization. Omit `amount` to capture in full. */
404
+ capture(transactionId: string, params?: {
405
+ amount?: Money;
406
+ }, options?: RequestOptions): Promise<CardPaymentResult>;
407
+ /** Cancels a pre-authorization. Omit `amount` to cancel in full. */
408
+ cancel(transactionId: string, params?: {
409
+ amount?: Money;
410
+ }, options?: RequestOptions): Promise<CardPaymentResult>;
411
+ /** Pays with a Google Pay token. */
412
+ googlePay(transactionId: string, params: GooglePayParams, options?: RequestOptions): Promise<CardPaymentResult>;
413
+ /** Initialises an Apple Pay session, or pays when `token` is given. */
414
+ applePay(transactionId: string, params: ApplePayParams, options?: RequestOptions): Promise<CardPaymentResult>;
415
+ }
416
+
417
+ /** Kind of notification dpay sent. */
418
+ declare const IpnType: {
419
+ readonly TRANSFER: "transfer";
420
+ readonly CAPTURE: "capture";
421
+ readonly DCB: "dcb";
422
+ };
423
+ type IpnType = (typeof IpnType)[keyof typeof IpnType];
424
+ /**
425
+ * Body dpay requires in the IPN response. It must be exactly this string;
426
+ * the HTTP status is ignored.
427
+ */
428
+ declare const IPN_ACK = "OK";
429
+ /** A verified IPN notification. */
430
+ interface IpnEvent {
431
+ readonly id: string;
432
+ /** Raw decimal string. The payload carries no currency, so compare it to your own order. */
433
+ readonly amount: string;
434
+ readonly email: string | null;
435
+ readonly type: IpnType | (string & {});
436
+ readonly attempt: number;
437
+ readonly version: number;
438
+ /** Whatever you passed as `custom` at registration time. */
439
+ readonly custom: string | null;
440
+ readonly capturePaymentId: string | null;
441
+ readonly signature: string;
442
+ readonly isTransfer: boolean;
443
+ readonly isCapture: boolean;
444
+ readonly isDcb: boolean;
445
+ readonly raw: Record<string, unknown>;
446
+ }
447
+
448
+ /** Verifies IPN notifications dpay posts to your server after a payment event. */
449
+ declare class IpnService {
450
+ private readonly config;
451
+ constructor(config: Config);
452
+ /** Verifies an IPN body. Uses the client's `secretHash` unless one is given. */
453
+ constructEvent(rawBody: string | Uint8Array, secretHash?: string): IpnEvent;
454
+ /** Reads and verifies an IPN straight from an incoming HTTP request. */
455
+ constructEventFromRequest(request: unknown, secretHash?: string): Promise<IpnEvent>;
456
+ }
457
+
458
+ /** Result of a successful payment registration. */
459
+ interface RegisteredPayment {
460
+ readonly transactionId: string;
461
+ /** Raw `msg` field. Carries either a URL or a status sentence. */
462
+ readonly message: string;
463
+ /** KSeF invoice identifier, when e-invoicing was requested. */
464
+ readonly ipksef: string | null;
465
+ /** Where to send the payer, or null when there is nothing to redirect to. */
466
+ readonly redirectUrl: string | null;
467
+ /** True when the payment was already settled inline. */
468
+ readonly isPaid: boolean;
469
+ /** True when dpay is processing the payment without a payer redirect. */
470
+ readonly isInternalProcessing: boolean;
471
+ /** Alias returned when a card mandate was registered. */
472
+ readonly cardRecurringAlias: string | null;
473
+ readonly raw: Record<string, unknown>;
474
+ }
475
+ /** A single refund attached to a transaction. */
476
+ interface TransactionRefund {
477
+ readonly paymentId: string;
478
+ readonly value: Money;
479
+ readonly status: TransactionStatus | (string & {});
480
+ readonly creationDate: string | null;
481
+ readonly paymentDate: string | null;
482
+ readonly raw: Record<string, unknown>;
483
+ }
484
+ /** Full transaction state from `pbl/details`. */
485
+ interface Transaction {
486
+ readonly id: string;
487
+ readonly value: Money;
488
+ readonly status: TransactionStatus | (string & {});
489
+ readonly paymentMethod: string | null;
490
+ readonly creationDate: string | null;
491
+ readonly paymentDate: string | null;
492
+ readonly isPaid: boolean;
493
+ readonly isSettled: boolean;
494
+ readonly isRefunded: boolean;
495
+ readonly refundedAmount: Money;
496
+ readonly availableRefundAmount: Money;
497
+ readonly isFullyRefunded: boolean;
498
+ readonly isDirect: boolean;
499
+ readonly gatewayId: string | null;
500
+ readonly payer: Record<string, unknown>;
501
+ readonly refunds: readonly TransactionRefund[];
502
+ readonly raw: Record<string, unknown>;
503
+ }
504
+
505
+ declare const MODELS: readonly ["A", "M", "O"];
506
+ /** Registers a one-off BLIK alias alongside a payment. */
507
+ interface BlikAliasRegistrationParams {
508
+ /** 1 to 50 characters, shown in the payer's banking app. */
509
+ label: string;
510
+ /** Defaults to `UID`. */
511
+ type?: BlikAliasType | (string & {});
512
+ }
513
+ /** Registers a recurring BLIK mandate alongside a payment. */
514
+ interface BlikRecurringRegistrationParams {
515
+ /** 1 to 50 characters. */
516
+ label: string;
517
+ /** `A` automatic, `M` merchant initiated, `O` one-off. */
518
+ model: (typeof MODELS)[number];
519
+ /** Count plus unit, for example `12M`. Units: D, W, M, Q, Y. */
520
+ frequency: string;
521
+ value?: Money;
522
+ /** Single charge limit in minor units. */
523
+ limitAmt?: number;
524
+ /** Total limit in minor units. */
525
+ totLimitAmt?: number;
526
+ limitAmtFixed?: boolean;
527
+ /** YYYY-MM-DD. */
528
+ expirationDate?: string;
529
+ /** YYYY-MM-DD. */
530
+ initDate?: string;
531
+ }
532
+
533
+ /** Registers a card mandate alongside a payment. */
534
+ interface CardRecurringRegistrationParams {
535
+ /** 1 to 50 characters. */
536
+ label: string;
537
+ frequency?: CardRecurringFrequency | (string & {});
538
+ limitAmt?: Money;
539
+ totLimitAmt?: Money;
540
+ limitAmtFixed?: boolean;
541
+ /** YYYY-MM-DD. */
542
+ expirationDate?: string;
543
+ /** YYYY-MM-DD. */
544
+ initDate?: string;
545
+ }
546
+
547
+ /** Everything `payments.register` accepts. Only the first three fields are required. */
548
+ interface RegisterPaymentParams {
549
+ /** Amount to charge. */
550
+ amount: Money;
551
+ /** Payment flow. */
552
+ transactionType: TransactionType | (string & {});
553
+ /** Success, failure and IPN URLs. */
554
+ urls: ReturnUrls;
555
+ description?: string;
556
+ /** Opaque merchant reference, echoed back in the IPN. */
557
+ custom?: string;
558
+ payer?: PayerParams;
559
+ acceptTos?: boolean;
560
+ /** Payment channel identifier from panel.dpay.pl. */
561
+ channel?: string;
562
+ creditCard?: boolean;
563
+ paysafecard?: boolean;
564
+ blik?: boolean;
565
+ installment?: boolean;
566
+ paypal?: boolean;
567
+ /** Hides the bank list on the payment page. */
568
+ noBanks?: boolean;
569
+ /** Requires `currencyCode` to be set as well. */
570
+ phoneNumber?: string;
571
+ currencyCode?: string;
572
+ /** Uppercase letters and digits, up to 64 characters. */
573
+ partnerPlatform?: string;
574
+ /** Required together with `blikCode` or `blikAlias`. */
575
+ userAgent?: string;
576
+ /** Required together with `blikCode` or `blikAlias`. */
577
+ userIp?: string;
578
+ /** Exactly six digits. Cannot be combined with `blikAlias`. */
579
+ blikCode?: string;
580
+ /** Cannot be combined with `blikCode` or any alias registration. */
581
+ blikAlias?: string;
582
+ registerBlikAlias?: BlikAliasRegistrationParams;
583
+ registerBlikRecurringAlias?: BlikRecurringRegistrationParams;
584
+ aliasIpnUrl?: string;
585
+ noDelay?: boolean;
586
+ /** Cannot be combined with `cardRecurringAlias`. */
587
+ registerCardRecurring?: CardRecurringRegistrationParams;
588
+ /** Cannot be combined with `registerCardRecurring`. */
589
+ cardRecurringAlias?: string;
590
+ authorizeOnly?: boolean;
591
+ cardRecurringOperation?: CardRecurringOperation | (string & {});
592
+ payout?: PayoutInstructionParams;
593
+ billingAddress?: Record<string, unknown>;
594
+ shippingAddress?: Record<string, unknown>;
595
+ deviceInfo?: DeviceInfoParams;
596
+ products?: ReadonlyArray<Record<string, unknown>>;
597
+ /** Only valid when `transactionType` is `transfers`. */
598
+ efaktura?: boolean;
599
+ invoice?: InvoiceParams;
600
+ }
601
+
602
+ /** Registers dpay payments and reads their current transaction status. */
603
+ declare class PaymentService {
604
+ private readonly api;
605
+ constructor(api: ApiRequestor);
606
+ /**
607
+ * Registers a payment and returns the redirect target.
608
+ * Throws `PaymentRejectedError` when dpay rejects it with HTTP 200.
609
+ */
610
+ register(params: RegisterPaymentParams, options?: RequestOptions): Promise<RegisteredPayment>;
611
+ /** Reads the current state of a transaction, including its refunds. */
612
+ details(transactionId: string, options?: RequestOptions): Promise<Transaction>;
613
+ }
614
+
615
+ /** Beneficiary of a payout. */
616
+ interface PayoutReceiver {
617
+ readonly nrb: string | null;
618
+ readonly title: string | null;
619
+ readonly amount: Money | null;
620
+ readonly service: string | null;
621
+ readonly receiverName: string | null;
622
+ readonly receiverAddress: string | null;
623
+ readonly raw: Record<string, unknown>;
624
+ }
625
+ /** State of a single payout. */
626
+ interface PayoutDetails {
627
+ readonly id: number;
628
+ /** 0 waiting, 1 processed, -1 failed. */
629
+ readonly state: number;
630
+ readonly net: Money;
631
+ readonly fee: Money;
632
+ readonly gross: Money;
633
+ readonly creationDate: string | null;
634
+ readonly isDirectSettlement: boolean;
635
+ readonly nrb: string | null;
636
+ readonly isDeclined: boolean;
637
+ readonly declineReason: string | null;
638
+ readonly declineStatus: string | null;
639
+ readonly receiver: PayoutReceiver | null;
640
+ readonly isWaiting: boolean;
641
+ readonly isProcessed: boolean;
642
+ readonly isFailed: boolean;
643
+ readonly raw: Record<string, unknown>;
644
+ }
645
+
646
+ interface PayoutDetailsParams {
647
+ withdrawId: number;
648
+ timestamp?: number;
649
+ }
650
+
651
+ /** Reads the state of payouts (withdrawals) from a dpay merchant balance. */
652
+ declare class PayoutService {
653
+ private readonly api;
654
+ constructor(api: ApiRequestor);
655
+ /** Reads the state of a single payout. */
656
+ details(params: PayoutDetailsParams, options?: RequestOptions): Promise<PayoutDetails>;
657
+ }
658
+
659
+ /** Outcome of a refund request. */
660
+ interface Refund {
661
+ readonly isAccepted: boolean;
662
+ readonly message: string | null;
663
+ readonly raw: Record<string, unknown>;
664
+ }
665
+ /** Outcome of a refund availability check. */
666
+ interface RefundAvailability {
667
+ readonly isAvailable: boolean;
668
+ readonly message: string | null;
669
+ /** HTTP status the API answered with. The API signals refusal through the status. */
670
+ readonly httpStatus: number;
671
+ readonly raw: Record<string, unknown>;
672
+ }
673
+
674
+ interface RefundParams {
675
+ transactionId: string;
676
+ amount?: Money;
677
+ reason?: string;
678
+ }
679
+
680
+ /** Refunds transactions and checks whether a refund would be accepted before performing it. */
681
+ declare class RefundService {
682
+ private readonly api;
683
+ constructor(api: ApiRequestor);
684
+ /** Refunds a transaction in full, or partially when `amount` is given. */
685
+ create(params: RefundParams, options?: RequestOptions): Promise<Refund>;
686
+ /**
687
+ * Checks whether a refund would be accepted, without performing it.
688
+ * Refusal arrives as a 4xx status carrying an outcome body, not as an error.
689
+ */
690
+ checkAvailability(params: RefundParams, options?: RequestOptions): Promise<RefundAvailability>;
691
+ }
692
+
693
+ /** Entry point of the SDK. One instance per payment point. */
694
+ declare class DPayClient {
695
+ /** Version of this SDK. */
696
+ readonly VERSION = "0.1.0";
697
+ /** Register payments and read transaction state. */
698
+ readonly payments: PaymentService;
699
+ /** Refund transactions and check refund availability. */
700
+ readonly refunds: RefundService;
701
+ /** List banks available on the payment page. */
702
+ readonly banks: BankService;
703
+ /** Register, unregister and inspect BLIK aliases. */
704
+ readonly blik: BlikService;
705
+ /** Server-to-server card payments, wallets and pre-authorizations. */
706
+ readonly cards: CardService;
707
+ /** Read the state of payouts. */
708
+ readonly payouts: PayoutService;
709
+ /** Verify incoming IPN notifications. */
710
+ readonly ipn: IpnService;
711
+ /**
712
+ * Validates `options` eagerly - before any network call - and mounts every service on
713
+ * top of a shared transport. Defaults to `FetchHttpClient` when `options.httpClient` is
714
+ * not given.
715
+ */
716
+ constructor(options: DPayClientOptions);
717
+ }
718
+
719
+ declare const SDK_VERSION = "0.1.0";
720
+
721
+ /** Currency codes used by dpay. Any ISO-4217 style code is accepted. */
722
+ declare const Currency: {
723
+ readonly PLN: "PLN";
724
+ readonly EUR: "EUR";
725
+ readonly CZK: "CZK";
726
+ };
727
+ type Currency = (typeof Currency)[keyof typeof Currency] | (string & {});
728
+ declare function isValidCurrency(code: string): boolean;
729
+ declare function assertCurrency(code: string): void;
730
+
731
+ /** Default transport, built on the global `fetch`. */
732
+ declare class FetchHttpClient implements HttpClient {
733
+ private readonly fetchImpl;
734
+ constructor(fetchImpl?: typeof fetch);
735
+ request(request: ApiRequest): Promise<ApiResponse>;
736
+ }
737
+
738
+ type DPayErrorType = 'value_error' | 'transport_error' | 'signature_verification_error' | 'card_encryption_error' | 'api_error' | 'authentication_error' | 'invalid_request_error' | 'access_denied_error' | 'not_found_error' | 'rate_limit_error' | 'card_payment_error' | 'payment_rejected_error' | 'api_server_error';
739
+ /** Base class for every error thrown by this SDK. */
740
+ declare class DPayError extends Error {
741
+ /** Stable discriminator, usable in `switch` when `instanceof` is unreliable. */
742
+ readonly type: DPayErrorType;
743
+ constructor(message: string, options?: {
744
+ cause?: unknown;
745
+ });
746
+ }
747
+ /** Invalid argument passed to the SDK. Thrown before any network call. */
748
+ declare class DPayValueError extends DPayError {
749
+ readonly type = "value_error";
750
+ }
751
+ /** Network failure, timeout or abort. The payment status is unknown. */
752
+ declare class TransportError extends DPayError {
753
+ readonly type = "transport_error";
754
+ }
755
+ /** The IPN payload is malformed or its signature does not match. */
756
+ declare class SignatureVerificationError extends DPayError {
757
+ readonly type = "signature_verification_error";
758
+ }
759
+ /** Card data could not be encrypted with the public key from the API. */
760
+ declare class CardEncryptionError extends DPayError {
761
+ readonly type = "card_encryption_error";
762
+ }
763
+ /** The API answered, but rejected the request. */
764
+ declare class ApiError extends DPayError {
765
+ readonly type: DPayErrorType;
766
+ /** HTTP status of the response, or 200 for rejections carried in a success body. */
767
+ readonly httpStatus: number;
768
+ /** Business error code from the API, when present. */
769
+ readonly errorCode: string | null;
770
+ /** Per-field validation messages, normalized across the 400 and 422 formats. */
771
+ readonly fieldErrors: Record<string, string[]>;
772
+ /** Unparsed response body. */
773
+ readonly rawBody: string;
774
+ constructor(message: string, httpStatus: number, errorCode?: string | null, fieldErrors?: Record<string, string[]>, rawBody?: string);
775
+ }
776
+ /** HTTP 401 - usually a wrong checksum. */
777
+ declare class AuthenticationError extends ApiError {
778
+ readonly type = "authentication_error";
779
+ }
780
+ /** HTTP 400 or 422 - see `fieldErrors`. */
781
+ declare class InvalidRequestError extends ApiError {
782
+ readonly type = "invalid_request_error";
783
+ }
784
+ /** HTTP 403. */
785
+ declare class AccessDeniedError extends ApiError {
786
+ readonly type = "access_denied_error";
787
+ }
788
+ /** HTTP 404. */
789
+ declare class NotFoundError extends ApiError {
790
+ readonly type = "not_found_error";
791
+ }
792
+ /** HTTP 5xx. */
793
+ declare class ApiServerError extends ApiError {
794
+ readonly type = "api_server_error";
795
+ }
796
+ /** HTTP 429. */
797
+ declare class RateLimitError extends ApiError {
798
+ readonly type = "rate_limit_error";
799
+ /** Seconds from the `Retry-After` header. */
800
+ readonly retryAfter: number | null;
801
+ /** Value of `X-RateLimit-Limit`. */
802
+ readonly limit: number | null;
803
+ /** Value of `X-RateLimit-Remaining`. */
804
+ readonly remaining: number | null;
805
+ constructor(message: string, httpStatus: number, retryAfter?: number | null, limit?: number | null, remaining?: number | null, rawBody?: string);
806
+ }
807
+ /** Payment registration rejected with HTTP 200 and `error: true`. */
808
+ declare class PaymentRejectedError extends ApiError {
809
+ readonly type = "payment_rejected_error";
810
+ /** Transaction identifier returned alongside the rejection, when present. */
811
+ readonly transactionId: string | null;
812
+ constructor(message: string, httpStatus: number, errorCode?: string | null, fieldErrors?: Record<string, string[]>, rawBody?: string, transactionId?: string | null);
813
+ static fromApi(data: Record<string, unknown>): PaymentRejectedError;
814
+ }
815
+ /** Card payment rejected with HTTP 200 and `success != true`. */
816
+ declare class CardPaymentError extends ApiError {
817
+ readonly type = "card_payment_error";
818
+ static fromApi(data: Record<string, unknown>): CardPaymentError;
819
+ }
820
+
821
+ /**
822
+ * Raw card credentials, held only long enough to encrypt them.
823
+ *
824
+ * Redacts itself when logged or serialized, so it never reaches a log sink in clear text.
825
+ * `pan`, `cvv`, and `expiry` are exposed through getters backed by private fields rather than
826
+ * plain enumerable own data properties, so APIs that bypass custom inspection - such as
827
+ * `console.dir(card)` or `Object.keys(card)` - have nothing to dump either.
828
+ */
829
+ declare class CardData {
830
+ #private;
831
+ constructor(params: {
832
+ pan: string;
833
+ cvv: string;
834
+ expiry: string;
835
+ });
836
+ /** Card number, normalized to digits only (spaces stripped). */
837
+ get pan(): string;
838
+ /** Card verification value, 3-4 digits. */
839
+ get cvv(): string;
840
+ /** Expiry in `MM/YY` format. */
841
+ get expiry(): string;
842
+ private redacted;
843
+ /** Redacted representation - `pan` masked to its last 4 digits, `cvv` fully masked. */
844
+ toJSON(): {
845
+ pan: string;
846
+ cvv: string;
847
+ expiry: string;
848
+ };
849
+ /** Redacted representation - `pan` masked to its last 4 digits, `cvv` fully masked. */
850
+ toString(): string;
851
+ /** Node `util.inspect` hook - delegates to the same redacted `toString()`. */
852
+ [inspect.custom](): string;
853
+ }
854
+
855
+ /** Encrypts card credentials with the rotating RSA key from `cards.publicKey()`. */
856
+ declare class CardEncryptor {
857
+ /**
858
+ * Returns the Base64 payload to put in `encryptedCardData`.
859
+ * Fetch the public key immediately before every attempt - dpay rotates it.
860
+ */
861
+ encrypt(card: CardData, transactionId: string, publicKeyPem: string): string;
862
+ }
863
+
864
+ /**
865
+ * Parses and verifies an IPN body. Always pass the exact bytes dpay sent -
866
+ * a re-serialized JSON object will not verify.
867
+ */
868
+ declare function constructIpnEvent(rawBody: string | Uint8Array, secretHash: string): IpnEvent;
869
+
870
+ /**
871
+ * Reads the exact bytes of an incoming request body.
872
+ * Accepts a WHATWG `Request`, a Node `IncomingMessage`, a string, a Buffer, or a Uint8Array.
873
+ */
874
+ declare function readRawBody(request: unknown): Promise<string>;
875
+
876
+ export { AccessDeniedError, ApiError, ApiRequest, ApiResponse, ApiServerError, type ApplePayParams, AuthenticationError, type Bank, type BlikAlias, type BlikAliasParams, type BlikAliasRegistrationParams, BlikAliasType, type BlikApp, type BlikRecurringRegistrationInfo, type BlikRecurringRegistrationParams, type BlikRecurringStatus, type BlikUnregisterAliasParams, CardData, CardEncryptionError, CardEncryptor, CardPaymentError, type CardPaymentParams, type CardPaymentResult, CardRecurringFrequency, CardRecurringOperation, type CardRecurringRegistrationParams, Currency, DEFAULT_TIMEOUT, DPayClient, type DPayClientOptions, DPayError, type DPayErrorType, DPayValueError, DccDecision, type DccMarkup, type DccOffer, type DeviceInfoParams, FetchHttpClient, type GooglePayParams, HttpClient, IPN_ACK, InvalidRequestError, type InvoiceParams, type IpnEvent, IpnType, Money, NotFoundError, type PayerParams, PaymentRejectedError, type PayoutDetails, type PayoutDetailsParams, PayoutFeeMode, type PayoutInstructionParams, type PayoutPositionParams, type PayoutReceiver, RateLimitError, RedirectType, type Refund, type RefundAvailability, type RefundParams, type RegisterPaymentParams, type RegisteredPayment, type RequestHookContext, type RequestOptions, type ResponseHookContext, type ReturnUrls, SDK_VERSION, SignatureVerificationError, type Transaction, type TransactionRefund, TransactionStatus, TransactionType, TransportError, assertCurrency, constructIpnEvent, isValidCurrency, readRawBody };