@waffo/waffo-node 2.0.2

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,4639 @@
1
+ /**
2
+ * @fileoverview Logger Type Definitions
3
+ * @module types/logger
4
+ *
5
+ * Logger interface for SDK debugging. Compatible with `console` and most
6
+ * logging libraries (winston, pino, bunyan, etc.).
7
+ *
8
+ * When provided to the SDK, logs detailed information about:
9
+ * - HTTP requests/responses
10
+ * - Signature generation/verification
11
+ * - Errors and stack traces
12
+ *
13
+ * @see {@link WaffoConfig.logger} for configuring the logger
14
+ *
15
+ * @example
16
+ * // Use console for simple debugging
17
+ * const waffo = new Waffo({
18
+ * apiKey: 'key',
19
+ * privateKey: 'key',
20
+ * logger: console,
21
+ * });
22
+ *
23
+ * @example
24
+ * // Use a custom logger
25
+ * const waffo = new Waffo({
26
+ * apiKey: 'key',
27
+ * privateKey: 'key',
28
+ * logger: {
29
+ * debug: (msg, ...args) => myLogger.debug(msg, args),
30
+ * info: (msg, ...args) => myLogger.info(msg, args),
31
+ * warn: (msg, ...args) => myLogger.warn(msg, args),
32
+ * error: (msg, ...args) => myLogger.error(msg, args),
33
+ * },
34
+ * });
35
+ */
36
+ /**
37
+ * Logger interface for SDK debugging.
38
+ *
39
+ * Compatible with `console` and popular logging libraries.
40
+ *
41
+ * **Log Levels:**
42
+ * - `debug` - Detailed debugging (request/response details)
43
+ * - `info` - Informational messages (operation status)
44
+ * - `warn` - Warnings (signature issues, retries)
45
+ * - `error` - Errors (network failures, parsing errors)
46
+ *
47
+ * @interface Logger
48
+ *
49
+ * @example
50
+ * // Simply use console
51
+ * const config: WaffoConfig = {
52
+ * apiKey: 'key',
53
+ * privateKey: 'key',
54
+ * logger: console,
55
+ * };
56
+ */
57
+ interface Logger {
58
+ /** Log detailed debugging information */
59
+ debug: (message: string, ...args: unknown[]) => void;
60
+ /** Log general informational messages */
61
+ info: (message: string, ...args: unknown[]) => void;
62
+ /** Log warning messages */
63
+ warn: (message: string, ...args: unknown[]) => void;
64
+ /** Log error messages */
65
+ error: (message: string, ...args: unknown[]) => void;
66
+ }
67
+
68
+ /**
69
+ * @fileoverview SDK Configuration Type Definitions
70
+ * @module types/config
71
+ *
72
+ * Configuration types for the Waffo SDK:
73
+ * - Environment settings (SANDBOX/PRODUCTION)
74
+ * - SDK initialization configuration
75
+ * - HTTP request options
76
+ *
77
+ * @see {@link Waffo} for SDK initialization
78
+ * @see {@link HttpClient} for making API requests
79
+ *
80
+ * @example
81
+ * import { Environment, WaffoConfig } from 'waffo-sdk';
82
+ *
83
+ * const config: WaffoConfig = {
84
+ * apiKey: 'your-api-key',
85
+ * privateKey: 'your-private-key',
86
+ * environment: Environment.SANDBOX,
87
+ * };
88
+ */
89
+
90
+ /**
91
+ * SDK runtime environment.
92
+ *
93
+ * - **SANDBOX**: Development and testing (no real transactions)
94
+ * - **PRODUCTION**: Live transactions with real payments
95
+ *
96
+ * @enum {string}
97
+ * @readonly
98
+ *
99
+ * @example
100
+ * import { Environment } from 'waffo-sdk';
101
+ *
102
+ * // Use sandbox for testing
103
+ * const waffo = new Waffo({
104
+ * apiKey: 'test-key',
105
+ * privateKey: 'test-private-key',
106
+ * environment: Environment.SANDBOX,
107
+ * });
108
+ *
109
+ * // Use production for live payments
110
+ * const waffoProd = new Waffo({
111
+ * apiKey: process.env.WAFFO_API_KEY,
112
+ * privateKey: process.env.WAFFO_PRIVATE_KEY,
113
+ * environment: Environment.PRODUCTION,
114
+ * });
115
+ */
116
+ declare enum Environment {
117
+ /** Sandbox testing environment */
118
+ SANDBOX = "sandbox",
119
+ /** Production environment for live transactions */
120
+ PRODUCTION = "production"
121
+ }
122
+ /**
123
+ * Maps environments to their API base URLs.
124
+ *
125
+ * | Environment | Base URL |
126
+ * |-------------|----------|
127
+ * | SANDBOX | https://api-sandbox.waffo.com/api/v1 |
128
+ * | PRODUCTION | https://api.waffo.com/api/v1 |
129
+ *
130
+ * @constant
131
+ * @type {Record<Environment, string>}
132
+ */
133
+ declare const EnvironmentUrls: Record<Environment, string>;
134
+ /**
135
+ * Maps environments to Waffo's RSA public keys.
136
+ *
137
+ * Used to verify API response signatures. Keys are Base64 encoded X509/SPKI DER format.
138
+ * These are embedded in the SDK and updated when Waffo rotates their keys.
139
+ *
140
+ * @constant
141
+ * @type {Record<Environment, string>}
142
+ * @remarks To use a custom public key, provide it via the `waffoPublicKey` config option.
143
+ */
144
+ declare const EnvironmentPublicKeys: Record<Environment, string>;
145
+ /**
146
+ * Configuration for initializing the Waffo SDK.
147
+ *
148
+ * **Required:**
149
+ * - `apiKey` - Your API key from Waffo
150
+ * - `privateKey` - Your merchant private key for signing requests
151
+ *
152
+ * **Optional:**
153
+ * - `waffoPublicKey` - Override the built-in Waffo public key
154
+ * - `environment` - API environment (defaults to PRODUCTION)
155
+ * - `timeout` - Request timeout in milliseconds (defaults to 30000)
156
+ * - `logger` - Logger instance for debugging
157
+ *
158
+ * @interface WaffoConfig
159
+ *
160
+ * @example
161
+ * const config: WaffoConfig = {
162
+ * apiKey: process.env.WAFFO_API_KEY!,
163
+ * privateKey: process.env.WAFFO_PRIVATE_KEY!,
164
+ * environment: Environment.PRODUCTION,
165
+ * timeout: 60000,
166
+ * logger: console,
167
+ * };
168
+ *
169
+ * @see {@link Waffo} for SDK initialization
170
+ * @see {@link Environment} for available environments
171
+ */
172
+ interface WaffoConfig {
173
+ /** API key assigned by Waffo (required) */
174
+ apiKey: string;
175
+ /** Merchant private key, Base64 encoded PKCS8 DER format (required) */
176
+ privateKey: string;
177
+ /** Waffo's public key for response verification (defaults to built-in) */
178
+ waffoPublicKey?: string;
179
+ /** SDK runtime environment (defaults to PRODUCTION) */
180
+ environment?: Environment;
181
+ /** HTTP request timeout in milliseconds (defaults to 30000) */
182
+ timeout?: number;
183
+ /** Logger instance for debugging */
184
+ logger?: Logger;
185
+ }
186
+ /**
187
+ * Options for individual HTTP requests.
188
+ *
189
+ * Used when calling {@link HttpClient.post} directly.
190
+ *
191
+ * @interface RequestOptions
192
+ * @template B - Request body type (defaults to `Record<string, unknown>`)
193
+ *
194
+ * @example
195
+ * const options: RequestOptions<CreateOrderParams> = {
196
+ * body: { paymentRequestId: '123', ... },
197
+ * headers: { 'X-Custom-Header': 'value' },
198
+ * };
199
+ *
200
+ * @see {@link HttpClient.post} for making HTTP requests
201
+ */
202
+ interface RequestOptions<B extends object = Record<string, unknown>> {
203
+ /** Request body (will be JSON serialized and signed) */
204
+ body?: B;
205
+ /** Additional HTTP headers to include */
206
+ headers?: Record<string, string>;
207
+ }
208
+
209
+ /**
210
+ * @fileoverview Common Network Type Definitions
211
+ * @module types/network
212
+ *
213
+ * Common network-related types shared across HTTP client and webhook handling:
214
+ * - HTTP status codes
215
+ * - Signature header interface
216
+ */
217
+ /**
218
+ * Standard HTTP status codes used in API responses.
219
+ *
220
+ * @enum {number}
221
+ * @readonly
222
+ *
223
+ * @example
224
+ * if (result.statusCode === HttpStatusCode.OK) {
225
+ * console.log('Request successful');
226
+ * } else if (result.statusCode === HttpStatusCode.REQUEST_TIMEOUT) {
227
+ * console.log('Request timed out');
228
+ * }
229
+ */
230
+ declare enum HttpStatusCode {
231
+ OK = 200,
232
+ BAD_REQUEST = 400,
233
+ UNAUTHORIZED = 401,
234
+ PAYMENT_REQUIRED = 402,
235
+ FORBIDDEN = 403,
236
+ NOT_FOUND = 404,
237
+ METHOD_NOT_ALLOWED = 405,
238
+ REQUEST_TIMEOUT = 408,
239
+ INTERNAL_SERVER_ERROR = 500,
240
+ NOT_IMPLEMENTED = 501,
241
+ BAD_GATEWAY = 502,
242
+ SERVICE_UNAVAILABLE = 503,
243
+ GATEWAY_TIMEOUT = 504
244
+ }
245
+ /**
246
+ * Common header structure containing RSA-SHA256 signature.
247
+ *
248
+ * Used in API responses and webhook requests/responses.
249
+ *
250
+ * @interface SignatureHeader
251
+ */
252
+ interface SignatureHeader {
253
+ /** RSA-SHA256 signature (Base64 encoded) */
254
+ "X-SIGNATURE": string;
255
+ /** MIME type (typically "application/json") */
256
+ "Content-Type": string;
257
+ }
258
+
259
+ /**
260
+ * @fileoverview HTTP Client Type Definitions
261
+ * @module types/httpClient
262
+ *
263
+ * Types for the HTTP client:
264
+ * - SDK API response wrapper
265
+ * - Waffo API response format definitions
266
+ *
267
+ * @see {@link HttpClient} for making API requests
268
+ *
269
+ * @example
270
+ * import { ApiResponse, HttpStatusCode } from 'waffo-sdk';
271
+ *
272
+ * const result: ApiResponse<CreateOrderData> = await waffo.order.create(params);
273
+ * if (result.success && result.statusCode === HttpStatusCode.OK) {
274
+ * console.log('Order created:', result.data);
275
+ * }
276
+ */
277
+
278
+ /**
279
+ * Standard response format for all SDK API calls.
280
+ *
281
+ * @interface ApiResponse
282
+ * @template T - Type of response data on success
283
+ *
284
+ * @example
285
+ * const result: ApiResponse<CreateOrderData> = await waffo.order.create(params);
286
+ *
287
+ * if (result.success) {
288
+ * console.log('Order ID:', result.data.acquiringOrderId);
289
+ * } else {
290
+ * console.error('Error:', result.error);
291
+ * console.log('HTTP Status:', result.statusCode);
292
+ * }
293
+ */
294
+ interface ApiResponse<T = unknown> {
295
+ /** Whether the API request was successful */
296
+ success: boolean;
297
+ /** HTTP status code of the response */
298
+ statusCode: HttpStatusCode;
299
+ /** Business data (only on success) */
300
+ data?: T;
301
+ /** Error message (only on failure) */
302
+ error?: string;
303
+ }
304
+ /**
305
+ * HTTP response header from Waffo API.
306
+ * @type WaffoResponseHeader
307
+ */
308
+ type WaffoResponseHeader = SignatureHeader;
309
+ /**
310
+ * Standard response body from all Waffo API endpoints.
311
+ *
312
+ * - code "0" = success
313
+ * - other codes (A0xxx, B0xxx, C0xxx, S0xxx) = errors
314
+ *
315
+ * @interface WaffoResponseBody
316
+ * @template T - Type of business data in `data` field
317
+ */
318
+ interface WaffoResponseBody<T = unknown> {
319
+ /** Response code: "0" for success, error codes otherwise */
320
+ code: string;
321
+ /** Human-readable result message */
322
+ msg: string;
323
+ /** Business data payload (on success) */
324
+ data?: T;
325
+ }
326
+ /**
327
+ * Complete response structure from Waffo API.
328
+ *
329
+ * @interface WaffoApiResponse
330
+ * @template T - Type of business data
331
+ */
332
+ interface WaffoApiResponse<T = unknown> {
333
+ /** Response headers with signature */
334
+ header: WaffoResponseHeader;
335
+ /** Response body with code, message, and data */
336
+ body: WaffoResponseBody<T>;
337
+ }
338
+
339
+ /**
340
+ * @fileoverview Payment Related Enumeration Definitions
341
+ * @module types/payment
342
+ *
343
+ * Payment-related enumerations shared across Order, Subscription, and Config resources:
344
+ * - **{@link ProductName}** - Payment product types for acquiring API
345
+ * - **{@link SubscriptionProductName}** - Product types for subscription API
346
+ *
347
+ * @see {@link PaymentInfo} for payment configuration
348
+ * @see {@link CreateOrderParams} for order creation
349
+ *
350
+ * @example
351
+ * import { ProductName } from 'waffo-sdk';
352
+ *
353
+ * const paymentInfo = {
354
+ * productName: ProductName.ONE_TIME_PAYMENT,
355
+ * payMethodName: 'DANA',
356
+ * };
357
+ */
358
+ /**
359
+ * Payment product type for acquiring API.
360
+ *
361
+ * @enum {string}
362
+ * @readonly
363
+ *
364
+ * @example
365
+ * paymentInfo: {
366
+ * productName: ProductName.ONE_TIME_PAYMENT,
367
+ * payMethodName: 'DANA',
368
+ * }
369
+ */
370
+ declare enum ProductName {
371
+ /** Standard payment with redirect flow */
372
+ ONE_TIME_PAYMENT = "ONE_TIME_PAYMENT",
373
+ /** Payment within mini program environment */
374
+ MINI_PROGRAM_PAYMENT = "MINI_PROGRAM_PAYMENT",
375
+ /** Card payment (requires PCI-DSS compliance) */
376
+ DIRECT_PAYMENT = "DIRECT_PAYMENT"
377
+ }
378
+ /**
379
+ * Payment product type for subscription API.
380
+ *
381
+ * @enum {string}
382
+ * @readonly
383
+ *
384
+ * @example
385
+ * paymentInfo: {
386
+ * productName: SubscriptionProductName.SUBSCRIPTION,
387
+ * payMethodName: 'ALIPAY_HK',
388
+ * }
389
+ */
390
+ declare enum SubscriptionProductName {
391
+ /** Web-based subscription signing */
392
+ SUBSCRIPTION = "SUBSCRIPTION",
393
+ /** Subscription within mini program */
394
+ MINI_PROGRAM_SUBSCRIPTION = "MINI_PROGRAM_SUBSCRIPTION"
395
+ }
396
+
397
+ /**
398
+ * @fileoverview Common/Shared Type Definitions
399
+ * @module types/common
400
+ *
401
+ * Shared enums and types used across multiple resource modules.
402
+ * This file helps avoid circular dependencies between type modules.
403
+ */
404
+ /**
405
+ * Risk User Type Enum
406
+ *
407
+ * @description
408
+ * User type for risk assessment data.
409
+ *
410
+ * @enum {string}
411
+ * @readonly
412
+ */
413
+ declare enum RiskUserType {
414
+ INDIVIDUAL = "Individual",
415
+ AGENT = "Agent",
416
+ INSTITUTION = "Institution",
417
+ INTERNAL = "Internal"
418
+ }
419
+ /**
420
+ * Refund User Type Enum
421
+ *
422
+ * @description
423
+ * User type for refund processing.
424
+ *
425
+ * @enum {string}
426
+ * @readonly
427
+ */
428
+ declare enum RefundUserType {
429
+ INDIVIDUAL = "INDIVIDUAL",
430
+ BUSINESS = "BUSINESS"
431
+ }
432
+
433
+ /**
434
+ * @fileoverview Order Resource Type Definitions
435
+ * @module types/order
436
+ *
437
+ * Type definitions for the Order resource (based on Waffo API JSON Schema).
438
+ *
439
+ * **Categories:**
440
+ * - **Enums:** Order status, action types, payment modes
441
+ * - **Request Interfaces:** Parameters for create, inquiry, cancel, refund, capture
442
+ * - **Response Interfaces:** API response data structures
443
+ * - **Webhook Interfaces:** Payment notification structures
444
+ *
445
+ * @see {@link OrderResource} for API methods
446
+ * @see {@link CreateOrderParams} for order creation
447
+ *
448
+ * @example
449
+ * import {
450
+ * CreateOrderParams,
451
+ * OrderStatus,
452
+ * ProductName,
453
+ * UserTerminalType,
454
+ * } from 'waffo-sdk';
455
+ *
456
+ * const params: CreateOrderParams = {
457
+ * paymentRequestId: 'req-123',
458
+ * merchantOrderId: 'order-456',
459
+ * orderCurrency: 'USD',
460
+ * orderAmount: '10.00',
461
+ * // ...
462
+ * };
463
+ */
464
+
465
+ /**
466
+ * User Terminal Type Enum
467
+ *
468
+ * @description
469
+ * Identifies the terminal environment where the user initiates payment.
470
+ *
471
+ * @enum {string}
472
+ * @readonly
473
+ */
474
+ declare enum UserTerminalType {
475
+ WEB = "WEB",
476
+ APP = "APP",
477
+ IN_WALLET_APP = "IN_WALLET_APP",
478
+ IN_MINI_PROGRAM = "IN_MINI_PROGRAM"
479
+ }
480
+ /**
481
+ * Order Status Enum
482
+ *
483
+ * @description
484
+ * Identifies the current status of an order in the payment process.
485
+ *
486
+ * @enum {string}
487
+ * @readonly
488
+ */
489
+ declare enum OrderStatus {
490
+ PAY_IN_PROGRESS = "PAY_IN_PROGRESS",
491
+ AUTHORIZATION_REQUIRED = "AUTHORIZATION_REQUIRED",
492
+ AUTHED_WAITING_CAPTURE = "AUTHED_WAITING_CAPTURE",
493
+ PAY_SUCCESS = "PAY_SUCCESS",
494
+ ORDER_CLOSE = "ORDER_CLOSE",
495
+ CAPTURE_IN_PROGRESS = "CAPTURE_IN_PROGRESS"
496
+ }
497
+ /**
498
+ * Order Action Type Enum
499
+ *
500
+ * @description
501
+ * Indicates the redirect method for user to complete payment authorization.
502
+ *
503
+ * @enum {string}
504
+ * @readonly
505
+ */
506
+ declare enum OrderActionType {
507
+ WEB = "WEB",
508
+ DEEPLINK = "DEEPLINK"
509
+ }
510
+ /**
511
+ * Pay Method User Account Type Enum
512
+ *
513
+ * @description
514
+ * User account type at the designated pay method.
515
+ *
516
+ * @enum {string}
517
+ * @readonly
518
+ */
519
+ declare enum PayMethodUserAccountType {
520
+ EMAIL = "EMAIL",
521
+ PHONE_NO = "PHONE_NO",
522
+ ACCOUNT_ID = "ACCOUNT_ID"
523
+ }
524
+ /**
525
+ * Capture Mode Enum
526
+ *
527
+ * @description
528
+ * Capture mode for order payment.
529
+ *
530
+ * @enum {string}
531
+ * @readonly
532
+ */
533
+ declare enum CaptureMode {
534
+ MANUAL_CAPTURE = "manualCapture"
535
+ }
536
+ /**
537
+ * Merchant Initiated Mode Enum
538
+ *
539
+ * @description
540
+ * MIT mode for merchant initiated transactions.
541
+ *
542
+ * @enum {string}
543
+ * @readonly
544
+ */
545
+ declare enum MerchantInitiatedMode {
546
+ SCHEDULED = "scheduled",
547
+ UNSCHEDULED = "unscheduled"
548
+ }
549
+ /**
550
+ * 3DS Decision Enum
551
+ *
552
+ * @description
553
+ * Merchant 3DS decision for card payments.
554
+ *
555
+ * @enum {string}
556
+ * @readonly
557
+ */
558
+ declare enum ThreeDsDecision {
559
+ FORCE = "3DS_FORCE",
560
+ ATTEMPT = "3DS_ATTEMPT",
561
+ NO_3DS = "NO_3DS"
562
+ }
563
+ /**
564
+ * Merchant Information Interface (Request Parameters)
565
+ *
566
+ * @description
567
+ * Used to identify the merchant initiating the request.
568
+ *
569
+ * @interface MerchantInfo
570
+ */
571
+ interface MerchantInfo {
572
+ merchantId: string;
573
+ subMerchantId?: string;
574
+ }
575
+ /**
576
+ * User Information Interface (Request Parameters)
577
+ *
578
+ * @description
579
+ * Basic information of the paying user, used for risk control and user identification.
580
+ *
581
+ * @interface UserInfo
582
+ */
583
+ interface UserInfo {
584
+ userId: string;
585
+ userEmail: string;
586
+ userPhone?: string;
587
+ userCountryCode?: string;
588
+ userTerminal: UserTerminalType | string;
589
+ userFirstName?: string;
590
+ userLastName?: string;
591
+ userCreatedAt?: string;
592
+ userBrowserIp?: string;
593
+ userAgent?: string;
594
+ }
595
+ /**
596
+ * Goods Information Interface (Request Parameters)
597
+ *
598
+ * @description
599
+ * Product or service information associated with the order.
600
+ *
601
+ * @interface GoodsInfo
602
+ */
603
+ interface GoodsInfo {
604
+ goodsId?: string;
605
+ goodsName: string;
606
+ goodsCategory?: string;
607
+ goodsUrl?: string;
608
+ appName?: string;
609
+ skuName?: string;
610
+ goodsUniquePrice?: string;
611
+ goodsQuantity?: number | string;
612
+ }
613
+ /**
614
+ * Address Information Interface (Request Parameters)
615
+ *
616
+ * @description
617
+ * Shipping address information for the order, used for risk control and logistics.
618
+ *
619
+ * @interface AddressInfo
620
+ */
621
+ interface AddressInfo {
622
+ address?: string;
623
+ city?: string;
624
+ region?: string;
625
+ postcode?: string;
626
+ addressCountryCode?: string;
627
+ }
628
+ /**
629
+ * Payment Method Properties Interface (Request Parameters)
630
+ *
631
+ * @description
632
+ * Additional properties required for specific payment methods.
633
+ *
634
+ * @interface PayMethodProperties
635
+ */
636
+ interface PayMethodProperties {
637
+ cpf?: string;
638
+ cardPrefix?: string;
639
+ cardPrefixPurpose?: string;
640
+ [key: string]: string | undefined;
641
+ }
642
+ /**
643
+ * Cashier Appearance Interface (Request Parameters)
644
+ *
645
+ * @description
646
+ * Cashier UI appearance variables.
647
+ *
648
+ * @interface CashierAppearance
649
+ */
650
+ interface CashierAppearance {
651
+ variables?: {
652
+ colorPrimary?: string;
653
+ colorBackground?: string;
654
+ colorText?: string;
655
+ [key: string]: string | undefined;
656
+ };
657
+ }
658
+ /**
659
+ * Card Information Interface (Request Parameters)
660
+ *
661
+ * @description
662
+ * Card information for direct card payment, only applicable for PCI-DSS certified merchants.
663
+ *
664
+ * @interface CardInfo
665
+ * @warning This interface involves sensitive card data, ensure PCI-DSS compliance
666
+ */
667
+ interface CardInfo {
668
+ cardNumber: string;
669
+ cardExpiryYear: string;
670
+ cardExpiryMonth: string;
671
+ cardCvv: string;
672
+ cardHolderName: string;
673
+ threeDsDecision?: ThreeDsDecision | string;
674
+ }
675
+ /**
676
+ * Payment Information Interface (Request Parameters)
677
+ *
678
+ * @description
679
+ * Specify payment product, method, and mode.
680
+ *
681
+ * @interface PaymentInfo
682
+ */
683
+ interface PaymentInfo {
684
+ productName: ProductName | string;
685
+ /**
686
+ * Payment type (max 256 characters)
687
+ * Example values: "EWALLET", "CREDITCARD", "BANKTRANSFER", "ONLINE_BANKING", "DIGITAL_BANKING", "OTC", "DEBITCARD"
688
+ * Note: This list may be updated. Please refer to the latest API documentation.
689
+ */
690
+ payMethodType?: string;
691
+ /**
692
+ * Specific payment method (max 24 characters)
693
+ * Example E-wallets: "OVO", "DANA", "GOPAY", "SHOPEEPAY", "GCASH", "ALIPAY_HK"
694
+ * Example Credit Cards: "CC_VISA", "CC_MASTERCARD"
695
+ * Example Bank Transfer: "VA_BCA", "VA_BNI"
696
+ * Note: This list may be updated. Please refer to the latest API documentation.
697
+ */
698
+ payMethodName?: string;
699
+ payMethodCountry?: string;
700
+ payMethodProperties?: PayMethodProperties | string;
701
+ payMethodUserAccountType?: PayMethodUserAccountType | string;
702
+ payMethodUserAccountNo?: string;
703
+ cashierLanguage?: string;
704
+ cashierAppearance?: CashierAppearance;
705
+ userPaymentAccessToken?: string;
706
+ captureMode?: CaptureMode | string;
707
+ merchantInitiatedMode?: MerchantInitiatedMode | string;
708
+ }
709
+ /**
710
+ * Risk Data Interface (Request Parameters)
711
+ *
712
+ * @description
713
+ * Auxiliary data for risk assessment.
714
+ *
715
+ * @interface RiskData
716
+ */
717
+ interface RiskData {
718
+ userType?: RiskUserType;
719
+ userCategory?: string;
720
+ userLegalName?: string;
721
+ userDisplayName?: string;
722
+ userRegistrationIp?: string;
723
+ userLastSeenIp?: string;
724
+ userIsNew?: string;
725
+ userIsFirstPurchase?: string;
726
+ }
727
+ /**
728
+ * User Bank Information Interface (Request Parameters)
729
+ *
730
+ * @description
731
+ * Bank account information for bank transfer and similar payment method refunds.
732
+ *
733
+ * @interface UserBankInfo
734
+ */
735
+ interface UserBankInfo {
736
+ bankAccountNo: string;
737
+ bankCode: string;
738
+ bankCity?: string;
739
+ bankBranch?: string;
740
+ [key: string]: string | undefined;
741
+ }
742
+ /**
743
+ * Refund User Information Interface (Request Parameters)
744
+ *
745
+ * @description
746
+ * User information required for refunds with specific payment methods.
747
+ *
748
+ * @interface RefundUserInfo
749
+ */
750
+ interface RefundUserInfo {
751
+ userType?: RefundUserType;
752
+ userFirstName?: string;
753
+ userLastName?: string;
754
+ userEmail?: string;
755
+ userBankInfo?: UserBankInfo | string;
756
+ userPhone?: string;
757
+ userIDType?: string;
758
+ userIDNumber?: string;
759
+ userIDIssueDate?: string;
760
+ userIDExpiryDate?: string;
761
+ }
762
+ /**
763
+ * Create Order Request Parameters Interface
764
+ *
765
+ * @description
766
+ * Request parameters for calling `waffo.order.create()`.
767
+ *
768
+ * @interface CreateOrderParams
769
+ */
770
+ interface CreateOrderParams {
771
+ paymentRequestId: string;
772
+ merchantOrderId: string;
773
+ orderCurrency: string;
774
+ orderAmount: string;
775
+ orderDescription: string;
776
+ userCurrency?: string;
777
+ merchantInfo: MerchantInfo;
778
+ userInfo: UserInfo;
779
+ goodsInfo: GoodsInfo;
780
+ addressInfo?: AddressInfo;
781
+ paymentInfo: PaymentInfo;
782
+ cardInfo?: CardInfo;
783
+ PaymentTokenData?: string;
784
+ orderRequestedAt?: string;
785
+ orderExpiredAt?: string;
786
+ successRedirectUrl?: string;
787
+ failedRedirectUrl?: string;
788
+ cancelRedirectUrl?: string;
789
+ notifyUrl: string;
790
+ riskData?: RiskData;
791
+ extendInfo?: string | Record<string, unknown>;
792
+ }
793
+ /**
794
+ * Inquiry Order Request Parameters Interface
795
+ *
796
+ * @description
797
+ * Request parameters for calling `waffo.order.inquiry()`.
798
+ *
799
+ * @interface InquiryOrderParams
800
+ */
801
+ interface InquiryOrderParams {
802
+ paymentRequestId?: string;
803
+ acquiringOrderId?: string;
804
+ }
805
+ /**
806
+ * Cancel Order Request Parameters Interface
807
+ *
808
+ * @description
809
+ * Request parameters for calling `waffo.order.cancel()`.
810
+ *
811
+ * @interface CancelOrderParams
812
+ */
813
+ interface CancelOrderParams {
814
+ paymentRequestId?: string;
815
+ acquiringOrderId?: string;
816
+ merchantId: string;
817
+ orderRequestedAt?: string;
818
+ }
819
+ /**
820
+ * Order Refund Request Parameters Interface
821
+ *
822
+ * @description
823
+ * Request parameters for calling `waffo.order.refund()`.
824
+ *
825
+ * @interface RefundOrderParams
826
+ */
827
+ interface RefundOrderParams {
828
+ refundRequestId: string;
829
+ acquiringOrderId: string;
830
+ merchantRefundOrderId?: string;
831
+ merchantId: string;
832
+ requestedAt?: string;
833
+ refundAmount: string;
834
+ refundReason: string;
835
+ refundNotifyUrl?: string;
836
+ userInfo?: RefundUserInfo;
837
+ extendInfo?: string | Record<string, unknown>;
838
+ }
839
+ /**
840
+ * Capture Request Parameters Interface
841
+ *
842
+ * @description
843
+ * Request parameters for calling `waffo.order.capture()`.
844
+ *
845
+ * @interface CaptureOrderParams
846
+ */
847
+ interface CaptureOrderParams {
848
+ paymentRequestId?: string;
849
+ acquiringOrderId?: string;
850
+ merchantId: string;
851
+ captureRequestedAt?: string;
852
+ captureAmount: string;
853
+ }
854
+ /**
855
+ * Order Action Data Interface (Response)
856
+ *
857
+ * @description
858
+ * Payment data for merchant's custom checkout page.
859
+ *
860
+ * @interface OrderActionData
861
+ */
862
+ interface OrderActionData {
863
+ paymentExpiryTime?: string;
864
+ paymentQr?: string;
865
+ paymentCode?: string;
866
+ paymentBarCode?: string;
867
+ paymentCurrency?: string;
868
+ paymentAmount?: string;
869
+ userFeeAmount?: string;
870
+ userFeeCurrency?: string;
871
+ exchangeRate?: string;
872
+ [key: string]: string | undefined;
873
+ }
874
+ /**
875
+ * Order Action Interface (Response)
876
+ *
877
+ * @description
878
+ * Returned when order status is AUTHORIZATION_REQUIRED.
879
+ *
880
+ * @interface OrderAction
881
+ */
882
+ interface OrderAction {
883
+ actionType: OrderActionType | string;
884
+ webUrl?: string;
885
+ deeplinkUrl?: string;
886
+ actionData?: OrderActionData;
887
+ }
888
+ /**
889
+ * Merchant Information Interface (Response)
890
+ *
891
+ * @description
892
+ * Merchant information associated with the order.
893
+ *
894
+ * @interface MerchantInfoResponse
895
+ */
896
+ interface MerchantInfoResponse {
897
+ merchantId: string;
898
+ subMerchantId?: string;
899
+ }
900
+ /**
901
+ * User Information Interface (Response)
902
+ *
903
+ * @description
904
+ * User information associated with the order.
905
+ *
906
+ * @interface UserInfoResponse
907
+ */
908
+ interface UserInfoResponse {
909
+ userId: string;
910
+ userEmail: string;
911
+ userPhone?: string;
912
+ userCountryCode?: string;
913
+ userTerminal: UserTerminalType | string;
914
+ userFirstName?: string;
915
+ userLastName?: string;
916
+ userCreatedAt?: string;
917
+ userBrowserIp?: string;
918
+ userAgent?: string;
919
+ }
920
+ /**
921
+ * Goods Information Interface (Response)
922
+ *
923
+ * @description
924
+ * Product information associated with the order.
925
+ *
926
+ * @interface GoodsInfoResponse
927
+ */
928
+ interface GoodsInfoResponse {
929
+ goodsId?: string;
930
+ goodsName: string;
931
+ goodsCategory?: string;
932
+ goodsUrl?: string;
933
+ appName?: string;
934
+ skuName?: string;
935
+ goodsUniquePrice?: string;
936
+ goodsQuantity?: number | string;
937
+ }
938
+ /**
939
+ * Address Information Interface (Response)
940
+ *
941
+ * @description
942
+ * Address information associated with the order.
943
+ *
944
+ * @interface AddressInfoResponse
945
+ */
946
+ interface AddressInfoResponse {
947
+ address?: string;
948
+ city?: string;
949
+ region?: string;
950
+ postcode?: string;
951
+ addressCountryCode?: string;
952
+ }
953
+ /**
954
+ * Payment Method Response Data Interface (Response)
955
+ *
956
+ * @description
957
+ * Specific data returned by payment channel.
958
+ *
959
+ * @interface PayMethodResponse
960
+ */
961
+ interface PayMethodResponse {
962
+ payMethodRefId?: string;
963
+ exchangeRate?: string;
964
+ userOpenId?: string;
965
+ maskCardData?: string;
966
+ [key: string]: string | undefined;
967
+ }
968
+ /**
969
+ * Payment Information Interface (Response)
970
+ *
971
+ * @description
972
+ * Payment method details for the order.
973
+ *
974
+ * @interface PaymentInfoResponse
975
+ */
976
+ interface PaymentInfoResponse {
977
+ productName: ProductName | string;
978
+ /**
979
+ * Payment type (max 256 characters)
980
+ * Example values: "EWALLET", "CREDITCARD", "BANKTRANSFER", "ONLINE_BANKING", "DIGITAL_BANKING", "OTC", "DEBITCARD"
981
+ * Note: This list may be updated. Please refer to the latest API documentation.
982
+ */
983
+ payMethodType: string;
984
+ /**
985
+ * Specific payment method (max 24 characters)
986
+ * Example E-wallets: "OVO", "DANA", "GOPAY", "SHOPEEPAY", "GCASH", "ALIPAY_HK"
987
+ * Example Credit Cards: "CC_VISA", "CC_MASTERCARD"
988
+ * Example Bank Transfer: "VA_BCA", "VA_BNI"
989
+ * Note: This list may be updated. Please refer to the latest API documentation.
990
+ */
991
+ payMethodName: string;
992
+ payMethodCountry?: string;
993
+ payMethodProperties?: PayMethodProperties | string;
994
+ payMethodResponse?: PayMethodResponse | string;
995
+ payMethodUserAccountType?: PayMethodUserAccountType | string;
996
+ payMethodUserAccountNo?: string;
997
+ cashierLanguage?: string;
998
+ payOption?: string;
999
+ userPaymentAccessToken?: string;
1000
+ captureMode?: CaptureMode | string;
1001
+ merchantInitiatedMode?: MerchantInitiatedMode | string;
1002
+ }
1003
+ /**
1004
+ * Order Failed Reason Interface (Response)
1005
+ *
1006
+ * @description
1007
+ * Error details when order fails.
1008
+ *
1009
+ * @interface OrderFailedReason
1010
+ */
1011
+ interface OrderFailedReason {
1012
+ orderFailedCode: string;
1013
+ orderFailedDescription: string;
1014
+ }
1015
+ /**
1016
+ * Create Order Response Data Interface
1017
+ *
1018
+ * @description
1019
+ * Business data returned by `waffo.order.create()`.
1020
+ *
1021
+ * @interface CreateOrderData
1022
+ */
1023
+ interface CreateOrderData {
1024
+ paymentRequestId: string;
1025
+ merchantOrderId: string;
1026
+ acquiringOrderId: string;
1027
+ orderStatus: OrderStatus | string;
1028
+ orderAction?: OrderAction;
1029
+ }
1030
+ /**
1031
+ * Order Inquiry Response Data Interface
1032
+ *
1033
+ * @description
1034
+ * Complete order details returned by `waffo.order.inquiry()`.
1035
+ *
1036
+ * @interface InquiryOrderData
1037
+ */
1038
+ interface InquiryOrderData {
1039
+ paymentRequestId: string;
1040
+ merchantOrderId: string;
1041
+ acquiringOrderId: string;
1042
+ orderStatus: OrderStatus | string;
1043
+ orderAction?: OrderAction;
1044
+ orderCurrency: string;
1045
+ orderAmount: string;
1046
+ userCurrency?: string;
1047
+ finalDealAmount: string;
1048
+ orderDescription: string;
1049
+ merchantInfo: MerchantInfoResponse;
1050
+ userInfo: UserInfoResponse;
1051
+ goodsInfo?: GoodsInfoResponse;
1052
+ addressInfo?: AddressInfoResponse;
1053
+ paymentInfo: PaymentInfoResponse;
1054
+ orderRequestedAt: string;
1055
+ orderExpiredAt?: string;
1056
+ orderUpdatedAt: string;
1057
+ orderCompletedAt: string;
1058
+ orderFailedReason?: OrderFailedReason | string;
1059
+ extendInfo?: string | Record<string, unknown>;
1060
+ }
1061
+ /**
1062
+ * Cancel Order Response Data Interface
1063
+ *
1064
+ * @description
1065
+ * Business data returned by `waffo.order.cancel()`.
1066
+ *
1067
+ * @interface CancelOrderData
1068
+ */
1069
+ interface CancelOrderData {
1070
+ paymentRequestId: string;
1071
+ merchantOrderId: string;
1072
+ acquiringOrderId: string;
1073
+ orderStatus: OrderStatus.ORDER_CLOSE | string;
1074
+ }
1075
+ /**
1076
+ * Capture Response Data Interface
1077
+ *
1078
+ * @description
1079
+ * Business data returned by `waffo.order.capture()`.
1080
+ *
1081
+ * @interface CaptureOrderData
1082
+ */
1083
+ interface CaptureOrderData {
1084
+ paymentRequestId: string;
1085
+ merchantOrderId: string;
1086
+ acquiringOrderId: string;
1087
+ orderStatus: OrderStatus | string;
1088
+ }
1089
+ /**
1090
+ * Payment Notification Result Interface
1091
+ *
1092
+ * @description
1093
+ * Payload for PAYMENT_NOTIFICATION webhook (one-time/direct payment).
1094
+ *
1095
+ * @interface PaymentNotificationResult
1096
+ */
1097
+ interface PaymentNotificationResult {
1098
+ paymentRequestId: string;
1099
+ merchantOrderId: string;
1100
+ acquiringOrderId: string;
1101
+ orderStatus: OrderStatus | string;
1102
+ orderAction?: OrderAction;
1103
+ orderCurrency: string;
1104
+ orderAmount: string;
1105
+ userCurrency?: string;
1106
+ finalDealAmount: string;
1107
+ orderDescription: string;
1108
+ merchantInfo: MerchantInfoResponse;
1109
+ userInfo: UserInfoResponse;
1110
+ goodsInfo?: GoodsInfoResponse;
1111
+ addressInfo?: AddressInfoResponse;
1112
+ paymentInfo: PaymentInfoResponse;
1113
+ orderRequestedAt: string;
1114
+ orderExpiredAt?: string;
1115
+ orderUpdatedAt: string;
1116
+ orderCompletedAt: string;
1117
+ orderFailedReason?: OrderFailedReason | string;
1118
+ extendInfo?: string | Record<string, unknown>;
1119
+ }
1120
+ /**
1121
+ * Payment Notification Interface
1122
+ *
1123
+ * @description
1124
+ * Webhook notification for payment order status changes.
1125
+ *
1126
+ * @interface PaymentNotification
1127
+ */
1128
+ interface PaymentNotification {
1129
+ eventType: WebhookEventType.PAYMENT_NOTIFICATION;
1130
+ result: PaymentNotificationResult;
1131
+ }
1132
+ /**
1133
+ * Payment Webhook Request Interface
1134
+ *
1135
+ * @description
1136
+ * Full structure of payment notification webhook request from Waffo.
1137
+ *
1138
+ * @interface PaymentWebhookRequest
1139
+ */
1140
+ interface PaymentWebhookRequest {
1141
+ header: WebhookRequestHeader;
1142
+ body: PaymentNotification;
1143
+ }
1144
+
1145
+ /**
1146
+ * @fileoverview Refund Resource Type Definitions
1147
+ * @module types/refund
1148
+ *
1149
+ * Type definitions for the Refund resource (based on Waffo API JSON Schema).
1150
+ *
1151
+ * **Categories:**
1152
+ * - **Enums:** Refund status states
1153
+ * - **Request Interfaces:** Parameters for refund inquiry
1154
+ * - **Response Interfaces:** Refund data structures
1155
+ * - **Webhook Interfaces:** Refund notification structures
1156
+ *
1157
+ * @see {@link RefundResource} for API methods
1158
+ * @see {@link RefundInquiryParams} for inquiry parameters
1159
+ *
1160
+ * @example
1161
+ * import { RefundStatus, RefundInquiryParams } from 'waffo-sdk';
1162
+ *
1163
+ * const params: RefundInquiryParams = {
1164
+ * refundRequestId: 'refund-123',
1165
+ * };
1166
+ */
1167
+
1168
+ /**
1169
+ * Refund Status Enum
1170
+ *
1171
+ * @description
1172
+ * Identifies the current status of a refund request in the processing flow.
1173
+ *
1174
+ * @enum {string}
1175
+ * @readonly
1176
+ */
1177
+ declare enum RefundStatus {
1178
+ REFUND_IN_PROGRESS = "REFUND_IN_PROGRESS",
1179
+ ORDER_PARTIALLY_REFUNDED = "ORDER_PARTIALLY_REFUNDED",
1180
+ ORDER_FULLY_REFUNDED = "ORDER_FULLY_REFUNDED",
1181
+ ORDER_REFUND_FAILED = "ORDER_REFUND_FAILED"
1182
+ }
1183
+ /**
1184
+ * Refund Inquiry Request Parameters Interface
1185
+ *
1186
+ * @description
1187
+ * Request parameters for calling `waffo.refund.inquiry()`.
1188
+ *
1189
+ * @interface RefundInquiryParams
1190
+ */
1191
+ interface RefundInquiryParams {
1192
+ refundRequestId?: string;
1193
+ acquiringRefundOrderId?: string;
1194
+ }
1195
+ /**
1196
+ * Refund Failed Reason Interface (Response)
1197
+ *
1198
+ * @description
1199
+ * Error details when refund fails.
1200
+ *
1201
+ * @interface RefundFailedReason
1202
+ */
1203
+ interface RefundFailedReason {
1204
+ refundFailedCode: string;
1205
+ refundFailedDescription: string;
1206
+ }
1207
+ /**
1208
+ * Refund User Bank Information Interface (Response)
1209
+ *
1210
+ * @description
1211
+ * Bank account information returned for bank transfer refunds.
1212
+ *
1213
+ * @interface RefundUserBankInfo
1214
+ */
1215
+ interface RefundUserBankInfo {
1216
+ bankAccountNo: string;
1217
+ bankCode: string;
1218
+ bankCity?: string;
1219
+ bankBranch?: string;
1220
+ [key: string]: string | undefined;
1221
+ }
1222
+ /**
1223
+ * Refund User Information Interface (Response)
1224
+ *
1225
+ * @description
1226
+ * User information returned for specific payment method refunds.
1227
+ *
1228
+ * @interface RefundUserInfoResponse
1229
+ */
1230
+ interface RefundUserInfoResponse {
1231
+ userType?: RefundUserType;
1232
+ userFirstName?: string;
1233
+ userLastName?: string;
1234
+ userEmail?: string;
1235
+ userBankInfo?: RefundUserBankInfo | string;
1236
+ userPhone?: string;
1237
+ userIDType?: string;
1238
+ userIDNumber?: string;
1239
+ userIDIssueDate?: string;
1240
+ userIDExpiryDate?: string;
1241
+ }
1242
+ /**
1243
+ * Create Refund Response Data Interface
1244
+ *
1245
+ * @description
1246
+ * Business data returned by `waffo.order.refund()`.
1247
+ *
1248
+ * @interface CreateRefundData
1249
+ */
1250
+ interface CreateRefundData {
1251
+ refundRequestId: string;
1252
+ merchantRefundOrderId?: string;
1253
+ acquiringOrderId: string;
1254
+ acquiringRefundOrderId: string;
1255
+ refundAmount: string;
1256
+ refundStatus: RefundStatus | string;
1257
+ remainingRefundAmount: string;
1258
+ }
1259
+ /**
1260
+ * Refund Inquiry Response Data Interface
1261
+ *
1262
+ * @description
1263
+ * Complete refund details returned by `waffo.refund.inquiry()`.
1264
+ *
1265
+ * @interface InquiryRefundData
1266
+ */
1267
+ interface InquiryRefundData {
1268
+ refundRequestId: string;
1269
+ merchantRefundOrderId?: string;
1270
+ acquiringOrderId: string;
1271
+ acquiringRefundOrderId: string;
1272
+ origPaymentRequestId: string;
1273
+ refundAmount: string;
1274
+ refundStatus: RefundStatus | string;
1275
+ remainingRefundAmount: string;
1276
+ userCurrency?: string;
1277
+ finalDealAmount: string;
1278
+ refundReason: string;
1279
+ refundRequestedAt: string;
1280
+ refundUpdatedAt: string;
1281
+ refundCompletedAt: string;
1282
+ refundFailedReason?: RefundFailedReason | string;
1283
+ userInfo?: RefundUserInfoResponse;
1284
+ extendInfo?: string | Record<string, unknown>;
1285
+ }
1286
+ /**
1287
+ * Refund Notification Result Interface
1288
+ *
1289
+ * @description
1290
+ * Payload for REFUND_NOTIFICATION webhook.
1291
+ *
1292
+ * @interface RefundNotificationResult
1293
+ */
1294
+ interface RefundNotificationResult {
1295
+ refundRequestId: string;
1296
+ merchantRefundOrderId?: string;
1297
+ acquiringOrderId: string;
1298
+ acquiringRefundOrderId: string;
1299
+ origPaymentRequestId: string;
1300
+ refundAmount: string;
1301
+ refundStatus: RefundStatus | string;
1302
+ remainingRefundAmount: string;
1303
+ userCurrency?: string;
1304
+ finalDealAmount: string;
1305
+ refundReason: string;
1306
+ refundRequestedAt: string;
1307
+ refundUpdatedAt: string;
1308
+ refundCompletedAt: string;
1309
+ refundFailedReason?: RefundFailedReason | string;
1310
+ userInfo?: RefundUserInfoResponse;
1311
+ extendInfo?: string | Record<string, unknown>;
1312
+ }
1313
+ /**
1314
+ * Refund Notification Interface
1315
+ *
1316
+ * @description
1317
+ * Webhook notification for refund order status changes.
1318
+ *
1319
+ * @interface RefundNotification
1320
+ */
1321
+ interface RefundNotification {
1322
+ eventType: WebhookEventType.REFUND_NOTIFICATION;
1323
+ result: RefundNotificationResult;
1324
+ }
1325
+ /**
1326
+ * Refund Webhook Request Interface
1327
+ *
1328
+ * @description
1329
+ * Full structure of refund notification webhook request from Waffo.
1330
+ *
1331
+ * @interface RefundWebhookRequest
1332
+ */
1333
+ interface RefundWebhookRequest {
1334
+ header: WebhookRequestHeader;
1335
+ body: RefundNotification;
1336
+ }
1337
+
1338
+ /**
1339
+ * @fileoverview Subscription Resource Type Definitions
1340
+ * @module types/subscription
1341
+ *
1342
+ * Type definitions for the Subscription resource (based on Waffo API JSON Schema).
1343
+ *
1344
+ * **Categories:**
1345
+ * - **Enums:** Subscription status, period types, event types
1346
+ * - **Request Interfaces:** Parameters for create, inquiry, cancel, manage
1347
+ * - **Response Interfaces:** Subscription data structures
1348
+ * - **Webhook Interfaces:** Subscription notification structures
1349
+ *
1350
+ * @see {@link SubscriptionResource} for API methods
1351
+ * @see {@link CreateSubscriptionParams} for subscription creation
1352
+ *
1353
+ * @example
1354
+ * import {
1355
+ * CreateSubscriptionParams,
1356
+ * SubscriptionStatus,
1357
+ * PeriodType,
1358
+ * } from 'waffo-sdk';
1359
+ *
1360
+ * const params: CreateSubscriptionParams = {
1361
+ * subscriptionRequest: 'sub-123',
1362
+ * currency: 'USD',
1363
+ * amount: '9.99',
1364
+ * productInfo: {
1365
+ * description: 'Monthly Plan',
1366
+ * periodType: PeriodType.MONTHLY,
1367
+ * periodInterval: '1',
1368
+ * },
1369
+ * // ...
1370
+ * };
1371
+ */
1372
+
1373
+ /**
1374
+ * Subscription Status Enum
1375
+ *
1376
+ * @description
1377
+ * Identifies the current status of a subscription.
1378
+ *
1379
+ * @enum {string}
1380
+ * @readonly
1381
+ */
1382
+ declare enum SubscriptionStatus {
1383
+ AUTHORIZATION_REQUIRED = "AUTHORIZATION_REQUIRED",
1384
+ IN_PROGRESS = "IN_PROGRESS",
1385
+ ACTIVE = "ACTIVE",
1386
+ CLOSE = "CLOSE",
1387
+ MERCHANT_CANCELLED = "MERCHANT_CANCELLED",
1388
+ USER_CANCELLED = "USER_CANCELLED",
1389
+ CHANNEL_CANCELLED = "CHANNEL_CANCELLED",
1390
+ EXPIRED = "EXPIRED"
1391
+ }
1392
+ /**
1393
+ * Period Type Enum
1394
+ *
1395
+ * @description
1396
+ * Billing period type for subscription.
1397
+ *
1398
+ * @enum {string}
1399
+ * @readonly
1400
+ */
1401
+ declare enum PeriodType {
1402
+ DAILY = "DAILY",
1403
+ WEEKLY = "WEEKLY",
1404
+ MONTHLY = "MONTHLY"
1405
+ }
1406
+ /**
1407
+ * User Terminal Type Enum
1408
+ *
1409
+ * @description
1410
+ * Identifies the terminal environment where the user initiates subscription.
1411
+ *
1412
+ * @enum {string}
1413
+ * @readonly
1414
+ */
1415
+ declare enum SubscriptionUserTerminalType {
1416
+ WEB = "WEB",
1417
+ APP = "APP"
1418
+ }
1419
+ /**
1420
+ * Cashier Language Enum
1421
+ *
1422
+ * @description
1423
+ * Supported cashier languages.
1424
+ *
1425
+ * @enum {string}
1426
+ * @readonly
1427
+ */
1428
+ declare enum CashierLanguage {
1429
+ EN_HK = "en-HK",
1430
+ ZH_HANT_HK = "zh-Hant-HK",
1431
+ ZH_HANS_HK = "zh-Hans-HK"
1432
+ }
1433
+ /**
1434
+ * Pay Method User Account Type Enum
1435
+ *
1436
+ * @description
1437
+ * User account type at the designated pay method.
1438
+ *
1439
+ * @enum {string}
1440
+ * @readonly
1441
+ */
1442
+ declare enum SubscriptionPayMethodUserAccountType {
1443
+ EMAIL = "EMAIL",
1444
+ PHONE_NO = "PHONE_NO",
1445
+ ACCOUNT_ID = "ACCOUNT_ID"
1446
+ }
1447
+ /**
1448
+ * Subscription Order Status Enum
1449
+ *
1450
+ * @description
1451
+ * Status for subscription payment order.
1452
+ *
1453
+ * @enum {string}
1454
+ * @readonly
1455
+ */
1456
+ declare enum SubscriptionOrderStatus {
1457
+ PAY_SUCCESS = "PAY_SUCCESS",
1458
+ ORDER_CLOSE = "ORDER_CLOSE"
1459
+ }
1460
+ /**
1461
+ * Subscription Event Type Enum
1462
+ *
1463
+ * @description
1464
+ * Event types for subscription webhook notifications.
1465
+ *
1466
+ * @enum {string}
1467
+ * @readonly
1468
+ */
1469
+ declare enum SubscriptionEventType {
1470
+ SUBSCRIPTION_STATUS_NOTIFICATION = "SUBSCRIPTION_STATUS_NOTIFICATION",
1471
+ PAYMENT_NOTIFICATION = "PAYMENT_NOTIFICATION"
1472
+ }
1473
+ /**
1474
+ * Product Information Interface (Request Parameters)
1475
+ *
1476
+ * @description
1477
+ * Subscription billing product configuration.
1478
+ *
1479
+ * @interface ProductInfo
1480
+ */
1481
+ interface ProductInfo {
1482
+ description: string;
1483
+ periodType: PeriodType | string;
1484
+ periodInterval: string;
1485
+ numberOfPeriod?: string;
1486
+ trialPeriodAmount?: string;
1487
+ numberOfTrialPeriod?: string;
1488
+ trialPeriodType?: PeriodType | string;
1489
+ trialPeriodInterval?: string;
1490
+ }
1491
+ /**
1492
+ * Merchant Information Interface (Request Parameters)
1493
+ *
1494
+ * @description
1495
+ * Merchant information for subscription.
1496
+ *
1497
+ * @interface SubscriptionMerchantInfo
1498
+ */
1499
+ interface SubscriptionMerchantInfo {
1500
+ merchantId: string;
1501
+ subMerchantId?: string;
1502
+ }
1503
+ /**
1504
+ * Subscription User Info Interface (Request Parameters)
1505
+ *
1506
+ * @description
1507
+ * User information for subscription.
1508
+ *
1509
+ * @interface SubscriptionUserInfo
1510
+ */
1511
+ interface SubscriptionUserInfo {
1512
+ userId: string;
1513
+ userEmail: string;
1514
+ userTerminal?: SubscriptionUserTerminalType | string;
1515
+ userPhone?: string;
1516
+ userFirstName?: string;
1517
+ userLastName?: string;
1518
+ userCreatedAt?: string;
1519
+ }
1520
+ /**
1521
+ * Subscription Goods Information Interface (Request Parameters)
1522
+ *
1523
+ * @description
1524
+ * Goods information for subscription.
1525
+ *
1526
+ * @interface SubscriptionGoodsInfo
1527
+ */
1528
+ interface SubscriptionGoodsInfo {
1529
+ goodsId: string;
1530
+ goodsName: string;
1531
+ goodsCategory?: string;
1532
+ goodsUrl?: string;
1533
+ appName?: string;
1534
+ skuName?: string;
1535
+ goodsUniquePrice?: string;
1536
+ goodsQuantity?: number;
1537
+ }
1538
+ /**
1539
+ * Subscription Address Information Interface (Request Parameters)
1540
+ *
1541
+ * @description
1542
+ * Address information for subscription.
1543
+ *
1544
+ * @interface SubscriptionAddressInfo
1545
+ */
1546
+ interface SubscriptionAddressInfo {
1547
+ address?: string;
1548
+ city?: string;
1549
+ region?: string;
1550
+ postcode?: string;
1551
+ addressCountryCode?: string;
1552
+ }
1553
+ /**
1554
+ * Subscription Payment Info Interface (Request Parameters)
1555
+ *
1556
+ * @description
1557
+ * Payment method configuration for subscription.
1558
+ *
1559
+ * @interface SubscriptionPaymentInfo
1560
+ */
1561
+ interface SubscriptionPaymentInfo {
1562
+ productName: SubscriptionProductName | string;
1563
+ /**
1564
+ * Payment method type (max 256 characters)
1565
+ * Example values: "EWALLET", "CREDITCARD", "DEBITCARD"
1566
+ * Note: This list may be updated. Please refer to the latest API documentation.
1567
+ */
1568
+ payMethodType?: string;
1569
+ /**
1570
+ * Specific payment method name (max 24 characters) - required
1571
+ * Example E-wallets: "DANA", "GCASH", "ALIPAY_HK"
1572
+ * Example Credit Cards: "CC_VISA", "CC_MASTERCARD"
1573
+ * Note: This list may be updated. Please refer to the latest API documentation.
1574
+ */
1575
+ payMethodName: string;
1576
+ payMethodProperties?: Record<string, unknown> | string;
1577
+ payMethodUserAccountType?: SubscriptionPayMethodUserAccountType | string;
1578
+ cashierLanguage?: CashierLanguage | string;
1579
+ payMethodUserAccountNo?: string;
1580
+ payMethodUserAccessToken?: string;
1581
+ }
1582
+ /**
1583
+ * Risk Data Interface (Request Parameters)
1584
+ *
1585
+ * @description
1586
+ * Auxiliary data for risk assessment.
1587
+ *
1588
+ * @interface SubscriptionRiskData
1589
+ */
1590
+ interface SubscriptionRiskData {
1591
+ userType?: RiskUserType;
1592
+ userCategory?: string;
1593
+ userLegalName?: string;
1594
+ userDisplayName?: string;
1595
+ userRegistrationIp?: string;
1596
+ userLastSeenIp?: string;
1597
+ userIsNew?: string;
1598
+ userIsFirstPurchase?: string;
1599
+ }
1600
+ /**
1601
+ * Create Subscription Request Parameters Interface
1602
+ *
1603
+ * @description
1604
+ * Request parameters for calling `waffo.subscription.create()`.
1605
+ *
1606
+ * @interface CreateSubscriptionParams
1607
+ */
1608
+ interface CreateSubscriptionParams {
1609
+ subscriptionRequest: string;
1610
+ merchantSubscriptionId?: string;
1611
+ currency: string;
1612
+ amount: string;
1613
+ userCurrency?: string;
1614
+ productInfo: ProductInfo;
1615
+ merchantInfo: SubscriptionMerchantInfo;
1616
+ userInfo: SubscriptionUserInfo;
1617
+ goodsInfo: SubscriptionGoodsInfo;
1618
+ addressInfo?: SubscriptionAddressInfo;
1619
+ paymentInfo: SubscriptionPaymentInfo;
1620
+ requestedAt?: string;
1621
+ successRedirectUrl?: string;
1622
+ failedRedirectUrl?: string;
1623
+ cancelRedirectUrl?: string;
1624
+ notifyUrl: string;
1625
+ subscriptionManagementUrl?: string;
1626
+ riskData?: SubscriptionRiskData;
1627
+ extendInfo?: string | Record<string, unknown>;
1628
+ }
1629
+ /**
1630
+ * Inquiry Subscription Request Parameters Interface
1631
+ *
1632
+ * @description
1633
+ * Request parameters for calling `waffo.subscription.inquiry()`.
1634
+ *
1635
+ * @interface InquirySubscriptionParams
1636
+ */
1637
+ interface InquirySubscriptionParams {
1638
+ subscriptionRequest?: string;
1639
+ subscriptionId?: string;
1640
+ paymentDetails?: "0" | "1";
1641
+ }
1642
+ /**
1643
+ * Cancel Subscription Request Parameters Interface
1644
+ *
1645
+ * @description
1646
+ * Request parameters for calling `waffo.subscription.cancel()`.
1647
+ *
1648
+ * @interface CancelSubscriptionParams
1649
+ */
1650
+ interface CancelSubscriptionParams {
1651
+ subscriptionId: string;
1652
+ merchantId: string;
1653
+ requestedAt?: string;
1654
+ }
1655
+ /**
1656
+ * Manage Subscription Request Parameters Interface
1657
+ *
1658
+ * @description
1659
+ * Request parameters for calling `waffo.subscription.manage()`.
1660
+ *
1661
+ * @interface ManageSubscriptionParams
1662
+ */
1663
+ interface ManageSubscriptionParams {
1664
+ subscriptionRequest?: string;
1665
+ subscriptionId?: string;
1666
+ }
1667
+ /**
1668
+ * Subscription Action Interface (Response)
1669
+ *
1670
+ * @description
1671
+ * Returned when subscription status is AUTHORIZATION_REQUIRED.
1672
+ *
1673
+ * @interface SubscriptionAction
1674
+ */
1675
+ interface SubscriptionAction {
1676
+ webUrl: string;
1677
+ }
1678
+ /**
1679
+ * Product Info Response Interface (Response)
1680
+ *
1681
+ * @description
1682
+ * Subscription product configuration in response.
1683
+ *
1684
+ * @interface ProductInfoResponse
1685
+ */
1686
+ interface ProductInfoResponse {
1687
+ description: string;
1688
+ periodType: PeriodType | string;
1689
+ periodInterval: string;
1690
+ numberOfPeriod?: string;
1691
+ trialPeriodAmount?: string;
1692
+ numberOfTrialPeriod?: string;
1693
+ startDateTime?: string;
1694
+ endDateTime?: string;
1695
+ nextPaymentDateTime?: string;
1696
+ currentPeriod?: string;
1697
+ }
1698
+ /**
1699
+ * Payment Detail Interface (Response)
1700
+ *
1701
+ * @description
1702
+ * Individual payment record within subscription.
1703
+ *
1704
+ * @interface PaymentDetail
1705
+ */
1706
+ interface PaymentDetail {
1707
+ acquiringOrderId: string;
1708
+ orderCurrency: string;
1709
+ orderAmount: string;
1710
+ orderStatus: SubscriptionOrderStatus | string;
1711
+ orderUpdatedAt: string;
1712
+ period: string;
1713
+ }
1714
+ /**
1715
+ * Subscription Failed Reason Interface (Response)
1716
+ *
1717
+ * @description
1718
+ * Error details when subscription fails.
1719
+ *
1720
+ * @interface SubscriptionFailedReason
1721
+ */
1722
+ interface SubscriptionFailedReason {
1723
+ orderFailedCode: string;
1724
+ orderFailedDescription: string;
1725
+ }
1726
+ /**
1727
+ * Payment Method Response Interface (Response)
1728
+ *
1729
+ * @description
1730
+ * Payment method response data.
1731
+ *
1732
+ * @interface SubscriptionPayMethodResponse
1733
+ */
1734
+ interface SubscriptionPayMethodResponse {
1735
+ payMethodRefId?: string;
1736
+ exchangeRate?: string;
1737
+ userOpenId?: string;
1738
+ maskCardData?: string;
1739
+ [key: string]: string | undefined;
1740
+ }
1741
+ /**
1742
+ * Subscription Payment Info Response Interface (Response)
1743
+ *
1744
+ * @description
1745
+ * Payment method information in response.
1746
+ *
1747
+ * @interface SubscriptionPaymentInfoResponse
1748
+ */
1749
+ interface SubscriptionPaymentInfoResponse {
1750
+ productName: SubscriptionProductName | string;
1751
+ /**
1752
+ * Payment method type (max 256 characters)
1753
+ * Example values: "EWALLET", "CREDITCARD", "DEBITCARD"
1754
+ * Note: This list may be updated. Please refer to the latest API documentation.
1755
+ */
1756
+ payMethodType?: string;
1757
+ /**
1758
+ * Payment method name (max 24 characters)
1759
+ * Example E-wallets: "DANA", "GCASH", "ALIPAY_HK"
1760
+ * Example Credit Cards: "CC_VISA", "CC_MASTERCARD"
1761
+ * Note: This list may be updated. Please refer to the latest API documentation.
1762
+ */
1763
+ payMethodName: string;
1764
+ payMethodProperties?: Record<string, unknown> | string;
1765
+ payMethodResponse?: SubscriptionPayMethodResponse | string;
1766
+ payMethodUserAccountType?: SubscriptionPayMethodUserAccountType | string;
1767
+ payMethodUserAccountNo?: string;
1768
+ payMethodUserAccessToken?: string;
1769
+ payMethodPublicUid?: string;
1770
+ }
1771
+ /**
1772
+ * Create Subscription Response Data Interface
1773
+ *
1774
+ * @description
1775
+ * Business data returned by `waffo.subscription.create()`.
1776
+ *
1777
+ * @interface CreateSubscriptionData
1778
+ */
1779
+ interface CreateSubscriptionData {
1780
+ subscriptionRequest: string;
1781
+ merchantSubscriptionId?: string;
1782
+ subscriptionId: string;
1783
+ payMethodSubscriptionId?: string;
1784
+ subscriptionStatus: SubscriptionStatus | string;
1785
+ subscriptionAction?: SubscriptionAction;
1786
+ }
1787
+ /**
1788
+ * Inquiry Subscription Response Data Interface
1789
+ *
1790
+ * @description
1791
+ * Business data returned by `waffo.subscription.inquiry()`.
1792
+ *
1793
+ * @interface InquirySubscriptionData
1794
+ */
1795
+ interface InquirySubscriptionData {
1796
+ subscriptionRequest: string;
1797
+ merchantSubscriptionId?: string;
1798
+ subscriptionId: string;
1799
+ subscriptionStatus: SubscriptionStatus | string;
1800
+ subscriptionAction?: SubscriptionAction;
1801
+ currency: string;
1802
+ amount: string;
1803
+ userCurrency?: string;
1804
+ productInfo: ProductInfoResponse;
1805
+ merchantInfo: SubscriptionMerchantInfo;
1806
+ userInfo: SubscriptionUserInfo;
1807
+ goodsInfo?: SubscriptionGoodsInfo;
1808
+ addressInfo?: SubscriptionAddressInfo;
1809
+ paymentInfo: SubscriptionPaymentInfoResponse;
1810
+ requestedAt: string;
1811
+ updatedAt: string;
1812
+ failedReason?: SubscriptionFailedReason | string;
1813
+ extendInfo?: string | Record<string, unknown>;
1814
+ subscriptionManagementUrl?: string;
1815
+ paymentDetails?: PaymentDetail[];
1816
+ }
1817
+ /**
1818
+ * Cancel Subscription Response Data Interface
1819
+ *
1820
+ * @description
1821
+ * Business data returned by `waffo.subscription.cancel()`.
1822
+ *
1823
+ * @interface CancelSubscriptionData
1824
+ */
1825
+ interface CancelSubscriptionData {
1826
+ subscriptionId: string;
1827
+ subscriptionRequest: string;
1828
+ merchantSubscriptionId?: string;
1829
+ orderStatus: SubscriptionStatus | string;
1830
+ }
1831
+ /**
1832
+ * Manage Subscription Response Data Interface
1833
+ *
1834
+ * @description
1835
+ * Business data returned by `waffo.subscription.manage()`.
1836
+ *
1837
+ * @interface ManageSubscriptionData
1838
+ */
1839
+ interface ManageSubscriptionData {
1840
+ subscriptionRequest: string;
1841
+ merchantSubscriptionId?: string;
1842
+ subscriptionId: string;
1843
+ managementUrl: string;
1844
+ expiredAt: string;
1845
+ subscriptionStatus: SubscriptionStatus | string;
1846
+ }
1847
+ /**
1848
+ * Subscription Info Interface (Response)
1849
+ *
1850
+ * @description
1851
+ * Subscription information in payment order response and webhook notifications.
1852
+ *
1853
+ * @interface SubscriptionInfo
1854
+ */
1855
+ interface SubscriptionInfo {
1856
+ subscriptionRequest: string;
1857
+ subscriptionId: string;
1858
+ period: string;
1859
+ }
1860
+ /**
1861
+ * Subscription Status Notification Result Interface
1862
+ *
1863
+ * @description
1864
+ * Payload for SUBSCRIPTION_STATUS_NOTIFICATION webhook.
1865
+ *
1866
+ * @interface SubscriptionStatusNotificationResult
1867
+ */
1868
+ interface SubscriptionStatusNotificationResult {
1869
+ subscriptionRequest: string;
1870
+ merchantSubscriptionId?: string;
1871
+ subscriptionId: string;
1872
+ subscriptionStatus: SubscriptionStatus | string;
1873
+ subscriptionAction?: SubscriptionAction;
1874
+ currency: string;
1875
+ amount: string;
1876
+ userCurrency?: string;
1877
+ productInfo: ProductInfoResponse;
1878
+ merchantInfo: SubscriptionMerchantInfo;
1879
+ userInfo: SubscriptionUserInfo;
1880
+ goodsInfo?: SubscriptionGoodsInfo;
1881
+ addressInfo?: SubscriptionAddressInfo;
1882
+ paymentInfo: SubscriptionPaymentInfoResponse;
1883
+ requestedAt: string;
1884
+ updatedAt: string;
1885
+ failedReason?: SubscriptionFailedReason | string;
1886
+ extendInfo?: string | Record<string, unknown>;
1887
+ subscriptionManagementUrl?: string;
1888
+ paymentDetails?: PaymentDetail[];
1889
+ }
1890
+ /**
1891
+ * Subscription Payment Notification Result Interface
1892
+ *
1893
+ * @description
1894
+ * Payload for PAYMENT_NOTIFICATION webhook (subscription deduction).
1895
+ *
1896
+ * @interface SubscriptionPaymentNotificationResult
1897
+ */
1898
+ interface SubscriptionPaymentNotificationResult {
1899
+ acquiringOrderId: string;
1900
+ orderStatus: SubscriptionOrderStatus | string;
1901
+ orderCurrency: string;
1902
+ orderAmount: string;
1903
+ userCurrency?: string;
1904
+ finalDealAmount: string;
1905
+ orderDescription: string;
1906
+ merchantInfo: SubscriptionMerchantInfo;
1907
+ userInfo: SubscriptionUserInfo;
1908
+ goodsInfo?: SubscriptionGoodsInfo;
1909
+ addressInfo?: SubscriptionAddressInfo;
1910
+ paymentInfo: SubscriptionPaymentInfoResponse;
1911
+ subscriptionInfo: SubscriptionInfo;
1912
+ orderRequestedAt: string;
1913
+ orderUpdatedAt: string;
1914
+ orderFailedReason?: SubscriptionFailedReason | string;
1915
+ extendInfo?: string | Record<string, unknown>;
1916
+ }
1917
+ /**
1918
+ * Subscription Status Notification Interface
1919
+ *
1920
+ * @description
1921
+ * Webhook notification for subscription status changes.
1922
+ *
1923
+ * @interface SubscriptionStatusNotification
1924
+ */
1925
+ interface SubscriptionStatusNotification {
1926
+ eventType: SubscriptionEventType.SUBSCRIPTION_STATUS_NOTIFICATION;
1927
+ result: SubscriptionStatusNotificationResult;
1928
+ }
1929
+ /**
1930
+ * Subscription Payment Notification Interface
1931
+ *
1932
+ * @description
1933
+ * Webhook notification for subscription payment events (recurring billing).
1934
+ *
1935
+ * @interface SubscriptionPaymentNotification
1936
+ */
1937
+ interface SubscriptionPaymentNotification {
1938
+ eventType: SubscriptionEventType.PAYMENT_NOTIFICATION;
1939
+ result: SubscriptionPaymentNotificationResult;
1940
+ }
1941
+ /**
1942
+ * Subscription Notification Union Type
1943
+ *
1944
+ * @description
1945
+ * Union type for all subscription webhook notifications.
1946
+ *
1947
+ * @typedef {SubscriptionStatusNotification | SubscriptionPaymentNotification} SubscriptionNotification
1948
+ */
1949
+ type SubscriptionNotification = SubscriptionStatusNotification | SubscriptionPaymentNotification;
1950
+ /**
1951
+ * Subscription Status Webhook Request Interface
1952
+ *
1953
+ * @description
1954
+ * Full structure of subscription status notification webhook request from Waffo.
1955
+ *
1956
+ * @interface SubscriptionStatusWebhookRequest
1957
+ */
1958
+ interface SubscriptionStatusWebhookRequest {
1959
+ header: WebhookRequestHeader;
1960
+ body: SubscriptionStatusNotification;
1961
+ }
1962
+ /**
1963
+ * Subscription Payment Webhook Request Interface
1964
+ *
1965
+ * @description
1966
+ * Full structure of subscription payment notification webhook request from Waffo.
1967
+ *
1968
+ * @interface SubscriptionPaymentWebhookRequest
1969
+ */
1970
+ interface SubscriptionPaymentWebhookRequest {
1971
+ header: WebhookRequestHeader;
1972
+ body: SubscriptionPaymentNotification;
1973
+ }
1974
+ /**
1975
+ * Subscription Webhook Request Union Type
1976
+ *
1977
+ * @description
1978
+ * Union type for all subscription webhook requests.
1979
+ *
1980
+ * @typedef {SubscriptionStatusWebhookRequest | SubscriptionPaymentWebhookRequest} SubscriptionWebhookRequest
1981
+ */
1982
+ type SubscriptionWebhookRequest = SubscriptionStatusWebhookRequest | SubscriptionPaymentWebhookRequest;
1983
+
1984
+ /**
1985
+ * @fileoverview Webhook Type Definitions
1986
+ * @module types/webhook
1987
+ *
1988
+ * Types for processing webhook notifications:
1989
+ * - Event types and response status enums
1990
+ * - Request/Response interfaces
1991
+ * - Handler types for processing notifications
1992
+ *
1993
+ * @see {@link WebhookHandler} for processing webhooks
1994
+ *
1995
+ * @example
1996
+ * import {
1997
+ * WebhookEventType,
1998
+ * WebhookResponseStatus,
1999
+ * WebhookHandlerOptions,
2000
+ * } from 'waffo-sdk';
2001
+ *
2002
+ * const options: WebhookHandlerOptions = {
2003
+ * onPayment: async (ctx) => {
2004
+ * console.log('Event:', ctx.eventType);
2005
+ * console.log('Notification:', ctx.notification);
2006
+ * },
2007
+ * };
2008
+ */
2009
+
2010
+ /**
2011
+ * Type of webhook notification from Waffo.
2012
+ *
2013
+ * @enum {string}
2014
+ * @readonly
2015
+ */
2016
+ declare enum WebhookEventType {
2017
+ /** Payment order status change */
2018
+ PAYMENT_NOTIFICATION = "PAYMENT_NOTIFICATION",
2019
+ /** Refund status change */
2020
+ REFUND_NOTIFICATION = "REFUND_NOTIFICATION",
2021
+ /** Subscription status change */
2022
+ SUBSCRIPTION_STATUS_NOTIFICATION = "SUBSCRIPTION_STATUS_NOTIFICATION"
2023
+ }
2024
+ /**
2025
+ * Merchant webhook response status.
2026
+ *
2027
+ * - **SUCCESS**: Waffo stops retrying
2028
+ * - **FAILED/UNKNOWN**: Waffo retries within 24 hours
2029
+ *
2030
+ * @enum {string}
2031
+ * @readonly
2032
+ *
2033
+ * @example
2034
+ * // Return SUCCESS to acknowledge receipt
2035
+ * const response = buildWebhookResponse(WebhookResponseStatus.SUCCESS, privateKey);
2036
+ *
2037
+ * // Return FAILED to request retry
2038
+ * const response = buildWebhookResponse(WebhookResponseStatus.FAILED, privateKey);
2039
+ */
2040
+ declare enum WebhookResponseStatus {
2041
+ /** Successfully processed, no retry needed */
2042
+ SUCCESS = "success",
2043
+ /** Processing failed, Waffo will retry */
2044
+ FAILED = "failed",
2045
+ /** Unknown status, Waffo will retry */
2046
+ UNKNOWN = "unknown"
2047
+ }
2048
+ /**
2049
+ * Webhook request headers from Waffo.
2050
+ * @interface WebhookRequestHeader
2051
+ */
2052
+ interface WebhookRequestHeader {
2053
+ /** RSA-SHA256 signature for verification */
2054
+ "X-SIGNATURE": string;
2055
+ /** Optional MIME type */
2056
+ "Content-Type"?: string;
2057
+ }
2058
+ /**
2059
+ * Webhook response headers to send back to Waffo.
2060
+ * @type WebhookResponseHeader
2061
+ */
2062
+ type WebhookResponseHeader = SignatureHeader;
2063
+ /**
2064
+ * Webhook response body to send back to Waffo.
2065
+ * @interface WebhookResponseBody
2066
+ */
2067
+ interface WebhookResponseBody {
2068
+ /** Response status message */
2069
+ message: WebhookResponseStatus | string;
2070
+ }
2071
+ /**
2072
+ * Complete webhook response structure.
2073
+ *
2074
+ * @interface WebhookResponse
2075
+ *
2076
+ * @example
2077
+ * const response: WebhookResponse = buildSuccessResponse(privateKey);
2078
+ * res.set(response.header).json(response.body);
2079
+ */
2080
+ interface WebhookResponse {
2081
+ /** Response headers (includes X-SIGNATURE) */
2082
+ header: WebhookResponseHeader;
2083
+ /** Response body (includes status message) */
2084
+ body: WebhookResponseBody;
2085
+ }
2086
+ /**
2087
+ * Context passed to webhook handlers.
2088
+ *
2089
+ * @interface WebhookHandlerContext
2090
+ * @template T - The notification type
2091
+ *
2092
+ * @example
2093
+ * const handler: PaymentNotificationHandler = async (ctx) => {
2094
+ * console.log('Event type:', ctx.eventType);
2095
+ * console.log('Raw body:', ctx.rawBody);
2096
+ * console.log('Order status:', ctx.notification.result.orderStatus);
2097
+ * };
2098
+ */
2099
+ interface WebhookHandlerContext<T> {
2100
+ /** Parsed notification payload */
2101
+ notification: T;
2102
+ /** Original raw request body (for logging/debugging) */
2103
+ rawBody: string;
2104
+ /** Webhook event type */
2105
+ eventType: WebhookEventType;
2106
+ }
2107
+ /**
2108
+ * Handler for payment notifications.
2109
+ * @param context - Context with PaymentNotification
2110
+ */
2111
+ type PaymentNotificationHandler = (context: WebhookHandlerContext<PaymentNotification>) => void | Promise<void>;
2112
+ /**
2113
+ * Handler for refund notifications.
2114
+ * @param context - Context with RefundNotification
2115
+ */
2116
+ type RefundNotificationHandler = (context: WebhookHandlerContext<RefundNotification>) => void | Promise<void>;
2117
+ /**
2118
+ * Handler for subscription status notifications.
2119
+ * @param context - Context with SubscriptionStatusNotification
2120
+ */
2121
+ type SubscriptionStatusNotificationHandler = (context: WebhookHandlerContext<SubscriptionStatusNotification>) => void | Promise<void>;
2122
+ /**
2123
+ * Handler for subscription payment notifications.
2124
+ * @param context - Context with SubscriptionPaymentNotification
2125
+ */
2126
+ type SubscriptionPaymentNotificationHandler = (context: WebhookHandlerContext<SubscriptionPaymentNotification>) => void | Promise<void>;
2127
+ /**
2128
+ * Handler for webhook processing errors.
2129
+ * @param error - The error that occurred
2130
+ */
2131
+ type WebhookErrorHandler = (error: Error) => void | Promise<void>;
2132
+ /**
2133
+ * Options for configuring webhook handlers.
2134
+ *
2135
+ * @interface WebhookHandlerOptions
2136
+ *
2137
+ * @example
2138
+ * const options: WebhookHandlerOptions = {
2139
+ * onPayment: async (ctx) => {
2140
+ * await updateOrder(ctx.notification.result);
2141
+ * },
2142
+ * onRefund: async (ctx) => {
2143
+ * await processRefund(ctx.notification.result);
2144
+ * },
2145
+ * onSubscriptionStatus: async (ctx) => {
2146
+ * await updateSubscription(ctx.notification.result);
2147
+ * },
2148
+ * onSubscriptionPayment: async (ctx) => {
2149
+ * await recordPayment(ctx.notification.result);
2150
+ * },
2151
+ * onError: async (error) => {
2152
+ * console.error('Webhook error:', error);
2153
+ * },
2154
+ * };
2155
+ */
2156
+ interface WebhookHandlerOptions {
2157
+ /** Handler for payment notifications */
2158
+ onPayment?: PaymentNotificationHandler;
2159
+ /** Handler for refund notifications */
2160
+ onRefund?: RefundNotificationHandler;
2161
+ /** Handler for subscription status changes */
2162
+ onSubscriptionStatus?: SubscriptionStatusNotificationHandler;
2163
+ /** Handler for subscription recurring payments */
2164
+ onSubscriptionPayment?: SubscriptionPaymentNotificationHandler;
2165
+ /** Handler for processing errors */
2166
+ onError?: WebhookErrorHandler;
2167
+ }
2168
+ /**
2169
+ * Result from webhook handler.
2170
+ *
2171
+ * @interface WebhookHandlerResult
2172
+ *
2173
+ * @example
2174
+ * const result = await waffo.webhook.handle(body, signature, options);
2175
+ * if (result.success) {
2176
+ * res.set(result.response.header).json(result.response.body);
2177
+ * } else {
2178
+ * console.error('Webhook failed:', result.error);
2179
+ * res.set(result.response.header).json(result.response.body);
2180
+ * }
2181
+ */
2182
+ interface WebhookHandlerResult {
2183
+ /** Whether processing was successful */
2184
+ success: boolean;
2185
+ /** Signed response to send back to Waffo */
2186
+ response: WebhookResponse;
2187
+ /** Error message (only on failure) */
2188
+ error?: string;
2189
+ }
2190
+
2191
+ /**
2192
+ * @fileoverview Cryptographic Type Definitions
2193
+ * @module types/crypto
2194
+ *
2195
+ * RSA key pair and related cryptographic types for API request signing
2196
+ * and response verification.
2197
+ *
2198
+ * @see {@link Waffo.generateKeyPair} for generating key pairs
2199
+ * @see {@link signForRSA} for signing requests
2200
+ * @see {@link verify} for verifying signatures
2201
+ *
2202
+ * @example
2203
+ * import { KeyPair } from 'waffo-sdk';
2204
+ *
2205
+ * const keys: KeyPair = Waffo.generateKeyPair();
2206
+ * console.log('Private key:', keys.privateKey);
2207
+ * console.log('Public key:', keys.publicKey);
2208
+ */
2209
+ /**
2210
+ * RSA key pair for signing and verification.
2211
+ *
2212
+ * Keys are in the format required by the Waffo API:
2213
+ * - Private key: Base64 encoded PKCS8 DER format
2214
+ * - Public key: Base64 encoded X509/SPKI DER format
2215
+ *
2216
+ * @interface KeyPair
2217
+ *
2218
+ * @example
2219
+ * const keys = Waffo.generateKeyPair();
2220
+ *
2221
+ * // Use private key with SDK
2222
+ * const waffo = new Waffo({
2223
+ * apiKey: 'key',
2224
+ * privateKey: keys.privateKey,
2225
+ * });
2226
+ *
2227
+ * // Register public key with Waffo merchant dashboard
2228
+ * console.log('Register this with Waffo:', keys.publicKey);
2229
+ */
2230
+ interface KeyPair {
2231
+ /** RSA private key (Base64 encoded PKCS8 DER), for signing requests */
2232
+ privateKey: string;
2233
+ /** RSA public key (Base64 encoded X509/SPKI DER), register with Waffo */
2234
+ publicKey: string;
2235
+ }
2236
+
2237
+ /**
2238
+ * @fileoverview ISO Standard Code Definitions
2239
+ * @module types/iso
2240
+ *
2241
+ * @description
2242
+ * This module contains ISO standard codes used throughout the SDK:
2243
+ *
2244
+ * - **{@link CountryCode}** - ISO 3166-1 alpha-3 country codes (e.g., USA, JPN, CHN)
2245
+ * - **{@link CurrencyCode}** - ISO 4217 currency codes (e.g., USD, JPY, EUR)
2246
+ *
2247
+ * These codes ensure international compatibility and standardization
2248
+ * for order creation, address information, and payment processing.
2249
+ *
2250
+ * @example
2251
+ * // Using country codes for user address
2252
+ * import { CountryCode, CurrencyCode } from 'waffo-sdk-nodejs';
2253
+ *
2254
+ * const orderParams = {
2255
+ * orderAmount: '1000',
2256
+ * orderCurrency: CurrencyCode.JPY,
2257
+ * userInfo: {
2258
+ * userCountry: CountryCode.JPN,
2259
+ * },
2260
+ * addressInfo: {
2261
+ * country: CountryCode.JPN,
2262
+ * city: 'Tokyo',
2263
+ * },
2264
+ * };
2265
+ *
2266
+ * @example
2267
+ * // Multi-currency support
2268
+ * const supportedCurrencies = [
2269
+ * CurrencyCode.USD,
2270
+ * CurrencyCode.EUR,
2271
+ * CurrencyCode.JPY,
2272
+ * CurrencyCode.GBP,
2273
+ * ];
2274
+ *
2275
+ * @see {@link CreateOrderParams} for order creation parameters
2276
+ * @see {@link AddressInfo} for address information structure
2277
+ */
2278
+ /**
2279
+ * ISO 3166-1 alpha-3 country codes.
2280
+ *
2281
+ * @description
2282
+ * Three-letter country codes following the ISO 3166-1 standard.
2283
+ * Use these codes for specifying user country and address information
2284
+ * in order creation and payment processing.
2285
+ *
2286
+ * Common codes:
2287
+ * - `USA` - United States of America
2288
+ * - `JPN` - Japan
2289
+ * - `CHN` - China
2290
+ * - `GBR` - United Kingdom
2291
+ * - `DEU` - Germany
2292
+ *
2293
+ * @example
2294
+ * // Specify user's country
2295
+ * const userInfo = {
2296
+ * userCountry: CountryCode.JPN,
2297
+ * userName: 'Taro Yamada',
2298
+ * };
2299
+ *
2300
+ * @example
2301
+ * // Specify shipping address country
2302
+ * const addressInfo = {
2303
+ * country: CountryCode.USA,
2304
+ * state: 'CA',
2305
+ * city: 'San Francisco',
2306
+ * address1: '123 Main St',
2307
+ * zipCode: '94102',
2308
+ * };
2309
+ *
2310
+ * @enum {string}
2311
+ * @readonly
2312
+ * @see https://www.iso.org/iso-3166-country-codes.html
2313
+ */
2314
+ declare enum CountryCode {
2315
+ AFG = "AFG",// Afghanistan
2316
+ ALB = "ALB",// Albania
2317
+ DZA = "DZA",// Algeria
2318
+ ASM = "ASM",// American Samoa
2319
+ AND = "AND",// Andorra
2320
+ AGO = "AGO",// Angola
2321
+ AIA = "AIA",// Anguilla
2322
+ ATA = "ATA",// Antarctica
2323
+ ATG = "ATG",// Antigua and Barbuda
2324
+ ARG = "ARG",// Argentina
2325
+ ARM = "ARM",// Armenia
2326
+ ABW = "ABW",// Aruba
2327
+ AUS = "AUS",// Australia
2328
+ AUT = "AUT",// Austria
2329
+ AZE = "AZE",// Azerbaijan
2330
+ BHS = "BHS",// Bahamas
2331
+ BHR = "BHR",// Bahrain
2332
+ BGD = "BGD",// Bangladesh
2333
+ BRB = "BRB",// Barbados
2334
+ BLR = "BLR",// Belarus
2335
+ BEL = "BEL",// Belgium
2336
+ BLZ = "BLZ",// Belize
2337
+ BEN = "BEN",// Benin
2338
+ BMU = "BMU",// Bermuda
2339
+ BTN = "BTN",// Bhutan
2340
+ BOL = "BOL",// Bolivia
2341
+ BES = "BES",// Bonaire, Sint Eustatius and Saba
2342
+ BIH = "BIH",// Bosnia and Herzegovina
2343
+ BWA = "BWA",// Botswana
2344
+ BVT = "BVT",// Bouvet Island
2345
+ BRA = "BRA",// Brazil
2346
+ IOT = "IOT",// British Indian Ocean Territory
2347
+ BRN = "BRN",// Brunei Darussalam
2348
+ BGR = "BGR",// Bulgaria
2349
+ BFA = "BFA",// Burkina Faso
2350
+ BDI = "BDI",// Burundi
2351
+ CPV = "CPV",// Cabo Verde
2352
+ KHM = "KHM",// Cambodia
2353
+ CMR = "CMR",// Cameroon
2354
+ CAN = "CAN",// Canada
2355
+ CYM = "CYM",// Cayman Islands
2356
+ CAF = "CAF",// Central African Republic
2357
+ TCD = "TCD",// Chad
2358
+ CHL = "CHL",// Chile
2359
+ CHN = "CHN",// China
2360
+ CXR = "CXR",// Christmas Island
2361
+ CCK = "CCK",// Cocos (Keeling) Islands
2362
+ COL = "COL",// Colombia
2363
+ COM = "COM",// Comoros
2364
+ COD = "COD",// Congo (Democratic Republic)
2365
+ COG = "COG",// Congo
2366
+ COK = "COK",// Cook Islands
2367
+ CRI = "CRI",// Costa Rica
2368
+ HRV = "HRV",// Croatia
2369
+ CUB = "CUB",// Cuba
2370
+ CUW = "CUW",// Curaçao
2371
+ CYP = "CYP",// Cyprus
2372
+ CZE = "CZE",// Czechia
2373
+ CIV = "CIV",// Côte d'Ivoire
2374
+ DNK = "DNK",// Denmark
2375
+ DJI = "DJI",// Djibouti
2376
+ DMA = "DMA",// Dominica
2377
+ DOM = "DOM",// Dominican Republic
2378
+ ECU = "ECU",// Ecuador
2379
+ EGY = "EGY",// Egypt
2380
+ SLV = "SLV",// El Salvador
2381
+ GNQ = "GNQ",// Equatorial Guinea
2382
+ ERI = "ERI",// Eritrea
2383
+ EST = "EST",// Estonia
2384
+ SWZ = "SWZ",// Eswatini
2385
+ ETH = "ETH",// Ethiopia
2386
+ FLK = "FLK",// Falkland Islands
2387
+ FRO = "FRO",// Faroe Islands
2388
+ FJI = "FJI",// Fiji
2389
+ FIN = "FIN",// Finland
2390
+ FRA = "FRA",// France
2391
+ GUF = "GUF",// French Guiana
2392
+ PYF = "PYF",// French Polynesia
2393
+ ATF = "ATF",// French Southern Territories
2394
+ GAB = "GAB",// Gabon
2395
+ GMB = "GMB",// Gambia
2396
+ GEO = "GEO",// Georgia
2397
+ DEU = "DEU",// Germany
2398
+ GHA = "GHA",// Ghana
2399
+ GIB = "GIB",// Gibraltar
2400
+ GRC = "GRC",// Greece
2401
+ GRL = "GRL",// Greenland
2402
+ GRD = "GRD",// Grenada
2403
+ GLP = "GLP",// Guadeloupe
2404
+ GUM = "GUM",// Guam
2405
+ GTM = "GTM",// Guatemala
2406
+ GGY = "GGY",// Guernsey
2407
+ GIN = "GIN",// Guinea
2408
+ GNB = "GNB",// Guinea-Bissau
2409
+ GUY = "GUY",// Guyana
2410
+ HTI = "HTI",// Haiti
2411
+ HMD = "HMD",// Heard Island and McDonald Islands
2412
+ VAT = "VAT",// Holy See
2413
+ HND = "HND",// Honduras
2414
+ HKG = "HKG",// Hong Kong
2415
+ HUN = "HUN",// Hungary
2416
+ ISL = "ISL",// Iceland
2417
+ IND = "IND",// India
2418
+ IDN = "IDN",// Indonesia
2419
+ IRN = "IRN",// Iran
2420
+ IRQ = "IRQ",// Iraq
2421
+ IRL = "IRL",// Ireland
2422
+ IMN = "IMN",// Isle of Man
2423
+ ISR = "ISR",// Israel
2424
+ ITA = "ITA",// Italy
2425
+ JAM = "JAM",// Jamaica
2426
+ JPN = "JPN",// Japan
2427
+ JEY = "JEY",// Jersey
2428
+ JOR = "JOR",// Jordan
2429
+ KAZ = "KAZ",// Kazakhstan
2430
+ KEN = "KEN",// Kenya
2431
+ KIR = "KIR",// Kiribati
2432
+ PRK = "PRK",// Korea (Democratic People's Republic)
2433
+ KOR = "KOR",// Korea (Republic)
2434
+ KWT = "KWT",// Kuwait
2435
+ KGZ = "KGZ",// Kyrgyzstan
2436
+ LAO = "LAO",// Lao People's Democratic Republic
2437
+ LVA = "LVA",// Latvia
2438
+ LBN = "LBN",// Lebanon
2439
+ LSO = "LSO",// Lesotho
2440
+ LBR = "LBR",// Liberia
2441
+ LBY = "LBY",// Libya
2442
+ LIE = "LIE",// Liechtenstein
2443
+ LTU = "LTU",// Lithuania
2444
+ LUX = "LUX",// Luxembourg
2445
+ MAC = "MAC",// Macao
2446
+ MDG = "MDG",// Madagascar
2447
+ MWI = "MWI",// Malawi
2448
+ MYS = "MYS",// Malaysia
2449
+ MDV = "MDV",// Maldives
2450
+ MLI = "MLI",// Mali
2451
+ MLT = "MLT",// Malta
2452
+ MHL = "MHL",// Marshall Islands
2453
+ MTQ = "MTQ",// Martinique
2454
+ MRT = "MRT",// Mauritania
2455
+ MUS = "MUS",// Mauritius
2456
+ MYT = "MYT",// Mayotte
2457
+ MEX = "MEX",// Mexico
2458
+ FSM = "FSM",// Micronesia
2459
+ MDA = "MDA",// Moldova
2460
+ MCO = "MCO",// Monaco
2461
+ MNG = "MNG",// Mongolia
2462
+ MNE = "MNE",// Montenegro
2463
+ MSR = "MSR",// Montserrat
2464
+ MAR = "MAR",// Morocco
2465
+ MOZ = "MOZ",// Mozambique
2466
+ MMR = "MMR",// Myanmar
2467
+ NAM = "NAM",// Namibia
2468
+ NRU = "NRU",// Nauru
2469
+ NPL = "NPL",// Nepal
2470
+ NLD = "NLD",// Netherlands
2471
+ NCL = "NCL",// New Caledonia
2472
+ NZL = "NZL",// New Zealand
2473
+ NIC = "NIC",// Nicaragua
2474
+ NER = "NER",// Niger
2475
+ NGA = "NGA",// Nigeria
2476
+ NIU = "NIU",// Niue
2477
+ NFK = "NFK",// Norfolk Island
2478
+ MKD = "MKD",// North Macedonia
2479
+ MNP = "MNP",// Northern Mariana Islands
2480
+ NOR = "NOR",// Norway
2481
+ OMN = "OMN",// Oman
2482
+ PAK = "PAK",// Pakistan
2483
+ PLW = "PLW",// Palau
2484
+ PSE = "PSE",// Palestine
2485
+ PAN = "PAN",// Panama
2486
+ PNG = "PNG",// Papua New Guinea
2487
+ PRY = "PRY",// Paraguay
2488
+ PER = "PER",// Peru
2489
+ PHL = "PHL",// Philippines
2490
+ PCN = "PCN",// Pitcairn
2491
+ POL = "POL",// Poland
2492
+ PRT = "PRT",// Portugal
2493
+ PRI = "PRI",// Puerto Rico
2494
+ QAT = "QAT",// Qatar
2495
+ ROU = "ROU",// Romania
2496
+ RUS = "RUS",// Russian Federation
2497
+ RWA = "RWA",// Rwanda
2498
+ REU = "REU",// Réunion
2499
+ BLM = "BLM",// Saint Barthélemy
2500
+ SHN = "SHN",// Saint Helena, Ascension and Tristan da Cunha
2501
+ KNA = "KNA",// Saint Kitts and Nevis
2502
+ LCA = "LCA",// Saint Lucia
2503
+ MAF = "MAF",// Saint Martin (French part)
2504
+ SPM = "SPM",// Saint Pierre and Miquelon
2505
+ VCT = "VCT",// Saint Vincent and the Grenadines
2506
+ WSM = "WSM",// Samoa
2507
+ SMR = "SMR",// San Marino
2508
+ STP = "STP",// Sao Tome and Principe
2509
+ SAU = "SAU",// Saudi Arabia
2510
+ SEN = "SEN",// Senegal
2511
+ SRB = "SRB",// Serbia
2512
+ SYC = "SYC",// Seychelles
2513
+ SLE = "SLE",// Sierra Leone
2514
+ SGP = "SGP",// Singapore
2515
+ SXM = "SXM",// Sint Maarten (Dutch part)
2516
+ SVK = "SVK",// Slovakia
2517
+ SVN = "SVN",// Slovenia
2518
+ SLB = "SLB",// Solomon Islands
2519
+ SOM = "SOM",// Somalia
2520
+ ZAF = "ZAF",// South Africa
2521
+ SGS = "SGS",// South Georgia and the South Sandwich Islands
2522
+ SSD = "SSD",// South Sudan
2523
+ ESP = "ESP",// Spain
2524
+ LKA = "LKA",// Sri Lanka
2525
+ SDN = "SDN",// Sudan
2526
+ SUR = "SUR",// Suriname
2527
+ SJM = "SJM",// Svalbard and Jan Mayen
2528
+ SWE = "SWE",// Sweden
2529
+ CHE = "CHE",// Switzerland
2530
+ SYR = "SYR",// Syrian Arab Republic
2531
+ TWN = "TWN",// Taiwan
2532
+ TJK = "TJK",// Tajikistan
2533
+ TZA = "TZA",// Tanzania
2534
+ THA = "THA",// Thailand
2535
+ TLS = "TLS",// Timor-Leste
2536
+ TGO = "TGO",// Togo
2537
+ TKL = "TKL",// Tokelau
2538
+ TON = "TON",// Tonga
2539
+ TTO = "TTO",// Trinidad and Tobago
2540
+ TUN = "TUN",// Tunisia
2541
+ TUR = "TUR",// Turkey
2542
+ TKM = "TKM",// Turkmenistan
2543
+ TCA = "TCA",// Turks and Caicos Islands
2544
+ TUV = "TUV",// Tuvalu
2545
+ UGA = "UGA",// Uganda
2546
+ UKR = "UKR",// Ukraine
2547
+ ARE = "ARE",// United Arab Emirates
2548
+ GBR = "GBR",// United Kingdom
2549
+ UMI = "UMI",// United States Minor Outlying Islands
2550
+ USA = "USA",// United States of America
2551
+ URY = "URY",// Uruguay
2552
+ UZB = "UZB",// Uzbekistan
2553
+ VUT = "VUT",// Vanuatu
2554
+ VEN = "VEN",// Venezuela
2555
+ VNM = "VNM",// Viet Nam
2556
+ VGB = "VGB",// Virgin Islands (British)
2557
+ VIR = "VIR",// Virgin Islands (U.S.)
2558
+ WLF = "WLF",// Wallis and Futuna
2559
+ ESH = "ESH",// Western Sahara
2560
+ YEM = "YEM",// Yemen
2561
+ ZMB = "ZMB",// Zambia
2562
+ ZWE = "ZWE",// Zimbabwe
2563
+ ALA = "ALA"
2564
+ }
2565
+ /**
2566
+ * ISO 4217 currency codes.
2567
+ *
2568
+ * @description
2569
+ * Three-letter currency codes following the ISO 4217 standard.
2570
+ * Use these codes for specifying order amounts and payment currencies.
2571
+ *
2572
+ * Common codes:
2573
+ * - `USD` - United States Dollar
2574
+ * - `EUR` - Euro
2575
+ * - `JPY` - Japanese Yen
2576
+ * - `GBP` - Pound Sterling
2577
+ * - `CNY` - Chinese Yuan
2578
+ *
2579
+ * Note: Currency codes determine the decimal precision for amounts.
2580
+ * For example, JPY has no decimal places, while USD has 2.
2581
+ *
2582
+ * @example
2583
+ * // Create an order with Japanese Yen
2584
+ * const orderParams = {
2585
+ * orderAmount: '1000', // 1000 JPY (no decimals)
2586
+ * orderCurrency: CurrencyCode.JPY,
2587
+ * };
2588
+ *
2589
+ * @example
2590
+ * // Create an order with US Dollars
2591
+ * const orderParams = {
2592
+ * orderAmount: '19.99', // $19.99
2593
+ * orderCurrency: CurrencyCode.USD,
2594
+ * };
2595
+ *
2596
+ * @example
2597
+ * // Validate supported currencies
2598
+ * function isSupportedCurrency(code: string): code is CurrencyCode {
2599
+ * return Object.values(CurrencyCode).includes(code as CurrencyCode);
2600
+ * }
2601
+ *
2602
+ * @enum {string}
2603
+ * @readonly
2604
+ * @see https://www.iso.org/iso-4217-currency-codes.html
2605
+ */
2606
+ declare enum CurrencyCode {
2607
+ AED = "AED",// United Arab Emirates Dirham
2608
+ AFN = "AFN",// Afghan Afghani
2609
+ ALL = "ALL",// Albanian Lek
2610
+ AMD = "AMD",// Armenian Dram
2611
+ ANG = "ANG",// Netherlands Antillean Guilder
2612
+ AOA = "AOA",// Angolan Kwanza
2613
+ ARS = "ARS",// Argentine Peso
2614
+ AUD = "AUD",// Australian Dollar
2615
+ AWG = "AWG",// Aruban Florin
2616
+ AZN = "AZN",// Azerbaijani Manat
2617
+ BAM = "BAM",// Bosnia and Herzegovina Convertible Mark
2618
+ BBD = "BBD",// Barbados Dollar
2619
+ BDT = "BDT",// Bangladeshi Taka
2620
+ BGN = "BGN",// Bulgarian Lev
2621
+ BHD = "BHD",// Bahraini Dinar
2622
+ BIF = "BIF",// Burundian Franc
2623
+ BMD = "BMD",// Bermudian Dollar
2624
+ BND = "BND",// Brunei Dollar
2625
+ BOB = "BOB",// Boliviano
2626
+ BOV = "BOV",// Bolivian Mvdol
2627
+ BRL = "BRL",// Brazilian Real
2628
+ BSD = "BSD",// Bahamian Dollar
2629
+ BTN = "BTN",// Bhutanese Ngultrum
2630
+ BWP = "BWP",// Botswana Pula
2631
+ BYN = "BYN",// Belarusian Ruble
2632
+ BZD = "BZD",// Belize Dollar
2633
+ CAD = "CAD",// Canadian Dollar
2634
+ CDF = "CDF",// Congolese Franc
2635
+ CHE = "CHE",// WIR Euro
2636
+ CHF = "CHF",// Swiss Franc
2637
+ CHW = "CHW",// WIR Franc
2638
+ CLF = "CLF",// Unidad de Fomento
2639
+ CLP = "CLP",// Chilean Peso
2640
+ CNY = "CNY",// Chinese Yuan
2641
+ COP = "COP",// Colombian Peso
2642
+ COU = "COU",// Unidad de Valor Real
2643
+ CRC = "CRC",// Costa Rican Colon
2644
+ CUC = "CUC",// Cuban Convertible Peso
2645
+ CUP = "CUP",// Cuban Peso
2646
+ CVE = "CVE",// Cape Verdean Escudo
2647
+ CZK = "CZK",// Czech Koruna
2648
+ DJF = "DJF",// Djiboutian Franc
2649
+ DKK = "DKK",// Danish Krone
2650
+ DOP = "DOP",// Dominican Peso
2651
+ DZD = "DZD",// Algerian Dinar
2652
+ EGP = "EGP",// Egyptian Pound
2653
+ ERN = "ERN",// Eritrean Nakfa
2654
+ ETB = "ETB",// Ethiopian Birr
2655
+ EUR = "EUR",// Euro
2656
+ FJD = "FJD",// Fiji Dollar
2657
+ FKP = "FKP",// Falkland Islands Pound
2658
+ GBP = "GBP",// Pound Sterling
2659
+ GEL = "GEL",// Georgian Lari
2660
+ GHS = "GHS",// Ghanaian Cedi
2661
+ GIP = "GIP",// Gibraltar Pound
2662
+ GMD = "GMD",// Gambian Dalasi
2663
+ GNF = "GNF",// Guinean Franc
2664
+ GTQ = "GTQ",// Guatemalan Quetzal
2665
+ GYD = "GYD",// Guyanese Dollar
2666
+ HKD = "HKD",// Hong Kong Dollar
2667
+ HNL = "HNL",// Honduran Lempira
2668
+ HRK = "HRK",// Croatian Kuna
2669
+ HTG = "HTG",// Haitian Gourde
2670
+ HUF = "HUF",// Hungarian Forint
2671
+ IDR = "IDR",// Indonesian Rupiah
2672
+ ILS = "ILS",// Israeli New Shekel
2673
+ INR = "INR",// Indian Rupee
2674
+ IQD = "IQD",// Iraqi Dinar
2675
+ IRR = "IRR",// Iranian Rial
2676
+ ISK = "ISK",// Icelandic Króna
2677
+ JMD = "JMD",// Jamaican Dollar
2678
+ JOD = "JOD",// Jordanian Dinar
2679
+ JPY = "JPY",// Japanese Yen
2680
+ KES = "KES",// Kenyan Shilling
2681
+ KGS = "KGS",// Kyrgyzstani Som
2682
+ KHR = "KHR",// Cambodian Riel
2683
+ KMF = "KMF",// Comoro Franc
2684
+ KPW = "KPW",// North Korean Won
2685
+ KRW = "KRW",// South Korean Won
2686
+ KWD = "KWD",// Kuwaiti Dinar
2687
+ KYD = "KYD",// Cayman Islands Dollar
2688
+ KZT = "KZT",// Kazakhstani Tenge
2689
+ LAK = "LAK",// Lao Kip
2690
+ LBP = "LBP",// Lebanese Pound
2691
+ LKR = "LKR",// Sri Lankan Rupee
2692
+ LRD = "LRD",// Liberian Dollar
2693
+ LSL = "LSL",// Lesotho Loti
2694
+ LYD = "LYD",// Libyan Dinar
2695
+ MAD = "MAD",// Moroccan Dirham
2696
+ MDL = "MDL",// Moldovan Leu
2697
+ MGA = "MGA",// Malagasy Ariary
2698
+ MKD = "MKD",// Macedonian Denar
2699
+ MMK = "MMK",// Myanmar Kyat
2700
+ MNT = "MNT",// Mongolian Tögrög
2701
+ MOP = "MOP",// Macanese Pataca
2702
+ MRU = "MRU",// Mauritanian Ouguiya
2703
+ MUR = "MUR",// Mauritian Rupee
2704
+ MVR = "MVR",// Maldivian Rufiyaa
2705
+ MWK = "MWK",// Malawian Kwacha
2706
+ MXN = "MXN",// Mexican Peso
2707
+ MXV = "MXV",// Mexican Unidad de Inversion
2708
+ MYR = "MYR",// Malaysian Ringgit
2709
+ MZN = "MZN",// Mozambican Metical
2710
+ NAD = "NAD",// Namibian Dollar
2711
+ NGN = "NGN",// Nigerian Naira
2712
+ NIO = "NIO",// Nicaraguan Córdoba
2713
+ NOK = "NOK",// Norwegian Krone
2714
+ NPR = "NPR",// Nepalese Rupee
2715
+ NZD = "NZD",// New Zealand Dollar
2716
+ OMR = "OMR",// Omani Rial
2717
+ PAB = "PAB",// Panamanian Balboa
2718
+ PEN = "PEN",// Peruvian Sol
2719
+ PGK = "PGK",// Papua New Guinean Kina
2720
+ PHP = "PHP",// Philippine Peso
2721
+ PKR = "PKR",// Pakistani Rupee
2722
+ PLN = "PLN",// Polish Zloty
2723
+ PYG = "PYG",// Paraguayan Guarani
2724
+ QAR = "QAR",// Qatari Riyal
2725
+ RON = "RON",// Romanian Leu
2726
+ RSD = "RSD",// Serbian Dinar
2727
+ RUB = "RUB",// Russian Ruble
2728
+ RWF = "RWF",// Rwandan Franc
2729
+ SAR = "SAR",// Saudi Riyal
2730
+ SBD = "SBD",// Solomon Islands Dollar
2731
+ SCR = "SCR",// Seychelles Rupee
2732
+ SDG = "SDG",// Sudanese Pound
2733
+ SEK = "SEK",// Swedish Krona
2734
+ SGD = "SGD",// Singapore Dollar
2735
+ SHP = "SHP",// Saint Helena Pound
2736
+ SLE = "SLE",// Sierra Leonean Leone
2737
+ SLL = "SLL",// Sierra Leonean Leone (old)
2738
+ SOS = "SOS",// Somali Shilling
2739
+ SRD = "SRD",// Surinamese Dollar
2740
+ SSP = "SSP",// South Sudanese Pound
2741
+ STN = "STN",// São Tomé and Príncipe Dobra
2742
+ SVC = "SVC",// Salvadoran Colón
2743
+ SYP = "SYP",// Syrian Pound
2744
+ SZL = "SZL",// Swazi Lilangeni
2745
+ THB = "THB",// Thai Baht
2746
+ TJS = "TJS",// Tajikistani Somoni
2747
+ TMT = "TMT",// Turkmenistan Manat
2748
+ TND = "TND",// Tunisian Dinar
2749
+ TOP = "TOP",// Tongan Paʻanga
2750
+ TRY = "TRY",// Turkish Lira
2751
+ TTD = "TTD",// Trinidad and Tobago Dollar
2752
+ TWD = "TWD",// New Taiwan Dollar
2753
+ TZS = "TZS",// Tanzanian Shilling
2754
+ UAH = "UAH",// Ukrainian Hryvnia
2755
+ UGX = "UGX",// Ugandan Shilling
2756
+ USD = "USD",// United States Dollar
2757
+ USN = "USN",// United States Dollar (Next day)
2758
+ UYI = "UYI",// Uruguay Peso en Unidades Indexadas
2759
+ UYU = "UYU",// Uruguayan Peso
2760
+ UYW = "UYW",// Unidad Previsional
2761
+ UZS = "UZS",// Uzbekistan Som
2762
+ VED = "VED",// Venezuelan Digital Bolívar
2763
+ VES = "VES",// Venezuelan Sovereign Bolívar
2764
+ VND = "VND",// Vietnamese Đồng
2765
+ VUV = "VUV",// Vanuatu Vatu
2766
+ WST = "WST",// Samoan Tala
2767
+ XAF = "XAF",// CFA Franc BEAC
2768
+ XAG = "XAG",// Silver (one troy ounce)
2769
+ XAU = "XAU",// Gold (one troy ounce)
2770
+ XBA = "XBA",// European Composite Unit
2771
+ XBB = "XBB",// European Monetary Unit
2772
+ XBC = "XBC",// European Unit of Account 9
2773
+ XBD = "XBD",// European Unit of Account 17
2774
+ XCD = "XCD",// East Caribbean Dollar
2775
+ XDR = "XDR",// Special Drawing Rights
2776
+ XOF = "XOF",// CFA Franc BCEAO
2777
+ XPD = "XPD",// Palladium (one troy ounce)
2778
+ XPF = "XPF",// CFP Franc
2779
+ XPT = "XPT",// Platinum (one troy ounce)
2780
+ XSU = "XSU",// Sucre
2781
+ XTS = "XTS",// Code reserved for testing
2782
+ XUA = "XUA",// ADB Unit of Account
2783
+ XXX = "XXX",// No currency
2784
+ YER = "YER",// Yemeni Rial
2785
+ ZAR = "ZAR",// South African Rand
2786
+ ZMW = "ZMW",// Zambian Kwacha
2787
+ ZWL = "ZWL"
2788
+ }
2789
+
2790
+ /**
2791
+ * @fileoverview Merchant Config Resource Type Definitions
2792
+ * @module types/merchantconfig
2793
+ *
2794
+ * Type definitions for the Merchant Config resource.
2795
+ *
2796
+ * **Categories:**
2797
+ * - **Request Interfaces:** Parameters for merchant config inquiry
2798
+ * - **Response Interfaces:** Merchant configuration data structures
2799
+ *
2800
+ * @see {@link MerchantConfigResource} for API methods
2801
+ *
2802
+ * @example
2803
+ * import { MerchantConfigInquiryParams, MerchantConfigInquiryData } from 'waffo-sdk';
2804
+ *
2805
+ * const params: MerchantConfigInquiryParams = { merchantId: 'M001' };
2806
+ * const result = await waffo.merchantConfig.inquiry(params);
2807
+ */
2808
+ /**
2809
+ * Merchant Config Inquiry Request Parameters Interface
2810
+ *
2811
+ * @description
2812
+ * Request parameters for calling `waffo.merchantConfig.inquiry()`.
2813
+ *
2814
+ * @interface MerchantConfigInquiryParams
2815
+ */
2816
+ interface MerchantConfigInquiryParams {
2817
+ merchantId: string;
2818
+ }
2819
+ /**
2820
+ * Merchant Config Inquiry Response Data Interface
2821
+ *
2822
+ * @description
2823
+ * Business data returned by `waffo.merchantConfig.inquiry()`.
2824
+ *
2825
+ * @interface MerchantConfigInquiryData
2826
+ */
2827
+ interface MerchantConfigInquiryData {
2828
+ merchantId: string;
2829
+ totalDailyLimit?: Record<string, string> | string;
2830
+ remainingDailyLimit?: Record<string, string> | string;
2831
+ transactionLimit?: Record<string, string> | string;
2832
+ }
2833
+
2834
+ /**
2835
+ * @fileoverview Pay Method Config Resource Type Definitions
2836
+ * @module types/paymethodconfig
2837
+ *
2838
+ * Type definitions for the Pay Method Config resource.
2839
+ *
2840
+ * **Categories:**
2841
+ * - **Request Interfaces:** Parameters for payment method config inquiry
2842
+ * - **Response Interfaces:** Payment method configuration data structures
2843
+ *
2844
+ * @see {@link PayMethodConfigResource} for API methods
2845
+ *
2846
+ * @example
2847
+ * import { PayMethodConfigInquiryParams, PayMethodDetail } from 'waffo-sdk';
2848
+ *
2849
+ * const params: PayMethodConfigInquiryParams = { merchantId: 'M001' };
2850
+ * const result = await waffo.payMethodConfig.inquiry(params);
2851
+ *
2852
+ * const available = result.data.payMethodDetails.filter(m => m.currentStatus === '1');
2853
+ */
2854
+
2855
+ /**
2856
+ * Pay Method Config Inquiry Request Parameters Interface
2857
+ *
2858
+ * @description
2859
+ * Request parameters for calling `waffo.payMethodConfig.inquiry()`.
2860
+ *
2861
+ * @interface PayMethodConfigInquiryParams
2862
+ */
2863
+ interface PayMethodConfigInquiryParams {
2864
+ merchantId: string;
2865
+ }
2866
+ /**
2867
+ * Fixed Maintenance Rule Interface (Response)
2868
+ *
2869
+ * @description
2870
+ * Fixed maintenance periods for payment method.
2871
+ *
2872
+ * @interface FixedMaintenanceRule
2873
+ */
2874
+ interface FixedMaintenanceRule {
2875
+ startRule?: string;
2876
+ endRule?: string;
2877
+ }
2878
+ /**
2879
+ * Pay Method Detail Interface (Response)
2880
+ *
2881
+ * @description
2882
+ * Payment method configuration details.
2883
+ *
2884
+ * @interface PayMethodDetail
2885
+ */
2886
+ interface PayMethodDetail {
2887
+ productName: ProductName | string;
2888
+ payMethodName: string;
2889
+ country: string;
2890
+ currentStatus: "0" | "1";
2891
+ fixedMaintenanceRules?: FixedMaintenanceRule[];
2892
+ fixedMaintenanceTimezone?: string;
2893
+ }
2894
+ /**
2895
+ * Pay Method Config Inquiry Response Data Interface
2896
+ *
2897
+ * @description
2898
+ * Business data returned by `waffo.payMethodConfig.inquiry()`.
2899
+ *
2900
+ * @interface PayMethodConfigInquiryData
2901
+ */
2902
+ interface PayMethodConfigInquiryData {
2903
+ merchantId: string;
2904
+ payMethodDetails: PayMethodDetail[];
2905
+ }
2906
+
2907
+ /**
2908
+ * @fileoverview HTTP Client for Waffo API Communication
2909
+ * @module core/httpClient
2910
+ *
2911
+ * Low-level HTTP client for communicating with the Waffo Payment Platform API.
2912
+ *
2913
+ * **Features:**
2914
+ * - Request signing using RSA-SHA256 algorithm
2915
+ * - Response signature verification for integrity
2916
+ * - Automatic timeout handling with AbortController
2917
+ * - Error handling and response parsing
2918
+ *
2919
+ * This client is used internally by all resource classes but can also be
2920
+ * accessed directly via `waffo.httpClient` for custom API requests.
2921
+ *
2922
+ * @see {@link Waffo} for the main SDK class
2923
+ * @see {@link ApiResponse} for the response format
2924
+ *
2925
+ * @example
2926
+ * // Direct usage through Waffo instance
2927
+ * const result = await waffo.httpClient.post('/custom/endpoint', {
2928
+ * body: { customField: 'value' },
2929
+ * });
2930
+ * if (result.success) {
2931
+ * console.log('Response:', result.data);
2932
+ * }
2933
+ */
2934
+
2935
+ /**
2936
+ * Low-level HTTP client for Waffo API communication.
2937
+ *
2938
+ * Handles all aspects of API communication:
2939
+ * - **Request Signing**: Automatically signs request bodies using RSA-SHA256
2940
+ * - **Response Verification**: Verifies response signatures for data integrity
2941
+ * - **Timeout Handling**: Uses AbortController for reliable timeout management
2942
+ * - **Error Handling**: Parses errors and wraps them in consistent response format
2943
+ *
2944
+ * @class HttpClient
2945
+ * @internal Primarily for internal SDK use
2946
+ *
2947
+ * @example
2948
+ * // Typically accessed through Waffo instance
2949
+ * const result = await waffo.httpClient.post<CustomResponse>('/custom/endpoint', {
2950
+ * body: { field: 'value' },
2951
+ * });
2952
+ *
2953
+ * @see {@link ApiResponse} for the response format
2954
+ * @see {@link RequestOptions} for request configuration
2955
+ */
2956
+ declare class HttpClient {
2957
+ /** @private */
2958
+ private config;
2959
+ /**
2960
+ * Creates an HTTP client instance with the provided SDK configuration.
2961
+ *
2962
+ * Resolves environment-specific settings such as API base URL and public key.
2963
+ *
2964
+ * @param {WaffoConfig} config - Waffo SDK configuration object
2965
+ * @param {string} config.apiKey - API key assigned by Waffo
2966
+ * @param {string} config.privateKey - Merchant private key (Base64 encoded PKCS8 DER)
2967
+ * @param {string} [config.waffoPublicKey] - Waffo public key for response verification
2968
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment
2969
+ * @param {number} [config.timeout=30000] - Request timeout in milliseconds
2970
+ * @param {Logger} [config.logger] - Logger instance for debugging
2971
+ *
2972
+ * @example
2973
+ * const client = new HttpClient({
2974
+ * apiKey: 'your-api-key',
2975
+ * privateKey: 'your-private-key',
2976
+ * environment: Environment.SANDBOX,
2977
+ * });
2978
+ *
2979
+ * @see {@link WaffoConfig} for configuration options
2980
+ */
2981
+ constructor(config: WaffoConfig);
2982
+ /**
2983
+ * Generates an RSA-SHA256 signature for the request body.
2984
+ *
2985
+ * @param {string} payload - Request body string to sign (JSON serialized)
2986
+ * @returns {string} Base64 encoded RSA-SHA256 signature
2987
+ * @throws {Error} "Failed to generate RSA signature" when signing fails
2988
+ * @private
2989
+ */
2990
+ private generateSignature;
2991
+ /**
2992
+ * Verifies the RSA-SHA256 signature of the response body.
2993
+ *
2994
+ * Ensures the response has not been tampered with during transmission.
2995
+ *
2996
+ * @param {string} responseBody - Response body string (raw JSON)
2997
+ * @param {string} signature - X-SIGNATURE header value (Base64 encoded)
2998
+ * @returns {boolean} `true` if signature is valid, `false` otherwise
2999
+ * @private
3000
+ */
3001
+ private verifyResponseSignature;
3002
+ /**
3003
+ * Sends an HTTP POST request with automatic signing and verification.
3004
+ *
3005
+ * **Request Flow:**
3006
+ * 1. Serializes the request body to JSON
3007
+ * 2. Signs the request body using RSA-SHA256
3008
+ * 3. Sends the request with X-API-KEY and X-SIGNATURE headers
3009
+ * 4. Verifies the response signature using Waffo's public key
3010
+ * 5. Parses and returns the response in standardized format
3011
+ *
3012
+ * **Error Handling:**
3013
+ * - Network errors: `{ success: false, error: message }`
3014
+ * - Timeout: status code 408 (REQUEST_TIMEOUT)
3015
+ * - Invalid signature: returns error
3016
+ * - Business errors (code !== "0"): parsed and returned as errors
3017
+ *
3018
+ * @template T - Expected response data type
3019
+ * @template B - Request body type (must extend object)
3020
+ *
3021
+ * @param {string} endpoint - API endpoint path (e.g., '/order/create')
3022
+ * @param {RequestOptions<B>} [options={}] - Request options
3023
+ * @param {B} [options.body] - Request body object (will be JSON serialized)
3024
+ * @param {Record<string, string>} [options.headers] - Additional request headers
3025
+ *
3026
+ * @returns {Promise<ApiResponse<T>>} Response object with success status and data/error
3027
+ *
3028
+ * @example
3029
+ * // Make a POST request
3030
+ * const result = await httpClient.post<CreateOrderData>('/order/create', {
3031
+ * body: {
3032
+ * paymentRequestId: 'req-123',
3033
+ * merchantOrderId: 'order-456',
3034
+ * // ... other fields
3035
+ * },
3036
+ * });
3037
+ *
3038
+ * if (result.success) {
3039
+ * console.log('Order created:', result.data.acquiringOrderId);
3040
+ * } else {
3041
+ * console.error('Error:', result.error);
3042
+ * }
3043
+ *
3044
+ * @example
3045
+ * // Handle timeout errors
3046
+ * const result = await httpClient.post('/order/create', { body: params });
3047
+ * if (!result.success && result.statusCode === HttpStatusCode.REQUEST_TIMEOUT) {
3048
+ * console.log('Request timed out, please retry');
3049
+ * }
3050
+ *
3051
+ * @see {@link ApiResponse} for the response format
3052
+ * @see {@link RequestOptions} for request options
3053
+ */
3054
+ post<T, B extends object = Record<string, unknown>>(endpoint: string, options?: RequestOptions<B>): Promise<ApiResponse<T>>;
3055
+ }
3056
+
3057
+ /**
3058
+ * @fileoverview Webhook Handler for Waffo Webhook Notifications
3059
+ * @module core/webhook
3060
+ *
3061
+ * Provides the WebhookHandler class for processing incoming webhook
3062
+ * notifications from the Waffo Payment Platform.
3063
+ *
3064
+ * **Features:**
3065
+ * - Signature verification using Waffo's public key
3066
+ * - Response signing using merchant's private key
3067
+ * - Event type routing to appropriate handlers
3068
+ * - Error handling and response formatting
3069
+ *
3070
+ * @see {@link Waffo} for the main SDK class
3071
+ * @see {@link WebhookHandlerOptions} for handler configuration
3072
+ *
3073
+ * @example
3074
+ * // Express.js webhook endpoint
3075
+ * app.post('/webhook', async (req, res) => {
3076
+ * const result = await waffo.webhook.handle(
3077
+ * JSON.stringify(req.body),
3078
+ * req.headers['x-signature'],
3079
+ * {
3080
+ * onPayment: async ({ notification }) => {
3081
+ * console.log('Payment:', notification.result.orderStatus);
3082
+ * },
3083
+ * onRefund: async ({ notification }) => {
3084
+ * console.log('Refund:', notification.result.refundStatus);
3085
+ * },
3086
+ * }
3087
+ * );
3088
+ * res.set(result.response.header).json(result.response.body);
3089
+ * });
3090
+ */
3091
+
3092
+ /**
3093
+ * Handles incoming webhook notifications from the Waffo Payment Platform.
3094
+ *
3095
+ * **Features:**
3096
+ * - Signature verification using Waffo's public key
3097
+ * - Event routing to appropriate handlers based on event type
3098
+ * - Response signing using merchant's private key
3099
+ * - Consistent error handling and response formatting
3100
+ *
3101
+ * Accessed via `waffo.webhook` after SDK initialization.
3102
+ *
3103
+ * @class WebhookHandler
3104
+ *
3105
+ * @example
3106
+ * // Handle different notification types
3107
+ * const result = await waffo.webhook.handle(requestBody, signature, {
3108
+ * onPayment: async (ctx) => {
3109
+ * const { orderStatus, acquiringOrderId } = ctx.notification.result;
3110
+ * if (orderStatus === 'PAY_SUCCESS') {
3111
+ * await fulfillOrder(acquiringOrderId);
3112
+ * }
3113
+ * },
3114
+ * onRefund: async (ctx) => {
3115
+ * const { refundStatus, acquiringRefundOrderId } = ctx.notification.result;
3116
+ * await updateRefundStatus(acquiringRefundOrderId, refundStatus);
3117
+ * },
3118
+ * onSubscriptionStatus: async (ctx) => {
3119
+ * const { subscriptionStatus, subscriptionId } = ctx.notification.result;
3120
+ * await updateSubscription(subscriptionId, subscriptionStatus);
3121
+ * },
3122
+ * onError: async (error) => {
3123
+ * console.error('Webhook error:', error.message);
3124
+ * },
3125
+ * });
3126
+ *
3127
+ * @see {@link WebhookHandlerOptions} for handler configuration
3128
+ * @see {@link WebhookHandlerResult} for return type
3129
+ */
3130
+ declare class WebhookHandler {
3131
+ /** @private */
3132
+ private config;
3133
+ /**
3134
+ * Creates a webhook handler instance.
3135
+ *
3136
+ * Initializes the handler with SDK configuration and resolves
3137
+ * environment-specific settings such as Waffo's public key.
3138
+ *
3139
+ * @param {WaffoConfig} config - Waffo SDK configuration object
3140
+ * @param {string} config.privateKey - Merchant private key (Base64 encoded PKCS8 DER)
3141
+ * @param {string} [config.waffoPublicKey] - Waffo public key for request verification
3142
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment
3143
+ *
3144
+ * @example
3145
+ * // Typically created automatically by Waffo SDK
3146
+ * const waffo = new Waffo(config);
3147
+ * // Access via: waffo.webhook
3148
+ *
3149
+ * @see {@link WaffoConfig} for configuration options
3150
+ */
3151
+ constructor(config: WaffoConfig);
3152
+ /**
3153
+ * Processes an incoming webhook notification from Waffo.
3154
+ *
3155
+ * **Processing Flow:**
3156
+ * 1. Verifies the request signature using Waffo's public key
3157
+ * 2. Parses the notification and determines its type
3158
+ * 3. Routes to the appropriate handler based on event type
3159
+ * 4. Returns a signed response to acknowledge receipt
3160
+ *
3161
+ * **Supported Event Types:**
3162
+ * - `PAYMENT_NOTIFICATION` - Payment order status changes
3163
+ * - `REFUND_NOTIFICATION` - Refund status changes
3164
+ * - `SUBSCRIPTION_STATUS_NOTIFICATION` - Subscription status changes
3165
+ * - `PAYMENT_NOTIFICATION` with subscriptionId - Subscription payments
3166
+ *
3167
+ * @param {string} requestBody - Raw request body string (JSON)
3168
+ * @param {string} signature - X-SIGNATURE header value from Waffo
3169
+ * @param {WebhookHandlerOptions} options - Handler configuration options
3170
+ *
3171
+ * @returns {Promise<WebhookHandlerResult>} Result with success status and signed response
3172
+ *
3173
+ * @example
3174
+ * // Express.js endpoint
3175
+ * app.post('/webhook', async (req, res) => {
3176
+ * const result = await waffo.webhook.handle(
3177
+ * JSON.stringify(req.body),
3178
+ * req.headers['x-signature'],
3179
+ * {
3180
+ * onPayment: async ({ notification }) => {
3181
+ * const { orderStatus, acquiringOrderId } = notification.result;
3182
+ * await db.orders.updateStatus(acquiringOrderId, orderStatus);
3183
+ * },
3184
+ * onRefund: async ({ notification }) => {
3185
+ * const { refundStatus } = notification.result;
3186
+ * await db.refunds.update(notification.result);
3187
+ * },
3188
+ * onSubscriptionStatus: async ({ notification }) => {
3189
+ * await db.subscriptions.update(notification.result);
3190
+ * },
3191
+ * onSubscriptionPayment: async ({ notification }) => {
3192
+ * await db.payments.create(notification.result);
3193
+ * },
3194
+ * onError: async (error) => {
3195
+ * logger.error('Webhook error', error);
3196
+ * },
3197
+ * }
3198
+ * );
3199
+ *
3200
+ * // Return signed response to Waffo
3201
+ * res.set(result.response.header).json(result.response.body);
3202
+ * });
3203
+ *
3204
+ * @example
3205
+ * // Next.js API route
3206
+ * export async function POST(request: Request) {
3207
+ * const body = await request.text();
3208
+ * const signature = request.headers.get('x-signature') || '';
3209
+ *
3210
+ * const result = await waffo.webhook.handle(body, signature, {
3211
+ * onPayment: async (ctx) => { ... },
3212
+ * });
3213
+ *
3214
+ * return new Response(JSON.stringify(result.response.body), {
3215
+ * headers: result.response.header,
3216
+ * });
3217
+ * }
3218
+ *
3219
+ * @see {@link WebhookHandlerOptions} for handler configuration
3220
+ * @see {@link WebhookHandlerResult} for return type
3221
+ */
3222
+ handle(requestBody: string, signature: string, options?: WebhookHandlerOptions): Promise<WebhookHandlerResult>;
3223
+ }
3224
+
3225
+ /**
3226
+ * @fileoverview Base Resource Class
3227
+ * @module resources/base
3228
+ *
3229
+ * Abstract base class for all API resource classes.
3230
+ * Defines common structure and dependencies shared by all resources.
3231
+ *
3232
+ * **Resource Inheritance:**
3233
+ * - {@link OrderResource} - Order operations
3234
+ * - {@link RefundResource} - Refund operations
3235
+ * - {@link SubscriptionResource} - Subscription operations
3236
+ * - {@link MerchantConfigResource} - Merchant config operations
3237
+ * - {@link PayMethodConfigResource} - Payment method config operations
3238
+ *
3239
+ * @internal For internal SDK use only
3240
+ */
3241
+
3242
+ /**
3243
+ * Abstract base class for all API resources in the Waffo SDK.
3244
+ *
3245
+ * Provides common foundation for all resource classes:
3246
+ * - HTTP client reference for making API requests
3247
+ * - Base path configuration for API endpoints
3248
+ *
3249
+ * @abstract
3250
+ * @class BaseResource
3251
+ * @internal For internal SDK use only
3252
+ *
3253
+ * @see {@link OrderResource} for order operations
3254
+ * @see {@link RefundResource} for refund operations
3255
+ * @see {@link SubscriptionResource} for subscription operations
3256
+ */
3257
+ declare abstract class BaseResource {
3258
+ /**
3259
+ * HTTP client for making API requests with automatic signing.
3260
+ * @protected
3261
+ */
3262
+ protected client: HttpClient;
3263
+ /**
3264
+ * Base path for API endpoints (e.g., '/order', '/refund').
3265
+ * @protected
3266
+ */
3267
+ protected basePath: string;
3268
+ /**
3269
+ * Initializes the base resource with HTTP client and base path.
3270
+ *
3271
+ * @param {HttpClient} client - HTTP client instance
3272
+ * @param {string} basePath - Base path for API endpoints
3273
+ * @protected
3274
+ */
3275
+ constructor(client: HttpClient, basePath: string);
3276
+ }
3277
+
3278
+ /**
3279
+ * @fileoverview Order Resource Implementation
3280
+ * @module resources/order/resource
3281
+ *
3282
+ * Implements the Order resource class providing all order-related API operations.
3283
+ *
3284
+ * @see {@link OrderResource} for the main class
3285
+ * @see {@link CreateOrderParams} for order creation parameters
3286
+ *
3287
+ * @example
3288
+ * // Access via Waffo instance
3289
+ * const result = await waffo.order.create({
3290
+ * paymentRequestId: 'req-123',
3291
+ * merchantOrderId: 'order-456',
3292
+ * orderCurrency: 'USD',
3293
+ * orderAmount: '10.00',
3294
+ * // ... other required fields
3295
+ * });
3296
+ */
3297
+
3298
+ /**
3299
+ * Order resource for all payment order operations.
3300
+ *
3301
+ * Provides methods for creating, querying, canceling, refunding,
3302
+ * and capturing payment orders.
3303
+ *
3304
+ * @class OrderResource
3305
+ * @extends BaseResource
3306
+ *
3307
+ * @example
3308
+ * // Create an order
3309
+ * const createResult = await waffo.order.create({ ... });
3310
+ *
3311
+ * // Query order status
3312
+ * const inquiryResult = await waffo.order.inquiry({
3313
+ * acquiringOrderId: createResult.data.acquiringOrderId,
3314
+ * });
3315
+ *
3316
+ * // Request a refund
3317
+ * const refundResult = await waffo.order.refund({
3318
+ * refundRequestId: 'refund-123',
3319
+ * acquiringOrderId: createResult.data.acquiringOrderId,
3320
+ * merchantId: 'M001',
3321
+ * refundAmount: '5.00',
3322
+ * refundReason: 'Customer request',
3323
+ * });
3324
+ */
3325
+ declare class OrderResource extends BaseResource {
3326
+ /**
3327
+ * Creates an Order resource instance.
3328
+ * @param {HttpClient} client - HTTP client instance
3329
+ */
3330
+ constructor(client: HttpClient);
3331
+ /**
3332
+ * Creates a new payment order.
3333
+ *
3334
+ * Supports multiple payment methods including e-wallet, credit card,
3335
+ * bank transfer, and more.
3336
+ *
3337
+ * @param {CreateOrderParams} params - Order creation parameters
3338
+ * @returns {Promise<ApiResponse<CreateOrderData>>} Order creation result
3339
+ *
3340
+ * @example
3341
+ * const result = await waffo.order.create({
3342
+ * paymentRequestId: 'req-' + Date.now(),
3343
+ * merchantOrderId: 'order-456',
3344
+ * orderCurrency: 'IDR',
3345
+ * orderAmount: '100000',
3346
+ * orderDescription: 'Product purchase',
3347
+ * merchantInfo: { merchantId: 'M001' },
3348
+ * userInfo: {
3349
+ * userId: 'U001',
3350
+ * userEmail: 'user@example.com',
3351
+ * userTerminal: 'WEB',
3352
+ * },
3353
+ * goodsInfo: {
3354
+ * goodsName: 'Premium Plan',
3355
+ * goodsUrl: 'https://example.com/product',
3356
+ * },
3357
+ * paymentInfo: {
3358
+ * productName: 'ONE_TIME_PAYMENT',
3359
+ * payMethodName: 'DANA',
3360
+ * },
3361
+ * notifyUrl: 'https://example.com/webhook',
3362
+ * successRedirectUrl: 'https://example.com/success',
3363
+ * });
3364
+ *
3365
+ * if (result.success) {
3366
+ * // Redirect user to payment page
3367
+ * const redirectUrl = result.data.orderAction?.webUrl;
3368
+ * }
3369
+ *
3370
+ * @see {@link CreateOrderParams} for all available parameters
3371
+ */
3372
+ create(params: CreateOrderParams): Promise<ApiResponse<CreateOrderData>>;
3373
+ /**
3374
+ * Queries current order status and details.
3375
+ *
3376
+ * Provide either `paymentRequestId` or `acquiringOrderId` to identify the order.
3377
+ *
3378
+ * @param {InquiryOrderParams} params - Query parameters
3379
+ * @returns {Promise<ApiResponse<InquiryOrderData>>} Order details
3380
+ *
3381
+ * @example
3382
+ * // Query by acquiring order ID
3383
+ * const result = await waffo.order.inquiry({
3384
+ * acquiringOrderId: 'ACQ123456789',
3385
+ * });
3386
+ *
3387
+ * if (result.success) {
3388
+ * console.log('Order status:', result.data.orderStatus);
3389
+ * console.log('Amount:', result.data.orderAmount, result.data.orderCurrency);
3390
+ * }
3391
+ *
3392
+ * @example
3393
+ * // Query by payment request ID
3394
+ * const result = await waffo.order.inquiry({
3395
+ * paymentRequestId: 'req-123',
3396
+ * });
3397
+ *
3398
+ * @see {@link InquiryOrderData} for response structure
3399
+ */
3400
+ inquiry(params: InquiryOrderParams): Promise<ApiResponse<InquiryOrderData>>;
3401
+ /**
3402
+ * Cancels an unpaid order.
3403
+ *
3404
+ * Only orders with status `AUTHORIZATION_REQUIRED` or `PAY_IN_PROGRESS` can be canceled.
3405
+ *
3406
+ * @param {CancelOrderParams} params - Cancel parameters
3407
+ * @returns {Promise<ApiResponse<CancelOrderData>>} Cancellation result
3408
+ *
3409
+ * @example
3410
+ * const result = await waffo.order.cancel({
3411
+ * acquiringOrderId: 'ACQ123456789',
3412
+ * merchantId: 'M001',
3413
+ * });
3414
+ *
3415
+ * if (result.success) {
3416
+ * console.log('Order canceled:', result.data.orderStatus);
3417
+ * // => 'ORDER_CLOSE'
3418
+ * }
3419
+ *
3420
+ * @see {@link CancelOrderData} for response structure
3421
+ */
3422
+ cancel(params: CancelOrderParams): Promise<ApiResponse<CancelOrderData>>;
3423
+ /**
3424
+ * Initiates a refund request for a paid order.
3425
+ *
3426
+ * Supports both full and partial refunds. Multiple partial refunds can be
3427
+ * made until the total refunded amount equals the original order amount.
3428
+ *
3429
+ * @param {RefundOrderParams} params - Refund parameters
3430
+ * @returns {Promise<ApiResponse<CreateRefundData>>} Refund request result
3431
+ *
3432
+ * @example
3433
+ * // Full refund
3434
+ * const result = await waffo.order.refund({
3435
+ * refundRequestId: 'refund-' + Date.now(),
3436
+ * acquiringOrderId: 'ACQ123456789',
3437
+ * merchantId: 'M001',
3438
+ * refundAmount: '100000',
3439
+ * refundReason: 'Customer request',
3440
+ * refundNotifyUrl: 'https://example.com/refund-webhook',
3441
+ * });
3442
+ *
3443
+ * if (result.success) {
3444
+ * console.log('Refund status:', result.data.refundStatus);
3445
+ * console.log('Remaining refundable:', result.data.remainingRefundAmount);
3446
+ * }
3447
+ *
3448
+ * @example
3449
+ * // Partial refund
3450
+ * const result = await waffo.order.refund({
3451
+ * refundRequestId: 'refund-partial-123',
3452
+ * acquiringOrderId: 'ACQ123456789',
3453
+ * merchantId: 'M001',
3454
+ * refundAmount: '50000', // Partial amount
3455
+ * refundReason: 'Partial refund',
3456
+ * });
3457
+ *
3458
+ * @see {@link CreateRefundData} for response structure
3459
+ */
3460
+ refund(params: RefundOrderParams): Promise<ApiResponse<CreateRefundData>>;
3461
+ /**
3462
+ * Captures an authorized payment (manualCapture mode only).
3463
+ *
3464
+ * Converts an authorization to an actual charge. Supports both
3465
+ * partial and full capture amounts.
3466
+ *
3467
+ * @param {CaptureOrderParams} params - Capture parameters
3468
+ * @returns {Promise<ApiResponse<CaptureOrderData>>} Capture result
3469
+ *
3470
+ * @example
3471
+ * // Full capture
3472
+ * const result = await waffo.order.capture({
3473
+ * acquiringOrderId: 'ACQ123456789',
3474
+ * merchantId: 'M001',
3475
+ * captureAmount: '100000', // Full authorized amount
3476
+ * });
3477
+ *
3478
+ * if (result.success) {
3479
+ * console.log('Capture status:', result.data.orderStatus);
3480
+ * }
3481
+ *
3482
+ * @example
3483
+ * // Partial capture
3484
+ * const result = await waffo.order.capture({
3485
+ * acquiringOrderId: 'ACQ123456789',
3486
+ * merchantId: 'M001',
3487
+ * captureAmount: '75000', // Capture less than authorized
3488
+ * });
3489
+ *
3490
+ * @see {@link CaptureOrderData} for response structure
3491
+ */
3492
+ capture(params: CaptureOrderParams): Promise<ApiResponse<CaptureOrderData>>;
3493
+ }
3494
+
3495
+ /**
3496
+ * @fileoverview Refund Resource Implementation
3497
+ * @module resources/refund/resource
3498
+ *
3499
+ * Implements the Refund resource class providing refund inquiry operations.
3500
+ *
3501
+ * @see {@link RefundResource} for the main class
3502
+ * @see {@link RefundInquiryParams} for inquiry parameters
3503
+ *
3504
+ * @example
3505
+ * // Query refund status
3506
+ * const result = await waffo.refund.inquiry({
3507
+ * refundRequestId: 'refund-123',
3508
+ * });
3509
+ */
3510
+
3511
+ /**
3512
+ * Refund resource for querying refund status and details.
3513
+ *
3514
+ * Note: Refund creation is done through {@link OrderResource.refund}.
3515
+ *
3516
+ * @class RefundResource
3517
+ * @extends BaseResource
3518
+ *
3519
+ * @example
3520
+ * const result = await waffo.refund.inquiry({
3521
+ * acquiringRefundOrderId: 'REF123456789',
3522
+ * });
3523
+ *
3524
+ * if (result.success) {
3525
+ * console.log('Refund status:', result.data.refundStatus);
3526
+ * }
3527
+ */
3528
+ declare class RefundResource extends BaseResource {
3529
+ /**
3530
+ * Creates a Refund resource instance.
3531
+ * @param {HttpClient} client - HTTP client instance
3532
+ */
3533
+ constructor(client: HttpClient);
3534
+ /**
3535
+ * Queries current refund status and details.
3536
+ *
3537
+ * Provide either `refundRequestId` or `acquiringRefundOrderId` to identify the refund.
3538
+ *
3539
+ * @param {RefundInquiryParams} params - Query parameters
3540
+ * @returns {Promise<ApiResponse<InquiryRefundData>>} Refund details
3541
+ *
3542
+ * @example
3543
+ * // Query by refund request ID
3544
+ * const result = await waffo.refund.inquiry({
3545
+ * refundRequestId: 'refund-123',
3546
+ * });
3547
+ *
3548
+ * if (result.success) {
3549
+ * const { refundStatus, refundAmount, remainingRefundAmount } = result.data;
3550
+ * console.log(`Status: ${refundStatus}`);
3551
+ * console.log(`Refunded: ${refundAmount}`);
3552
+ * console.log(`Remaining: ${remainingRefundAmount}`);
3553
+ * }
3554
+ *
3555
+ * @example
3556
+ * // Query by acquiring refund order ID
3557
+ * const result = await waffo.refund.inquiry({
3558
+ * acquiringRefundOrderId: 'REF123456789',
3559
+ * });
3560
+ *
3561
+ * @see {@link InquiryRefundData} for response structure
3562
+ */
3563
+ inquiry(params: RefundInquiryParams): Promise<ApiResponse<InquiryRefundData>>;
3564
+ }
3565
+
3566
+ /**
3567
+ * @fileoverview Subscription Resource Implementation
3568
+ * @module resources/subscription/resource
3569
+ *
3570
+ * Implements the Subscription resource class providing all subscription-related
3571
+ * API operations for recurring payments.
3572
+ *
3573
+ * @see {@link SubscriptionResource} for the main class
3574
+ * @see {@link CreateSubscriptionParams} for subscription creation parameters
3575
+ *
3576
+ * @example
3577
+ * // Create a subscription
3578
+ * const result = await waffo.subscription.create({
3579
+ * subscriptionRequest: 'sub-req-123',
3580
+ * currency: 'USD',
3581
+ * amount: '9.99',
3582
+ * productInfo: {
3583
+ * description: 'Monthly Premium',
3584
+ * periodType: 'MONTHLY',
3585
+ * periodInterval: '1',
3586
+ * },
3587
+ * // ... other required fields
3588
+ * });
3589
+ */
3590
+
3591
+ /**
3592
+ * Subscription resource for recurring payment operations.
3593
+ *
3594
+ * Provides methods for creating, querying, canceling, and managing subscriptions.
3595
+ *
3596
+ * @class SubscriptionResource
3597
+ * @extends BaseResource
3598
+ *
3599
+ * @example
3600
+ * // Full subscription lifecycle
3601
+ * const createResult = await waffo.subscription.create({ ... });
3602
+ * const inquiryResult = await waffo.subscription.inquiry({
3603
+ * subscriptionId: createResult.data.subscriptionId,
3604
+ * });
3605
+ * const cancelResult = await waffo.subscription.cancel({
3606
+ * subscriptionId: createResult.data.subscriptionId,
3607
+ * merchantId: 'M001',
3608
+ * });
3609
+ */
3610
+ declare class SubscriptionResource extends BaseResource {
3611
+ /**
3612
+ * Creates a Subscription resource instance.
3613
+ * @param {HttpClient} client - HTTP client instance
3614
+ */
3615
+ constructor(client: HttpClient);
3616
+ /**
3617
+ * Creates a new subscription signing request for recurring payments.
3618
+ *
3619
+ * After creation, redirect the user to the signing URL to authorize
3620
+ * the recurring payment agreement.
3621
+ *
3622
+ * @param {CreateSubscriptionParams} params - Subscription creation parameters
3623
+ * @returns {Promise<ApiResponse<CreateSubscriptionData>>} Subscription creation result
3624
+ *
3625
+ * @example
3626
+ * const result = await waffo.subscription.create({
3627
+ * subscriptionRequest: 'sub-' + Date.now(),
3628
+ * currency: 'HKD',
3629
+ * amount: '99.00',
3630
+ * productInfo: {
3631
+ * description: 'Premium Monthly Plan',
3632
+ * periodType: 'MONTHLY',
3633
+ * periodInterval: '1',
3634
+ * numberOfPeriod: '12', // 12 months
3635
+ * },
3636
+ * merchantInfo: { merchantId: 'M001' },
3637
+ * userInfo: {
3638
+ * userId: 'U001',
3639
+ * userEmail: 'user@example.com',
3640
+ * },
3641
+ * goodsInfo: {
3642
+ * goodsId: 'PREMIUM-PLAN',
3643
+ * goodsName: 'Premium Plan',
3644
+ * goodsUrl: 'https://example.com/plan',
3645
+ * },
3646
+ * paymentInfo: {
3647
+ * productName: 'SUBSCRIPTION',
3648
+ * payMethodName: 'ALIPAY_HK',
3649
+ * },
3650
+ * notifyUrl: 'https://example.com/webhook',
3651
+ * successRedirectUrl: 'https://example.com/success',
3652
+ * });
3653
+ *
3654
+ * if (result.success) {
3655
+ * // Redirect user to subscription signing page
3656
+ * const signingUrl = result.data.subscriptionAction?.webUrl;
3657
+ * }
3658
+ *
3659
+ * @see {@link CreateSubscriptionData} for response structure
3660
+ */
3661
+ create(params: CreateSubscriptionParams): Promise<ApiResponse<CreateSubscriptionData>>;
3662
+ /**
3663
+ * Queries subscription details and optionally payment history.
3664
+ *
3665
+ * @param {InquirySubscriptionParams} params - Query parameters
3666
+ * @returns {Promise<ApiResponse<InquirySubscriptionData>>} Subscription details
3667
+ *
3668
+ * @example
3669
+ * // Query subscription status
3670
+ * const result = await waffo.subscription.inquiry({
3671
+ * subscriptionId: 'SUB123456789',
3672
+ * });
3673
+ *
3674
+ * if (result.success) {
3675
+ * console.log('Status:', result.data.subscriptionStatus);
3676
+ * console.log('Next payment:', result.data.productInfo.nextPaymentDateTime);
3677
+ * }
3678
+ *
3679
+ * @example
3680
+ * // Query with payment history
3681
+ * const result = await waffo.subscription.inquiry({
3682
+ * subscriptionId: 'SUB123456789',
3683
+ * paymentDetails: '1', // Include payment history
3684
+ * });
3685
+ *
3686
+ * if (result.success && result.data.paymentDetails) {
3687
+ * result.data.paymentDetails.forEach(payment => {
3688
+ * console.log(`Period ${payment.period}: ${payment.orderStatus}`);
3689
+ * });
3690
+ * }
3691
+ *
3692
+ * @see {@link InquirySubscriptionData} for response structure
3693
+ */
3694
+ inquiry(params: InquirySubscriptionParams): Promise<ApiResponse<InquirySubscriptionData>>;
3695
+ /**
3696
+ * Cancels an active subscription.
3697
+ *
3698
+ * Once canceled, no further recurring payments will be processed.
3699
+ *
3700
+ * @param {CancelSubscriptionParams} params - Cancel parameters
3701
+ * @returns {Promise<ApiResponse<CancelSubscriptionData>>} Cancellation result
3702
+ *
3703
+ * @example
3704
+ * const result = await waffo.subscription.cancel({
3705
+ * subscriptionId: 'SUB123456789',
3706
+ * merchantId: 'M001',
3707
+ * });
3708
+ *
3709
+ * if (result.success) {
3710
+ * console.log('Subscription canceled:', result.data.orderStatus);
3711
+ * // => 'MERCHANT_CANCELLED'
3712
+ * }
3713
+ *
3714
+ * @see {@link CancelSubscriptionData} for response structure
3715
+ */
3716
+ cancel(params: CancelSubscriptionParams): Promise<ApiResponse<CancelSubscriptionData>>;
3717
+ /**
3718
+ * Generates a temporary management URL for users to manage their subscription.
3719
+ *
3720
+ * The URL allows users to view subscription details and cancel if needed.
3721
+ * The URL expires after a certain period (check `expiredAt` in response).
3722
+ *
3723
+ * @param {ManageSubscriptionParams} params - Management parameters
3724
+ * @returns {Promise<ApiResponse<ManageSubscriptionData>>} Management URL and expiration
3725
+ *
3726
+ * @example
3727
+ * const result = await waffo.subscription.manage({
3728
+ * subscriptionId: 'SUB123456789',
3729
+ * });
3730
+ *
3731
+ * if (result.success) {
3732
+ * console.log('Management URL:', result.data.managementUrl);
3733
+ * console.log('Expires at:', result.data.expiredAt);
3734
+ * // Send URL to user via email or display in app
3735
+ * }
3736
+ *
3737
+ * @see {@link ManageSubscriptionData} for response structure
3738
+ */
3739
+ manage(params: ManageSubscriptionParams): Promise<ApiResponse<ManageSubscriptionData>>;
3740
+ }
3741
+
3742
+ /**
3743
+ * @fileoverview Merchant Config Resource Implementation
3744
+ * @module resources/merchantconfig/resource
3745
+ *
3746
+ * Implements the Merchant Config resource class providing merchant
3747
+ * configuration inquiry operations.
3748
+ *
3749
+ * @see {@link MerchantConfigResource} for the main class
3750
+ * @see {@link MerchantConfigInquiryParams} for inquiry parameters
3751
+ *
3752
+ * @example
3753
+ * const result = await waffo.merchantConfig.inquiry({
3754
+ * merchantId: 'M001',
3755
+ * });
3756
+ */
3757
+
3758
+ /**
3759
+ * Merchant configuration resource for querying transaction limits.
3760
+ *
3761
+ * Use this to retrieve daily limits, remaining limits, and
3762
+ * per-transaction limits for a merchant.
3763
+ *
3764
+ * @class MerchantConfigResource
3765
+ * @extends BaseResource
3766
+ *
3767
+ * @example
3768
+ * const result = await waffo.merchantConfig.inquiry({ merchantId: 'M001' });
3769
+ * if (result.success) {
3770
+ * console.log('Daily limit:', result.data.totalDailyLimit);
3771
+ * console.log('Remaining:', result.data.remainingDailyLimit);
3772
+ * }
3773
+ */
3774
+ declare class MerchantConfigResource extends BaseResource {
3775
+ /**
3776
+ * Creates a Merchant Config resource instance.
3777
+ * @param {HttpClient} client - HTTP client instance
3778
+ */
3779
+ constructor(client: HttpClient);
3780
+ /**
3781
+ * Queries merchant configuration including transaction limits.
3782
+ *
3783
+ * @param {MerchantConfigInquiryParams} params - Query parameters
3784
+ * @returns {Promise<ApiResponse<MerchantConfigInquiryData>>} Merchant configuration
3785
+ *
3786
+ * @example
3787
+ * const result = await waffo.merchantConfig.inquiry({
3788
+ * merchantId: 'M001',
3789
+ * });
3790
+ *
3791
+ * if (result.success) {
3792
+ * const { totalDailyLimit, remainingDailyLimit, transactionLimit } = result.data;
3793
+ *
3794
+ * // Limits are returned as currency -> value maps
3795
+ * console.log('Daily limit (USD):', totalDailyLimit?.['USD']);
3796
+ * console.log('Remaining (USD):', remainingDailyLimit?.['USD']);
3797
+ * console.log('Per transaction (USD):', transactionLimit?.['USD']);
3798
+ * }
3799
+ *
3800
+ * @see {@link MerchantConfigInquiryData} for response structure
3801
+ */
3802
+ inquiry(params: MerchantConfigInquiryParams): Promise<ApiResponse<MerchantConfigInquiryData>>;
3803
+ }
3804
+
3805
+ /**
3806
+ * @fileoverview Pay Method Config Resource Implementation
3807
+ * @module resources/paymethodconfig/resource
3808
+ *
3809
+ * Implements the Pay Method Config resource class providing payment method
3810
+ * configuration inquiry operations.
3811
+ *
3812
+ * @see {@link PayMethodConfigResource} for the main class
3813
+ * @see {@link PayMethodConfigInquiryParams} for inquiry parameters
3814
+ *
3815
+ * @example
3816
+ * const result = await waffo.payMethodConfig.inquiry({
3817
+ * merchantId: 'M001',
3818
+ * });
3819
+ */
3820
+
3821
+ /**
3822
+ * Payment method configuration resource for querying available methods.
3823
+ *
3824
+ * Use this to retrieve available payment methods, their current status,
3825
+ * and scheduled maintenance windows.
3826
+ *
3827
+ * @class PayMethodConfigResource
3828
+ * @extends BaseResource
3829
+ *
3830
+ * @example
3831
+ * const result = await waffo.payMethodConfig.inquiry({ merchantId: 'M001' });
3832
+ * if (result.success) {
3833
+ * const availableMethods = result.data.payMethodDetails.filter(
3834
+ * m => m.currentStatus === '1'
3835
+ * );
3836
+ * }
3837
+ */
3838
+ declare class PayMethodConfigResource extends BaseResource {
3839
+ /**
3840
+ * Creates a Pay Method Config resource instance.
3841
+ * @param {HttpClient} client - HTTP client instance
3842
+ */
3843
+ constructor(client: HttpClient);
3844
+ /**
3845
+ * Queries available payment methods and their status.
3846
+ *
3847
+ * @param {PayMethodConfigInquiryParams} params - Query parameters
3848
+ * @returns {Promise<ApiResponse<PayMethodConfigInquiryData>>} Payment method details
3849
+ *
3850
+ * @example
3851
+ * const result = await waffo.payMethodConfig.inquiry({
3852
+ * merchantId: 'M001',
3853
+ * });
3854
+ *
3855
+ * if (result.success) {
3856
+ * result.data.payMethodDetails.forEach(method => {
3857
+ * const status = method.currentStatus === '1' ? 'Available' : 'Unavailable';
3858
+ * console.log(`${method.payMethodName} (${method.country}): ${status}`);
3859
+ *
3860
+ * // Check maintenance windows
3861
+ * if (method.fixedMaintenanceRules?.length) {
3862
+ * console.log(' Maintenance:', method.fixedMaintenanceRules);
3863
+ * }
3864
+ * });
3865
+ * }
3866
+ *
3867
+ * @example
3868
+ * // Filter available e-wallet methods
3869
+ * const ewallets = result.data.payMethodDetails.filter(
3870
+ * m => m.currentStatus === '1' && m.productName === 'ONE_TIME_PAYMENT'
3871
+ * );
3872
+ *
3873
+ * @see {@link PayMethodConfigInquiryData} for response structure
3874
+ */
3875
+ inquiry(params: PayMethodConfigInquiryParams): Promise<ApiResponse<PayMethodConfigInquiryData>>;
3876
+ }
3877
+
3878
+ /**
3879
+ * @fileoverview Waffo SDK Main Entry Point
3880
+ * @module core/waffo
3881
+ *
3882
+ * Provides the main SDK class for interacting with the Waffo Payment Platform.
3883
+ *
3884
+ * **Supported Operations:**
3885
+ * - Order management (create, inquiry, cancel, refund, capture)
3886
+ * - Refund status inquiry
3887
+ * - Subscription management (create, inquiry, cancel, manage)
3888
+ * - Merchant and payment method configuration inquiry
3889
+ *
3890
+ * @see {@link WaffoConfig} for SDK configuration options
3891
+ * @see {@link OrderResource} for order operations
3892
+ * @see {@link SubscriptionResource} for subscription operations
3893
+ *
3894
+ * @example
3895
+ * // Initialize the SDK
3896
+ * import { Waffo, Environment } from 'waffo-sdk';
3897
+ *
3898
+ * const waffo = new Waffo({
3899
+ * apiKey: 'your-api-key',
3900
+ * privateKey: 'your-base64-encoded-private-key',
3901
+ * environment: Environment.SANDBOX,
3902
+ * });
3903
+ *
3904
+ * // Create a payment order
3905
+ * const result = await waffo.order.create({
3906
+ * paymentRequestId: 'req-123',
3907
+ * merchantOrderId: 'order-456',
3908
+ * orderCurrency: 'USD',
3909
+ * orderAmount: '10.00',
3910
+ * // ... other required fields
3911
+ * });
3912
+ */
3913
+
3914
+ /**
3915
+ * Main SDK class for the Waffo Payment Platform.
3916
+ *
3917
+ * Provides a unified interface for all payment operations with automatic
3918
+ * RSA-SHA256 request signing and response verification.
3919
+ *
3920
+ * **Features:**
3921
+ * - Order operations: create, inquiry, cancel, refund, capture
3922
+ * - Refund inquiry
3923
+ * - Subscription management: create, inquiry, cancel, manage
3924
+ * - Configuration queries: merchant limits, payment methods
3925
+ *
3926
+ * @class Waffo
3927
+ *
3928
+ * @example
3929
+ * // Basic SDK initialization
3930
+ * const waffo = new Waffo({
3931
+ * apiKey: 'your-api-key',
3932
+ * privateKey: 'base64-encoded-pkcs8-private-key',
3933
+ * environment: Environment.PRODUCTION,
3934
+ * });
3935
+ *
3936
+ * @example
3937
+ * // Create and query an order
3938
+ * const createResult = await waffo.order.create({ ... });
3939
+ * if (createResult.success) {
3940
+ * const inquiryResult = await waffo.order.inquiry({
3941
+ * acquiringOrderId: createResult.data.acquiringOrderId,
3942
+ * });
3943
+ * }
3944
+ *
3945
+ * @example
3946
+ * // Handle webhooks
3947
+ * const result = await waffo.webhook.handle(requestBody, signature, {
3948
+ * onPayment: async (ctx) => {
3949
+ * console.log('Payment received:', ctx.notification.result.orderStatus);
3950
+ * },
3951
+ * });
3952
+ *
3953
+ * @see {@link WaffoConfig} - Configuration options
3954
+ * @see {@link OrderResource} - Order operations
3955
+ * @see {@link SubscriptionResource} - Subscription operations
3956
+ */
3957
+ declare class Waffo {
3958
+ /**
3959
+ * Order resource for payment processing operations.
3960
+ *
3961
+ * **Available methods:**
3962
+ * - `create()` - Create a new payment order
3963
+ * - `inquiry()` - Query order status and details
3964
+ * - `cancel()` - Cancel an unpaid order
3965
+ * - `refund()` - Request a refund for a paid order
3966
+ * - `capture()` - Capture an authorized payment (manualCapture mode)
3967
+ *
3968
+ * @type {OrderResource}
3969
+ * @readonly
3970
+ *
3971
+ * @example
3972
+ * const result = await waffo.order.create({
3973
+ * paymentRequestId: 'req-123',
3974
+ * merchantOrderId: 'order-456',
3975
+ * orderCurrency: 'USD',
3976
+ * orderAmount: '10.00',
3977
+ * orderDescription: 'Product purchase',
3978
+ * merchantInfo: { merchantId: 'M001' },
3979
+ * userInfo: { userId: 'U001', userEmail: 'user@example.com', userTerminal: 'WEB' },
3980
+ * goodsInfo: { goodsName: 'Product', goodsUrl: 'https://example.com/product' },
3981
+ * paymentInfo: { productName: 'ONE_TIME_PAYMENT', payMethodName: 'DANA' },
3982
+ * notifyUrl: 'https://example.com/webhook',
3983
+ * });
3984
+ *
3985
+ * @see {@link OrderResource}
3986
+ */
3987
+ readonly order: OrderResource;
3988
+ /**
3989
+ * Refund resource for querying refund status.
3990
+ *
3991
+ * **Available methods:**
3992
+ * - `inquiry()` - Query refund status by refundRequestId or acquiringRefundOrderId
3993
+ *
3994
+ * @type {RefundResource}
3995
+ * @readonly
3996
+ *
3997
+ * @example
3998
+ * const result = await waffo.refund.inquiry({
3999
+ * refundRequestId: 'refund-req-123',
4000
+ * });
4001
+ * if (result.success) {
4002
+ * console.log('Refund status:', result.data.refundStatus);
4003
+ * }
4004
+ *
4005
+ * @see {@link RefundResource}
4006
+ */
4007
+ readonly refund: RefundResource;
4008
+ /**
4009
+ * Subscription resource for recurring payment operations.
4010
+ *
4011
+ * **Available methods:**
4012
+ * - `create()` - Create a new subscription signing request
4013
+ * - `inquiry()` - Query subscription status and payment history
4014
+ * - `cancel()` - Cancel an active subscription
4015
+ * - `manage()` - Generate a temporary management URL for users
4016
+ *
4017
+ * @type {SubscriptionResource}
4018
+ * @readonly
4019
+ *
4020
+ * @example
4021
+ * const result = await waffo.subscription.create({
4022
+ * subscriptionRequest: 'sub-req-123',
4023
+ * currency: 'USD',
4024
+ * amount: '9.99',
4025
+ * productInfo: {
4026
+ * description: 'Monthly subscription',
4027
+ * periodType: 'MONTHLY',
4028
+ * periodInterval: '1',
4029
+ * },
4030
+ * // ... other required fields
4031
+ * });
4032
+ *
4033
+ * @see {@link SubscriptionResource}
4034
+ */
4035
+ readonly subscription: SubscriptionResource;
4036
+ /**
4037
+ * Merchant configuration resource for querying transaction limits.
4038
+ *
4039
+ * **Available methods:**
4040
+ * - `inquiry()` - Query daily limits, remaining limits, and transaction limits
4041
+ *
4042
+ * @type {MerchantConfigResource}
4043
+ * @readonly
4044
+ *
4045
+ * @example
4046
+ * const result = await waffo.merchantConfig.inquiry({
4047
+ * merchantId: 'M001',
4048
+ * });
4049
+ * if (result.success) {
4050
+ * console.log('Daily limit:', result.data.totalDailyLimit);
4051
+ * }
4052
+ *
4053
+ * @see {@link MerchantConfigResource}
4054
+ */
4055
+ readonly merchantConfig: MerchantConfigResource;
4056
+ /**
4057
+ * Payment method configuration resource for querying available methods.
4058
+ *
4059
+ * **Available methods:**
4060
+ * - `inquiry()` - Query available payment methods, status, and maintenance schedules
4061
+ *
4062
+ * @type {PayMethodConfigResource}
4063
+ * @readonly
4064
+ *
4065
+ * @example
4066
+ * const result = await waffo.payMethodConfig.inquiry({
4067
+ * merchantId: 'M001',
4068
+ * });
4069
+ * if (result.success) {
4070
+ * result.data.payMethodDetails.forEach(method => {
4071
+ * console.log(`${method.payMethodName}: ${method.currentStatus === '1' ? 'Available' : 'Unavailable'}`);
4072
+ * });
4073
+ * }
4074
+ *
4075
+ * @see {@link PayMethodConfigResource}
4076
+ */
4077
+ readonly payMethodConfig: PayMethodConfigResource;
4078
+ /**
4079
+ * Low-level HTTP client for direct API requests.
4080
+ *
4081
+ * All requests are automatically signed and responses are verified.
4082
+ * Use this for custom endpoints not covered by the resource classes.
4083
+ *
4084
+ * @type {HttpClient}
4085
+ * @readonly
4086
+ *
4087
+ * @example
4088
+ * // Make a custom API request
4089
+ * const result = await waffo.httpClient.post('/custom/endpoint', {
4090
+ * body: { customField: 'value' },
4091
+ * });
4092
+ *
4093
+ * @see {@link HttpClient}
4094
+ */
4095
+ readonly httpClient: HttpClient;
4096
+ /**
4097
+ * Webhook handler for processing incoming notifications from Waffo.
4098
+ *
4099
+ * Use `handle()` method to process webhook notifications with custom handlers.
4100
+ *
4101
+ * @type {WebhookHandler}
4102
+ * @readonly
4103
+ *
4104
+ * @example
4105
+ * // Express.js webhook endpoint
4106
+ * app.post('/webhook', async (req, res) => {
4107
+ * const result = await waffo.webhook.handle(
4108
+ * JSON.stringify(req.body),
4109
+ * req.headers['x-signature'],
4110
+ * {
4111
+ * onPayment: async (ctx) => {
4112
+ * await updateOrderStatus(ctx.notification.result);
4113
+ * },
4114
+ * onRefund: async (ctx) => {
4115
+ * await processRefund(ctx.notification.result);
4116
+ * },
4117
+ * }
4118
+ * );
4119
+ * res.set(result.response.header).json(result.response.body);
4120
+ * });
4121
+ *
4122
+ * @see {@link WebhookHandler}
4123
+ */
4124
+ readonly webhook: WebhookHandler;
4125
+ /**
4126
+ * Creates a new Waffo SDK instance.
4127
+ *
4128
+ * Initializes the SDK with the provided configuration. The SDK automatically
4129
+ * selects the appropriate API endpoint and public key based on the environment.
4130
+ *
4131
+ * @param {WaffoConfig} config - SDK configuration object
4132
+ * @param {string} config.apiKey - API key assigned by Waffo (required)
4133
+ * @param {string} config.privateKey - Merchant private key, Base64 encoded PKCS8 DER format (required)
4134
+ * @param {string} [config.waffoPublicKey] - Waffo public key for response verification (optional)
4135
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment (optional)
4136
+ * @param {number} [config.timeout=30000] - Request timeout in milliseconds (optional)
4137
+ * @param {Logger} [config.logger] - Logger instance for debugging (optional)
4138
+ *
4139
+ * @throws {Error} When API key or private key is missing or invalid
4140
+ *
4141
+ * @example
4142
+ * // Production configuration
4143
+ * const waffo = new Waffo({
4144
+ * apiKey: process.env.WAFFO_API_KEY,
4145
+ * privateKey: process.env.WAFFO_PRIVATE_KEY,
4146
+ * environment: Environment.PRODUCTION,
4147
+ * });
4148
+ *
4149
+ * @example
4150
+ * // Sandbox configuration with debugging
4151
+ * const waffo = new Waffo({
4152
+ * apiKey: 'sandbox-api-key',
4153
+ * privateKey: 'sandbox-private-key',
4154
+ * environment: Environment.SANDBOX,
4155
+ * timeout: 60000,
4156
+ * logger: console,
4157
+ * });
4158
+ *
4159
+ * @see {@link WaffoConfig} for configuration options
4160
+ * @see {@link Environment} for available environments
4161
+ */
4162
+ constructor(config: WaffoConfig);
4163
+ /**
4164
+ * Generates a new 2048-bit RSA key pair for API signing and verification.
4165
+ *
4166
+ * **Generated key formats:**
4167
+ * - Private key: Base64 encoded PKCS8 DER format (for signing requests)
4168
+ * - Public key: Base64 encoded X509/SPKI DER format (for verification)
4169
+ *
4170
+ * **Usage:**
4171
+ * 1. Generate a key pair using this method
4172
+ * 2. Register the public key with Waffo via merchant dashboard
4173
+ * 3. Store the private key securely on your server
4174
+ * 4. Use the private key when initializing the SDK
4175
+ *
4176
+ * @static
4177
+ * @returns {KeyPair} Object containing the generated key pair
4178
+ *
4179
+ * @example
4180
+ * // Generate a new key pair
4181
+ * const keys = Waffo.generateKeyPair();
4182
+ * console.log('Private Key:', keys.privateKey);
4183
+ * console.log('Public Key:', keys.publicKey);
4184
+ *
4185
+ * // Use the private key to initialize SDK
4186
+ * const waffo = new Waffo({
4187
+ * apiKey: 'your-api-key',
4188
+ * privateKey: keys.privateKey,
4189
+ * });
4190
+ *
4191
+ * @see {@link KeyPair} for the return type structure
4192
+ */
4193
+ static generateKeyPair(): KeyPair;
4194
+ }
4195
+
4196
+ /**
4197
+ * @fileoverview RSA Cryptographic Utility Functions
4198
+ * @module utils/rsa
4199
+ *
4200
+ * Provides RSA cryptographic operations for the Waffo SDK:
4201
+ * - **{@link signForRSA}** - Sign data using RSA-SHA256
4202
+ * - **{@link verify}** - Verify RSA-SHA256 signatures
4203
+ * - **{@link createKeyPair}** - Generate new RSA key pairs
4204
+ *
4205
+ * **Key Formats:**
4206
+ * - Private keys: Base64 encoded PKCS8 DER format
4207
+ * - Public keys: Base64 encoded X509/SPKI DER format
4208
+ *
4209
+ * @see {@link HttpClient} for automatic request signing
4210
+ * @see {@link verifyWebhookSignature} for webhook verification
4211
+ *
4212
+ * @example
4213
+ * import { signForRSA, verify, createKeyPair } from 'waffo-sdk';
4214
+ *
4215
+ * // Generate a new key pair
4216
+ * const keys = createKeyPair();
4217
+ *
4218
+ * // Sign data
4219
+ * const data = JSON.stringify({ message: 'Hello' });
4220
+ * const signature = signForRSA(data, keys.PRIVATE_KEY_NAME);
4221
+ *
4222
+ * // Verify signature
4223
+ * const isValid = verify(data, signature, keys.PUBLIC_KEY_NAME);
4224
+ */
4225
+ /**
4226
+ * Callback function for handling cryptographic errors.
4227
+ *
4228
+ * When provided to signing/verification functions, errors are passed
4229
+ * to this callback instead of causing the function to throw.
4230
+ *
4231
+ * @typedef {Function} ErrorHandler
4232
+ * @param {Error} error - The error that occurred
4233
+ *
4234
+ * @example
4235
+ * const signature = signForRSA(data, privateKey, 'utf8', (error) => {
4236
+ * console.error('Signing failed:', error.message);
4237
+ * });
4238
+ */
4239
+ type ErrorHandler = (error: Error) => void;
4240
+ /**
4241
+ * Signs a payload using RSA-SHA256 algorithm.
4242
+ *
4243
+ * Returns a Base64 encoded signature. Used internally by the SDK to sign
4244
+ * all outgoing API requests (included in `X-SIGNATURE` header).
4245
+ *
4246
+ * @param {string} body - Payload to sign (typically JSON serialized)
4247
+ * @param {string} privateKey - Private key (Base64 encoded PKCS8 DER format)
4248
+ * @param {string} [charSet='utf8'] - Character encoding ('utf8', 'ascii', 'latin1')
4249
+ * @param {ErrorHandler} [onError] - Optional error handler callback
4250
+ *
4251
+ * @returns {string | null} Base64 encoded signature, or `null` on failure
4252
+ *
4253
+ * @example
4254
+ * // Sign a JSON payload
4255
+ * const payload = JSON.stringify({ orderId: '123', amount: '100' });
4256
+ * const signature = signForRSA(payload, privateKey);
4257
+ *
4258
+ * if (signature) {
4259
+ * console.log('Signature:', signature);
4260
+ * }
4261
+ *
4262
+ * @example
4263
+ * // With error handling
4264
+ * const signature = signForRSA(payload, privateKey, 'utf8', (error) => {
4265
+ * console.error('Signing failed:', error.message);
4266
+ * });
4267
+ *
4268
+ * @see {@link verify} for signature verification
4269
+ * @see {@link createKeyPair} for generating key pairs
4270
+ */
4271
+ declare function signForRSA(body: string, privateKey: string, charSet?: string, onError?: ErrorHandler): string | null;
4272
+ /**
4273
+ * Verifies an RSA-SHA256 signature.
4274
+ *
4275
+ * Returns `true` if the signature is valid. Used internally by the SDK
4276
+ * to verify API response and webhook notification signatures.
4277
+ *
4278
+ * @param {string} body - Original payload that was signed
4279
+ * @param {string} sign - Signature to verify (Base64 encoded)
4280
+ * @param {string} publicKey - Public key (Base64 encoded X509/SPKI DER format)
4281
+ * @param {string} [charSet='utf8'] - Character encoding (must match signing)
4282
+ * @param {ErrorHandler} [onError] - Optional error handler callback
4283
+ *
4284
+ * @returns {boolean} `true` if signature is valid, `false` otherwise
4285
+ *
4286
+ * @example
4287
+ * // Verify a signature
4288
+ * const isValid = verify(payload, signature, publicKey);
4289
+ *
4290
+ * if (isValid) {
4291
+ * console.log('Signature verified successfully');
4292
+ * } else {
4293
+ * console.log('Invalid signature');
4294
+ * }
4295
+ *
4296
+ * @example
4297
+ * // With error handling
4298
+ * const isValid = verify(payload, signature, publicKey, 'utf8', (error) => {
4299
+ * console.error('Verification error:', error.message);
4300
+ * });
4301
+ *
4302
+ * @see {@link signForRSA} for signature generation
4303
+ * @see {@link verifyWebhookSignature} for webhook verification
4304
+ */
4305
+ declare function verify(body: string, sign: string, publicKey: string, charSet?: string, onError?: ErrorHandler): boolean;
4306
+ /**
4307
+ * Generates a new 2048-bit RSA key pair for Waffo API authentication.
4308
+ *
4309
+ * **Generated Key Formats:**
4310
+ * - Private key: Base64 encoded PKCS8 DER format (for signing)
4311
+ * - Public key: Base64 encoded X509/SPKI DER format (for verification)
4312
+ *
4313
+ * **Usage:**
4314
+ * 1. Generate a key pair using this function
4315
+ * 2. Register the public key with Waffo via merchant dashboard
4316
+ * 3. Store the private key securely on your server
4317
+ * 4. Use the private key when initializing the SDK
4318
+ *
4319
+ * **Security Notes:**
4320
+ * - Never expose the private key in client-side code
4321
+ * - Store privately (environment variables, secrets manager)
4322
+ * - Use different keys for sandbox/production
4323
+ *
4324
+ * @returns {{ PRIVATE_KEY_NAME: string, PUBLIC_KEY_NAME: string }} Generated key pair
4325
+ *
4326
+ * @example
4327
+ * // Generate a new key pair
4328
+ * const keys = createKeyPair();
4329
+ *
4330
+ * console.log('Private Key (store securely):');
4331
+ * console.log(keys.PRIVATE_KEY_NAME);
4332
+ *
4333
+ * console.log('Public Key (register with Waffo):');
4334
+ * console.log(keys.PUBLIC_KEY_NAME);
4335
+ *
4336
+ * @example
4337
+ * // Use the generated private key with SDK
4338
+ * const waffo = new Waffo({
4339
+ * apiKey: 'your-api-key',
4340
+ * privateKey: keys.PRIVATE_KEY_NAME,
4341
+ * });
4342
+ *
4343
+ * @see {@link Waffo.generateKeyPair} for static access via Waffo class
4344
+ */
4345
+ declare function createKeyPair(): {
4346
+ PRIVATE_KEY_NAME: string;
4347
+ PUBLIC_KEY_NAME: string;
4348
+ };
4349
+
4350
+ /**
4351
+ * @fileoverview Webhook Utility Functions
4352
+ * @module utils/webhook
4353
+ *
4354
+ * Utility functions for handling Waffo webhook notifications:
4355
+ * - **{@link verifyWebhookSignature}** - Verify incoming webhook signatures
4356
+ * - **{@link buildWebhookResponse}** - Build signed webhook responses
4357
+ * - **{@link buildSuccessResponse}** - Shorthand for success responses
4358
+ * - **{@link buildFailedResponse}** - Shorthand for failure responses
4359
+ * - **Type guard functions** - Check notification types
4360
+ *
4361
+ * **Webhook Flow:**
4362
+ * 1. Receive webhook POST request from Waffo
4363
+ * 2. Verify the X-SIGNATURE header
4364
+ * 3. Process the notification based on event type
4365
+ * 4. Return a signed response
4366
+ *
4367
+ * @see {@link WebhookEventType} for notification types
4368
+ * @see {@link WebhookResponseStatus} for response statuses
4369
+ *
4370
+ * @example
4371
+ * import {
4372
+ * verifyWebhookSignature,
4373
+ * buildSuccessResponse,
4374
+ * isPaymentNotification,
4375
+ * } from 'waffo-sdk';
4376
+ *
4377
+ * // In your webhook handler
4378
+ * const result = verifyWebhookSignature(body, signature, waffoPublicKey);
4379
+ * if (result.isValid && isPaymentNotification(result.notification)) {
4380
+ * // Process payment notification
4381
+ * await processPayment(result.notification);
4382
+ * return buildSuccessResponse(merchantPrivateKey);
4383
+ * }
4384
+ */
4385
+
4386
+ /**
4387
+ * Union type representing all webhook notification types from Waffo.
4388
+ *
4389
+ * Use type guard functions to narrow down the specific type:
4390
+ * - {@link isPaymentNotification} - Payment notifications
4391
+ * - {@link isRefundNotification} - Refund notifications
4392
+ * - {@link isSubscriptionStatusNotification} - Subscription status changes
4393
+ * - {@link isSubscriptionPaymentNotification} - Subscription payments
4394
+ *
4395
+ * @typedef {PaymentNotification | RefundNotification | SubscriptionNotification} AnyWebhookNotification
4396
+ */
4397
+ type AnyWebhookNotification = PaymentNotification | RefundNotification | SubscriptionNotification;
4398
+ /**
4399
+ * Result of webhook signature verification.
4400
+ *
4401
+ * Contains verification status and parsed notification data.
4402
+ *
4403
+ * @interface WebhookVerificationResult
4404
+ *
4405
+ * @example
4406
+ * const result = verifyWebhookSignature(body, signature, publicKey);
4407
+ * if (result.isValid) {
4408
+ * console.log('Event type:', result.eventType);
4409
+ * console.log('Notification:', result.notification);
4410
+ * } else {
4411
+ * console.error('Verification failed:', result.error);
4412
+ * }
4413
+ */
4414
+ interface WebhookVerificationResult {
4415
+ /** Whether the signature verification passed */
4416
+ isValid: boolean;
4417
+ /** Parsed notification data (only when isValid is true) */
4418
+ notification?: AnyWebhookNotification;
4419
+ /** Event type from the notification (only when isValid is true) */
4420
+ eventType?: WebhookEventType;
4421
+ /** Error message (only when isValid is false) */
4422
+ error?: string;
4423
+ }
4424
+ /**
4425
+ * Verifies the signature of a webhook notification from Waffo.
4426
+ *
4427
+ * @param {string} requestBody - Raw request body string (JSON)
4428
+ * @param {string} signature - X-SIGNATURE header value from Waffo
4429
+ * @param {string} waffoPublicKey - Waffo's public key (Base64 encoded X509 DER)
4430
+ * @returns {WebhookVerificationResult} Verification result with parsed notification
4431
+ *
4432
+ * @example
4433
+ * // Express.js webhook handler
4434
+ * app.post('/webhook', (req, res) => {
4435
+ * const result = verifyWebhookSignature(
4436
+ * JSON.stringify(req.body),
4437
+ * req.headers['x-signature'],
4438
+ * waffoPublicKey
4439
+ * );
4440
+ *
4441
+ * if (!result.isValid) {
4442
+ * console.error('Invalid signature:', result.error);
4443
+ * return res.status(400).send('Invalid signature');
4444
+ * }
4445
+ *
4446
+ * console.log('Event type:', result.eventType);
4447
+ * console.log('Notification:', result.notification);
4448
+ *
4449
+ * // Process notification...
4450
+ * });
4451
+ *
4452
+ * @see {@link WebhookVerificationResult} for return type
4453
+ */
4454
+ declare function verifyWebhookSignature(requestBody: string, signature: string, waffoPublicKey: string): WebhookVerificationResult;
4455
+ /**
4456
+ * Builds a properly signed webhook response to send back to Waffo.
4457
+ *
4458
+ * @param {WebhookResponseStatus} status - Response status (SUCCESS, FAILED, UNKNOWN)
4459
+ * @param {string} merchantPrivateKey - Merchant's private key (Base64 encoded PKCS8 DER)
4460
+ * @returns {WebhookResponse} Complete response with signed header
4461
+ * @throws {Error} "Failed to sign webhook response" when signing fails
4462
+ *
4463
+ * @example
4464
+ * // Build and send response
4465
+ * const response = buildWebhookResponse(
4466
+ * WebhookResponseStatus.SUCCESS,
4467
+ * merchantPrivateKey
4468
+ * );
4469
+ *
4470
+ * res.set(response.header).json(response.body);
4471
+ *
4472
+ * @example
4473
+ * // With error status
4474
+ * const response = buildWebhookResponse(
4475
+ * WebhookResponseStatus.FAILED,
4476
+ * merchantPrivateKey
4477
+ * );
4478
+ * // Waffo will retry the notification
4479
+ *
4480
+ * @see {@link buildSuccessResponse} for shorthand success response
4481
+ * @see {@link buildFailedResponse} for shorthand failure response
4482
+ */
4483
+ declare function buildWebhookResponse(status: WebhookResponseStatus, merchantPrivateKey: string): WebhookResponse;
4484
+ /**
4485
+ * Builds a success webhook response (shorthand).
4486
+ *
4487
+ * Use when the notification was successfully processed.
4488
+ * Equivalent to `buildWebhookResponse(WebhookResponseStatus.SUCCESS, merchantPrivateKey)`.
4489
+ *
4490
+ * @param {string} merchantPrivateKey - Merchant's private key (Base64 encoded PKCS8 DER)
4491
+ * @returns {WebhookResponse} Response with SUCCESS status
4492
+ * @throws {Error} "Failed to sign webhook response" when signing fails
4493
+ *
4494
+ * @example
4495
+ * // After successful processing
4496
+ * const response = buildSuccessResponse(merchantPrivateKey);
4497
+ * res.set(response.header).json(response.body);
4498
+ *
4499
+ * @see {@link buildFailedResponse} for failure responses
4500
+ */
4501
+ declare function buildSuccessResponse(merchantPrivateKey: string): WebhookResponse;
4502
+ /**
4503
+ * Builds a failed webhook response (shorthand).
4504
+ *
4505
+ * Use when notification processing failed (database error, validation error, etc.).
4506
+ * **Waffo will retry the notification within 24 hours using exponential backoff.**
4507
+ *
4508
+ * Equivalent to `buildWebhookResponse(WebhookResponseStatus.FAILED, merchantPrivateKey)`.
4509
+ *
4510
+ * @param {string} merchantPrivateKey - Merchant's private key (Base64 encoded PKCS8 DER)
4511
+ * @returns {WebhookResponse} Response with FAILED status
4512
+ * @throws {Error} "Failed to sign webhook response" when signing fails
4513
+ *
4514
+ * @example
4515
+ * // When processing fails
4516
+ * try {
4517
+ * await processNotification(notification);
4518
+ * return buildSuccessResponse(merchantPrivateKey);
4519
+ * } catch (error) {
4520
+ * console.error('Processing failed:', error);
4521
+ * return buildFailedResponse(merchantPrivateKey);
4522
+ * // Waffo will retry later
4523
+ * }
4524
+ *
4525
+ * @see {@link buildSuccessResponse} for success responses
4526
+ */
4527
+ declare function buildFailedResponse(merchantPrivateKey: string): WebhookResponse;
4528
+ /**
4529
+ * Extracts the event type from a webhook notification.
4530
+ *
4531
+ * Accepts either a parsed notification object or raw JSON string.
4532
+ *
4533
+ * @param {AnyWebhookNotification | string} notification - Parsed object or raw JSON
4534
+ * @returns {WebhookEventType | undefined} Event type, or `undefined` if invalid
4535
+ *
4536
+ * @example
4537
+ * // From parsed notification
4538
+ * const eventType = getWebhookEventType(notification);
4539
+ * // => 'PAYMENT_NOTIFICATION'
4540
+ *
4541
+ * @example
4542
+ * // From raw JSON string
4543
+ * const eventType = getWebhookEventType(requestBody);
4544
+ *
4545
+ * switch (eventType) {
4546
+ * case WebhookEventType.PAYMENT_NOTIFICATION:
4547
+ * handlePayment(notification);
4548
+ * break;
4549
+ * case WebhookEventType.REFUND_NOTIFICATION:
4550
+ * handleRefund(notification);
4551
+ * break;
4552
+ * }
4553
+ *
4554
+ * @see {@link WebhookEventType} for available event types
4555
+ */
4556
+ declare function getWebhookEventType(notification: AnyWebhookNotification | string): WebhookEventType | undefined;
4557
+ /**
4558
+ * Type guard: checks if notification is a payment notification.
4559
+ *
4560
+ * Payment notifications are sent when a one-time/direct payment order status changes.
4561
+ * When this returns `true`, TypeScript narrows the type to {@link PaymentNotification}.
4562
+ *
4563
+ * @param {AnyWebhookNotification} notification - Notification to check
4564
+ * @returns {boolean} `true` if payment notification
4565
+ *
4566
+ * @example
4567
+ * if (isPaymentNotification(notification)) {
4568
+ * // TypeScript knows this is PaymentNotification
4569
+ * const { orderStatus, acquiringOrderId } = notification.result;
4570
+ * console.log(`Order ${acquiringOrderId}: ${orderStatus}`);
4571
+ * }
4572
+ *
4573
+ * @see {@link PaymentNotification} for the notification structure
4574
+ */
4575
+ declare function isPaymentNotification(notification: AnyWebhookNotification): notification is PaymentNotification;
4576
+ /**
4577
+ * Type guard: checks if notification is a refund notification.
4578
+ *
4579
+ * Refund notifications are sent when a refund order status changes.
4580
+ * When this returns `true`, TypeScript narrows the type to {@link RefundNotification}.
4581
+ *
4582
+ * @param {AnyWebhookNotification} notification - Notification to check
4583
+ * @returns {boolean} `true` if refund notification
4584
+ *
4585
+ * @example
4586
+ * if (isRefundNotification(notification)) {
4587
+ * // TypeScript knows this is RefundNotification
4588
+ * const { refundStatus, refundAmount } = notification.result;
4589
+ * console.log(`Refund status: ${refundStatus}, amount: ${refundAmount}`);
4590
+ * }
4591
+ *
4592
+ * @see {@link RefundNotification} for the notification structure
4593
+ */
4594
+ declare function isRefundNotification(notification: AnyWebhookNotification): notification is RefundNotification;
4595
+ /**
4596
+ * Type guard: checks if notification is a subscription status notification.
4597
+ *
4598
+ * Subscription status notifications are sent when subscription status changes
4599
+ * (ACTIVE, MERCHANT_CANCELLED, CHANNEL_CANCELLED, EXPIRED).
4600
+ * When this returns `true`, TypeScript narrows the type to {@link SubscriptionStatusNotification}.
4601
+ *
4602
+ * @param {AnyWebhookNotification} notification - Notification to check
4603
+ * @returns {boolean} `true` if subscription status notification
4604
+ *
4605
+ * @example
4606
+ * if (isSubscriptionStatusNotification(notification)) {
4607
+ * // TypeScript knows this is SubscriptionStatusNotification
4608
+ * const { subscriptionStatus, subscriptionId } = notification.result;
4609
+ * console.log(`Subscription ${subscriptionId}: ${subscriptionStatus}`);
4610
+ * }
4611
+ *
4612
+ * @see {@link SubscriptionStatusNotification} for the notification structure
4613
+ */
4614
+ declare function isSubscriptionStatusNotification(notification: AnyWebhookNotification): notification is SubscriptionStatusNotification;
4615
+ /**
4616
+ * Type guard: checks if notification is a subscription payment notification.
4617
+ *
4618
+ * Subscription payment notifications are sent when a recurring payment is processed.
4619
+ * **Note:** Uses the same `PAYMENT_NOTIFICATION` event type as regular payments,
4620
+ * but includes `subscriptionId` in the result to distinguish them.
4621
+ *
4622
+ * When this returns `true`, TypeScript narrows the type to {@link SubscriptionPaymentNotification}.
4623
+ *
4624
+ * @param {AnyWebhookNotification} notification - Notification to check
4625
+ * @returns {boolean} `true` if subscription payment notification
4626
+ *
4627
+ * @example
4628
+ * if (isSubscriptionPaymentNotification(notification)) {
4629
+ * // TypeScript knows this is SubscriptionPaymentNotification
4630
+ * const { orderStatus, subscriptionInfo } = notification.result;
4631
+ * console.log(`Period ${subscriptionInfo.period}: ${orderStatus}`);
4632
+ * }
4633
+ *
4634
+ * @see {@link SubscriptionPaymentNotification} for the notification structure
4635
+ * @see {@link isPaymentNotification} for regular payment notifications
4636
+ */
4637
+ declare function isSubscriptionPaymentNotification(notification: AnyWebhookNotification): notification is SubscriptionPaymentNotification;
4638
+
4639
+ export { type AddressInfo, type AddressInfoResponse, type AnyWebhookNotification, type ApiResponse, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, CaptureMode, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CashierAppearance, CashierLanguage, CountryCode, type CreateOrderData, type CreateOrderParams, type CreateRefundData, type CreateSubscriptionData, type CreateSubscriptionParams, CurrencyCode, Environment, EnvironmentPublicKeys, EnvironmentUrls, type FixedMaintenanceRule, type GoodsInfo, type GoodsInfoResponse, HttpClient, HttpStatusCode, type InquiryOrderData, type InquiryOrderParams, type InquiryRefundData, type InquirySubscriptionData, type InquirySubscriptionParams, type KeyPair, type ManageSubscriptionData, type ManageSubscriptionParams, type MerchantConfigInquiryData, type MerchantConfigInquiryParams, type MerchantInfo, type MerchantInfoResponse, MerchantInitiatedMode, type OrderAction, type OrderActionData, OrderActionType, type OrderFailedReason, OrderStatus, type PayMethodConfigInquiryData, type PayMethodConfigInquiryParams, type PayMethodDetail, type PayMethodProperties, type PayMethodResponse, PayMethodUserAccountType, type PaymentDetail, type PaymentInfo, type PaymentInfoResponse, type PaymentNotification, type PaymentNotificationHandler, type PaymentNotificationResult, type PaymentWebhookRequest, PeriodType, type ProductInfo, type ProductInfoResponse, ProductName, type RefundFailedReason, type RefundInquiryParams, type RefundNotification, type RefundNotificationHandler, type RefundNotificationResult, type RefundOrderParams, RefundStatus, type RefundUserBankInfo, type RefundUserInfo, type RefundUserInfoResponse, type RefundWebhookRequest, type RequestOptions, type RiskData, type SubscriptionAction, type SubscriptionAddressInfo, SubscriptionEventType, type SubscriptionFailedReason, type SubscriptionGoodsInfo, type SubscriptionInfo, type SubscriptionMerchantInfo, type SubscriptionNotification, SubscriptionOrderStatus, type SubscriptionPayMethodResponse, SubscriptionPayMethodUserAccountType, type SubscriptionPaymentInfo, type SubscriptionPaymentInfoResponse, type SubscriptionPaymentNotification, type SubscriptionPaymentNotificationHandler, type SubscriptionPaymentNotificationResult, type SubscriptionPaymentWebhookRequest, SubscriptionProductName, type SubscriptionRiskData, SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionStatusNotificationHandler, type SubscriptionStatusNotificationResult, type SubscriptionStatusWebhookRequest, type SubscriptionUserInfo, SubscriptionUserTerminalType, type SubscriptionWebhookRequest, ThreeDsDecision, type UserBankInfo, type UserInfo, type UserInfoResponse, UserTerminalType, Waffo, type WaffoApiResponse, type WaffoConfig, type WaffoResponseBody, type WaffoResponseHeader, type WebhookErrorHandler, WebhookEventType, WebhookHandler, type WebhookHandlerContext, type WebhookHandlerOptions, type WebhookHandlerResult, type WebhookRequestHeader, type WebhookResponse, type WebhookResponseBody, type WebhookResponseHeader, WebhookResponseStatus, type WebhookVerificationResult, buildFailedResponse, buildSuccessResponse, buildWebhookResponse, createKeyPair, getWebhookEventType, isPaymentNotification, isRefundNotification, isSubscriptionPaymentNotification, isSubscriptionStatusNotification, signForRSA, verify, verifyWebhookSignature };