@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.
package/dist/index.js ADDED
@@ -0,0 +1,1795 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
8
+
9
+ // src/types/config.ts
10
+ var Environment = /* @__PURE__ */ ((Environment2) => {
11
+ Environment2["SANDBOX"] = "sandbox";
12
+ Environment2["PRODUCTION"] = "production";
13
+ return Environment2;
14
+ })(Environment || {});
15
+ var EnvironmentUrls = {
16
+ ["sandbox" /* SANDBOX */]: "https://api-sandbox.waffo.com/api/v1",
17
+ ["production" /* PRODUCTION */]: "https://api.waffo.com/api/v1"
18
+ };
19
+ var EnvironmentPublicKeys = {
20
+ ["sandbox" /* SANDBOX */]: "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhAbK3dBDZdCaX/5cqlO8EYYL4M4DyigqAMoIaT6R0SuSENu279dHZ3JiS8JukHx/xg85T9S3wDNwnu8KDypcwi8TxNQKgBE4czgAJ5GFEdJ+jtUS1dK46gjJFUnUlavb3uMLJJ0xZZKH0B5GtKOq75MwHWtXLK3zQrPqZosXqdgZhfbV+7bXlQaABdPlqif/ybN1DRrvcWmNVLAgsRiQvu4QnDOTMafzrSsF5tf8Ud3gK+JhcJs50NsXLPZZSc6NryZoH++xmz8atp0dOrBKmsJkZRWjrH+aXDZZT1sZDlgsKBMoRPf6F+lztFOPerrhSE81Y5MFaAp8R/QicMGCPueLhlebjx1OF0oowUD9b7ggZ8LiYpaR4HT9OmDpsu6NMN7zNG81qo7vnKCyy//xdOkpr4bQsm581r312y1UUjaYTZTlqAe+qbGZmZ7zS+ra0uwS6zLoZOY1ToOwlJbTwRPx2epweJcRnJVueiS1fPxaAlQz+tuVtIGONmZ836aHAgMBAAE=",
21
+ ["production" /* PRODUCTION */]: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqVHKdn76r6IhRXxWihdy+AiG0tzVR8LjDXC+0WFdTkn05Ga7ZS0WC3MRpxgRsbBWDlEVZYPUBdrtAmQeZYD7rwKSKSTdd62eZxehDI8DCzNhxppbeMPBhMn72eQvB/RQl1qhP7HLZx9IyTC7EbWWO0zhhomzf0hQ2K7KXDFq9bSYdBGAzSg+kOQFP2eifON8qm4TuwlxNSdTcgRWa8cRwy9h9aLra1iaeFRx9k68KxIcK0ZiGbD6KiR1a2NtZuxjB6bTJ7N/ydfKqQY+wB1CTWIlvouW1qajYYGBAcde9JN6o6CiWz3sPt42312CF3+k+gQeiuofdXkzVlMryVivfwIDAQAB"
22
+ };
23
+
24
+ // src/types/network.ts
25
+ var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
26
+ HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
27
+ HttpStatusCode2[HttpStatusCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
28
+ HttpStatusCode2[HttpStatusCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
29
+ HttpStatusCode2[HttpStatusCode2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
30
+ HttpStatusCode2[HttpStatusCode2["FORBIDDEN"] = 403] = "FORBIDDEN";
31
+ HttpStatusCode2[HttpStatusCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
32
+ HttpStatusCode2[HttpStatusCode2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
33
+ HttpStatusCode2[HttpStatusCode2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
34
+ HttpStatusCode2[HttpStatusCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
35
+ HttpStatusCode2[HttpStatusCode2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
36
+ HttpStatusCode2[HttpStatusCode2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
37
+ HttpStatusCode2[HttpStatusCode2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
38
+ HttpStatusCode2[HttpStatusCode2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
39
+ return HttpStatusCode2;
40
+ })(HttpStatusCode || {});
41
+
42
+ // src/types/webhook.ts
43
+ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
44
+ WebhookEventType2["PAYMENT_NOTIFICATION"] = "PAYMENT_NOTIFICATION";
45
+ WebhookEventType2["REFUND_NOTIFICATION"] = "REFUND_NOTIFICATION";
46
+ WebhookEventType2["SUBSCRIPTION_STATUS_NOTIFICATION"] = "SUBSCRIPTION_STATUS_NOTIFICATION";
47
+ return WebhookEventType2;
48
+ })(WebhookEventType || {});
49
+ var WebhookResponseStatus = /* @__PURE__ */ ((WebhookResponseStatus2) => {
50
+ WebhookResponseStatus2["SUCCESS"] = "success";
51
+ WebhookResponseStatus2["FAILED"] = "failed";
52
+ WebhookResponseStatus2["UNKNOWN"] = "unknown";
53
+ return WebhookResponseStatus2;
54
+ })(WebhookResponseStatus || {});
55
+
56
+ // src/types/iso.ts
57
+ var CountryCode = /* @__PURE__ */ ((CountryCode2) => {
58
+ CountryCode2["AFG"] = "AFG";
59
+ CountryCode2["ALB"] = "ALB";
60
+ CountryCode2["DZA"] = "DZA";
61
+ CountryCode2["ASM"] = "ASM";
62
+ CountryCode2["AND"] = "AND";
63
+ CountryCode2["AGO"] = "AGO";
64
+ CountryCode2["AIA"] = "AIA";
65
+ CountryCode2["ATA"] = "ATA";
66
+ CountryCode2["ATG"] = "ATG";
67
+ CountryCode2["ARG"] = "ARG";
68
+ CountryCode2["ARM"] = "ARM";
69
+ CountryCode2["ABW"] = "ABW";
70
+ CountryCode2["AUS"] = "AUS";
71
+ CountryCode2["AUT"] = "AUT";
72
+ CountryCode2["AZE"] = "AZE";
73
+ CountryCode2["BHS"] = "BHS";
74
+ CountryCode2["BHR"] = "BHR";
75
+ CountryCode2["BGD"] = "BGD";
76
+ CountryCode2["BRB"] = "BRB";
77
+ CountryCode2["BLR"] = "BLR";
78
+ CountryCode2["BEL"] = "BEL";
79
+ CountryCode2["BLZ"] = "BLZ";
80
+ CountryCode2["BEN"] = "BEN";
81
+ CountryCode2["BMU"] = "BMU";
82
+ CountryCode2["BTN"] = "BTN";
83
+ CountryCode2["BOL"] = "BOL";
84
+ CountryCode2["BES"] = "BES";
85
+ CountryCode2["BIH"] = "BIH";
86
+ CountryCode2["BWA"] = "BWA";
87
+ CountryCode2["BVT"] = "BVT";
88
+ CountryCode2["BRA"] = "BRA";
89
+ CountryCode2["IOT"] = "IOT";
90
+ CountryCode2["BRN"] = "BRN";
91
+ CountryCode2["BGR"] = "BGR";
92
+ CountryCode2["BFA"] = "BFA";
93
+ CountryCode2["BDI"] = "BDI";
94
+ CountryCode2["CPV"] = "CPV";
95
+ CountryCode2["KHM"] = "KHM";
96
+ CountryCode2["CMR"] = "CMR";
97
+ CountryCode2["CAN"] = "CAN";
98
+ CountryCode2["CYM"] = "CYM";
99
+ CountryCode2["CAF"] = "CAF";
100
+ CountryCode2["TCD"] = "TCD";
101
+ CountryCode2["CHL"] = "CHL";
102
+ CountryCode2["CHN"] = "CHN";
103
+ CountryCode2["CXR"] = "CXR";
104
+ CountryCode2["CCK"] = "CCK";
105
+ CountryCode2["COL"] = "COL";
106
+ CountryCode2["COM"] = "COM";
107
+ CountryCode2["COD"] = "COD";
108
+ CountryCode2["COG"] = "COG";
109
+ CountryCode2["COK"] = "COK";
110
+ CountryCode2["CRI"] = "CRI";
111
+ CountryCode2["HRV"] = "HRV";
112
+ CountryCode2["CUB"] = "CUB";
113
+ CountryCode2["CUW"] = "CUW";
114
+ CountryCode2["CYP"] = "CYP";
115
+ CountryCode2["CZE"] = "CZE";
116
+ CountryCode2["CIV"] = "CIV";
117
+ CountryCode2["DNK"] = "DNK";
118
+ CountryCode2["DJI"] = "DJI";
119
+ CountryCode2["DMA"] = "DMA";
120
+ CountryCode2["DOM"] = "DOM";
121
+ CountryCode2["ECU"] = "ECU";
122
+ CountryCode2["EGY"] = "EGY";
123
+ CountryCode2["SLV"] = "SLV";
124
+ CountryCode2["GNQ"] = "GNQ";
125
+ CountryCode2["ERI"] = "ERI";
126
+ CountryCode2["EST"] = "EST";
127
+ CountryCode2["SWZ"] = "SWZ";
128
+ CountryCode2["ETH"] = "ETH";
129
+ CountryCode2["FLK"] = "FLK";
130
+ CountryCode2["FRO"] = "FRO";
131
+ CountryCode2["FJI"] = "FJI";
132
+ CountryCode2["FIN"] = "FIN";
133
+ CountryCode2["FRA"] = "FRA";
134
+ CountryCode2["GUF"] = "GUF";
135
+ CountryCode2["PYF"] = "PYF";
136
+ CountryCode2["ATF"] = "ATF";
137
+ CountryCode2["GAB"] = "GAB";
138
+ CountryCode2["GMB"] = "GMB";
139
+ CountryCode2["GEO"] = "GEO";
140
+ CountryCode2["DEU"] = "DEU";
141
+ CountryCode2["GHA"] = "GHA";
142
+ CountryCode2["GIB"] = "GIB";
143
+ CountryCode2["GRC"] = "GRC";
144
+ CountryCode2["GRL"] = "GRL";
145
+ CountryCode2["GRD"] = "GRD";
146
+ CountryCode2["GLP"] = "GLP";
147
+ CountryCode2["GUM"] = "GUM";
148
+ CountryCode2["GTM"] = "GTM";
149
+ CountryCode2["GGY"] = "GGY";
150
+ CountryCode2["GIN"] = "GIN";
151
+ CountryCode2["GNB"] = "GNB";
152
+ CountryCode2["GUY"] = "GUY";
153
+ CountryCode2["HTI"] = "HTI";
154
+ CountryCode2["HMD"] = "HMD";
155
+ CountryCode2["VAT"] = "VAT";
156
+ CountryCode2["HND"] = "HND";
157
+ CountryCode2["HKG"] = "HKG";
158
+ CountryCode2["HUN"] = "HUN";
159
+ CountryCode2["ISL"] = "ISL";
160
+ CountryCode2["IND"] = "IND";
161
+ CountryCode2["IDN"] = "IDN";
162
+ CountryCode2["IRN"] = "IRN";
163
+ CountryCode2["IRQ"] = "IRQ";
164
+ CountryCode2["IRL"] = "IRL";
165
+ CountryCode2["IMN"] = "IMN";
166
+ CountryCode2["ISR"] = "ISR";
167
+ CountryCode2["ITA"] = "ITA";
168
+ CountryCode2["JAM"] = "JAM";
169
+ CountryCode2["JPN"] = "JPN";
170
+ CountryCode2["JEY"] = "JEY";
171
+ CountryCode2["JOR"] = "JOR";
172
+ CountryCode2["KAZ"] = "KAZ";
173
+ CountryCode2["KEN"] = "KEN";
174
+ CountryCode2["KIR"] = "KIR";
175
+ CountryCode2["PRK"] = "PRK";
176
+ CountryCode2["KOR"] = "KOR";
177
+ CountryCode2["KWT"] = "KWT";
178
+ CountryCode2["KGZ"] = "KGZ";
179
+ CountryCode2["LAO"] = "LAO";
180
+ CountryCode2["LVA"] = "LVA";
181
+ CountryCode2["LBN"] = "LBN";
182
+ CountryCode2["LSO"] = "LSO";
183
+ CountryCode2["LBR"] = "LBR";
184
+ CountryCode2["LBY"] = "LBY";
185
+ CountryCode2["LIE"] = "LIE";
186
+ CountryCode2["LTU"] = "LTU";
187
+ CountryCode2["LUX"] = "LUX";
188
+ CountryCode2["MAC"] = "MAC";
189
+ CountryCode2["MDG"] = "MDG";
190
+ CountryCode2["MWI"] = "MWI";
191
+ CountryCode2["MYS"] = "MYS";
192
+ CountryCode2["MDV"] = "MDV";
193
+ CountryCode2["MLI"] = "MLI";
194
+ CountryCode2["MLT"] = "MLT";
195
+ CountryCode2["MHL"] = "MHL";
196
+ CountryCode2["MTQ"] = "MTQ";
197
+ CountryCode2["MRT"] = "MRT";
198
+ CountryCode2["MUS"] = "MUS";
199
+ CountryCode2["MYT"] = "MYT";
200
+ CountryCode2["MEX"] = "MEX";
201
+ CountryCode2["FSM"] = "FSM";
202
+ CountryCode2["MDA"] = "MDA";
203
+ CountryCode2["MCO"] = "MCO";
204
+ CountryCode2["MNG"] = "MNG";
205
+ CountryCode2["MNE"] = "MNE";
206
+ CountryCode2["MSR"] = "MSR";
207
+ CountryCode2["MAR"] = "MAR";
208
+ CountryCode2["MOZ"] = "MOZ";
209
+ CountryCode2["MMR"] = "MMR";
210
+ CountryCode2["NAM"] = "NAM";
211
+ CountryCode2["NRU"] = "NRU";
212
+ CountryCode2["NPL"] = "NPL";
213
+ CountryCode2["NLD"] = "NLD";
214
+ CountryCode2["NCL"] = "NCL";
215
+ CountryCode2["NZL"] = "NZL";
216
+ CountryCode2["NIC"] = "NIC";
217
+ CountryCode2["NER"] = "NER";
218
+ CountryCode2["NGA"] = "NGA";
219
+ CountryCode2["NIU"] = "NIU";
220
+ CountryCode2["NFK"] = "NFK";
221
+ CountryCode2["MKD"] = "MKD";
222
+ CountryCode2["MNP"] = "MNP";
223
+ CountryCode2["NOR"] = "NOR";
224
+ CountryCode2["OMN"] = "OMN";
225
+ CountryCode2["PAK"] = "PAK";
226
+ CountryCode2["PLW"] = "PLW";
227
+ CountryCode2["PSE"] = "PSE";
228
+ CountryCode2["PAN"] = "PAN";
229
+ CountryCode2["PNG"] = "PNG";
230
+ CountryCode2["PRY"] = "PRY";
231
+ CountryCode2["PER"] = "PER";
232
+ CountryCode2["PHL"] = "PHL";
233
+ CountryCode2["PCN"] = "PCN";
234
+ CountryCode2["POL"] = "POL";
235
+ CountryCode2["PRT"] = "PRT";
236
+ CountryCode2["PRI"] = "PRI";
237
+ CountryCode2["QAT"] = "QAT";
238
+ CountryCode2["ROU"] = "ROU";
239
+ CountryCode2["RUS"] = "RUS";
240
+ CountryCode2["RWA"] = "RWA";
241
+ CountryCode2["REU"] = "REU";
242
+ CountryCode2["BLM"] = "BLM";
243
+ CountryCode2["SHN"] = "SHN";
244
+ CountryCode2["KNA"] = "KNA";
245
+ CountryCode2["LCA"] = "LCA";
246
+ CountryCode2["MAF"] = "MAF";
247
+ CountryCode2["SPM"] = "SPM";
248
+ CountryCode2["VCT"] = "VCT";
249
+ CountryCode2["WSM"] = "WSM";
250
+ CountryCode2["SMR"] = "SMR";
251
+ CountryCode2["STP"] = "STP";
252
+ CountryCode2["SAU"] = "SAU";
253
+ CountryCode2["SEN"] = "SEN";
254
+ CountryCode2["SRB"] = "SRB";
255
+ CountryCode2["SYC"] = "SYC";
256
+ CountryCode2["SLE"] = "SLE";
257
+ CountryCode2["SGP"] = "SGP";
258
+ CountryCode2["SXM"] = "SXM";
259
+ CountryCode2["SVK"] = "SVK";
260
+ CountryCode2["SVN"] = "SVN";
261
+ CountryCode2["SLB"] = "SLB";
262
+ CountryCode2["SOM"] = "SOM";
263
+ CountryCode2["ZAF"] = "ZAF";
264
+ CountryCode2["SGS"] = "SGS";
265
+ CountryCode2["SSD"] = "SSD";
266
+ CountryCode2["ESP"] = "ESP";
267
+ CountryCode2["LKA"] = "LKA";
268
+ CountryCode2["SDN"] = "SDN";
269
+ CountryCode2["SUR"] = "SUR";
270
+ CountryCode2["SJM"] = "SJM";
271
+ CountryCode2["SWE"] = "SWE";
272
+ CountryCode2["CHE"] = "CHE";
273
+ CountryCode2["SYR"] = "SYR";
274
+ CountryCode2["TWN"] = "TWN";
275
+ CountryCode2["TJK"] = "TJK";
276
+ CountryCode2["TZA"] = "TZA";
277
+ CountryCode2["THA"] = "THA";
278
+ CountryCode2["TLS"] = "TLS";
279
+ CountryCode2["TGO"] = "TGO";
280
+ CountryCode2["TKL"] = "TKL";
281
+ CountryCode2["TON"] = "TON";
282
+ CountryCode2["TTO"] = "TTO";
283
+ CountryCode2["TUN"] = "TUN";
284
+ CountryCode2["TUR"] = "TUR";
285
+ CountryCode2["TKM"] = "TKM";
286
+ CountryCode2["TCA"] = "TCA";
287
+ CountryCode2["TUV"] = "TUV";
288
+ CountryCode2["UGA"] = "UGA";
289
+ CountryCode2["UKR"] = "UKR";
290
+ CountryCode2["ARE"] = "ARE";
291
+ CountryCode2["GBR"] = "GBR";
292
+ CountryCode2["UMI"] = "UMI";
293
+ CountryCode2["USA"] = "USA";
294
+ CountryCode2["URY"] = "URY";
295
+ CountryCode2["UZB"] = "UZB";
296
+ CountryCode2["VUT"] = "VUT";
297
+ CountryCode2["VEN"] = "VEN";
298
+ CountryCode2["VNM"] = "VNM";
299
+ CountryCode2["VGB"] = "VGB";
300
+ CountryCode2["VIR"] = "VIR";
301
+ CountryCode2["WLF"] = "WLF";
302
+ CountryCode2["ESH"] = "ESH";
303
+ CountryCode2["YEM"] = "YEM";
304
+ CountryCode2["ZMB"] = "ZMB";
305
+ CountryCode2["ZWE"] = "ZWE";
306
+ CountryCode2["ALA"] = "ALA";
307
+ return CountryCode2;
308
+ })(CountryCode || {});
309
+ var CurrencyCode = /* @__PURE__ */ ((CurrencyCode2) => {
310
+ CurrencyCode2["AED"] = "AED";
311
+ CurrencyCode2["AFN"] = "AFN";
312
+ CurrencyCode2["ALL"] = "ALL";
313
+ CurrencyCode2["AMD"] = "AMD";
314
+ CurrencyCode2["ANG"] = "ANG";
315
+ CurrencyCode2["AOA"] = "AOA";
316
+ CurrencyCode2["ARS"] = "ARS";
317
+ CurrencyCode2["AUD"] = "AUD";
318
+ CurrencyCode2["AWG"] = "AWG";
319
+ CurrencyCode2["AZN"] = "AZN";
320
+ CurrencyCode2["BAM"] = "BAM";
321
+ CurrencyCode2["BBD"] = "BBD";
322
+ CurrencyCode2["BDT"] = "BDT";
323
+ CurrencyCode2["BGN"] = "BGN";
324
+ CurrencyCode2["BHD"] = "BHD";
325
+ CurrencyCode2["BIF"] = "BIF";
326
+ CurrencyCode2["BMD"] = "BMD";
327
+ CurrencyCode2["BND"] = "BND";
328
+ CurrencyCode2["BOB"] = "BOB";
329
+ CurrencyCode2["BOV"] = "BOV";
330
+ CurrencyCode2["BRL"] = "BRL";
331
+ CurrencyCode2["BSD"] = "BSD";
332
+ CurrencyCode2["BTN"] = "BTN";
333
+ CurrencyCode2["BWP"] = "BWP";
334
+ CurrencyCode2["BYN"] = "BYN";
335
+ CurrencyCode2["BZD"] = "BZD";
336
+ CurrencyCode2["CAD"] = "CAD";
337
+ CurrencyCode2["CDF"] = "CDF";
338
+ CurrencyCode2["CHE"] = "CHE";
339
+ CurrencyCode2["CHF"] = "CHF";
340
+ CurrencyCode2["CHW"] = "CHW";
341
+ CurrencyCode2["CLF"] = "CLF";
342
+ CurrencyCode2["CLP"] = "CLP";
343
+ CurrencyCode2["CNY"] = "CNY";
344
+ CurrencyCode2["COP"] = "COP";
345
+ CurrencyCode2["COU"] = "COU";
346
+ CurrencyCode2["CRC"] = "CRC";
347
+ CurrencyCode2["CUC"] = "CUC";
348
+ CurrencyCode2["CUP"] = "CUP";
349
+ CurrencyCode2["CVE"] = "CVE";
350
+ CurrencyCode2["CZK"] = "CZK";
351
+ CurrencyCode2["DJF"] = "DJF";
352
+ CurrencyCode2["DKK"] = "DKK";
353
+ CurrencyCode2["DOP"] = "DOP";
354
+ CurrencyCode2["DZD"] = "DZD";
355
+ CurrencyCode2["EGP"] = "EGP";
356
+ CurrencyCode2["ERN"] = "ERN";
357
+ CurrencyCode2["ETB"] = "ETB";
358
+ CurrencyCode2["EUR"] = "EUR";
359
+ CurrencyCode2["FJD"] = "FJD";
360
+ CurrencyCode2["FKP"] = "FKP";
361
+ CurrencyCode2["GBP"] = "GBP";
362
+ CurrencyCode2["GEL"] = "GEL";
363
+ CurrencyCode2["GHS"] = "GHS";
364
+ CurrencyCode2["GIP"] = "GIP";
365
+ CurrencyCode2["GMD"] = "GMD";
366
+ CurrencyCode2["GNF"] = "GNF";
367
+ CurrencyCode2["GTQ"] = "GTQ";
368
+ CurrencyCode2["GYD"] = "GYD";
369
+ CurrencyCode2["HKD"] = "HKD";
370
+ CurrencyCode2["HNL"] = "HNL";
371
+ CurrencyCode2["HRK"] = "HRK";
372
+ CurrencyCode2["HTG"] = "HTG";
373
+ CurrencyCode2["HUF"] = "HUF";
374
+ CurrencyCode2["IDR"] = "IDR";
375
+ CurrencyCode2["ILS"] = "ILS";
376
+ CurrencyCode2["INR"] = "INR";
377
+ CurrencyCode2["IQD"] = "IQD";
378
+ CurrencyCode2["IRR"] = "IRR";
379
+ CurrencyCode2["ISK"] = "ISK";
380
+ CurrencyCode2["JMD"] = "JMD";
381
+ CurrencyCode2["JOD"] = "JOD";
382
+ CurrencyCode2["JPY"] = "JPY";
383
+ CurrencyCode2["KES"] = "KES";
384
+ CurrencyCode2["KGS"] = "KGS";
385
+ CurrencyCode2["KHR"] = "KHR";
386
+ CurrencyCode2["KMF"] = "KMF";
387
+ CurrencyCode2["KPW"] = "KPW";
388
+ CurrencyCode2["KRW"] = "KRW";
389
+ CurrencyCode2["KWD"] = "KWD";
390
+ CurrencyCode2["KYD"] = "KYD";
391
+ CurrencyCode2["KZT"] = "KZT";
392
+ CurrencyCode2["LAK"] = "LAK";
393
+ CurrencyCode2["LBP"] = "LBP";
394
+ CurrencyCode2["LKR"] = "LKR";
395
+ CurrencyCode2["LRD"] = "LRD";
396
+ CurrencyCode2["LSL"] = "LSL";
397
+ CurrencyCode2["LYD"] = "LYD";
398
+ CurrencyCode2["MAD"] = "MAD";
399
+ CurrencyCode2["MDL"] = "MDL";
400
+ CurrencyCode2["MGA"] = "MGA";
401
+ CurrencyCode2["MKD"] = "MKD";
402
+ CurrencyCode2["MMK"] = "MMK";
403
+ CurrencyCode2["MNT"] = "MNT";
404
+ CurrencyCode2["MOP"] = "MOP";
405
+ CurrencyCode2["MRU"] = "MRU";
406
+ CurrencyCode2["MUR"] = "MUR";
407
+ CurrencyCode2["MVR"] = "MVR";
408
+ CurrencyCode2["MWK"] = "MWK";
409
+ CurrencyCode2["MXN"] = "MXN";
410
+ CurrencyCode2["MXV"] = "MXV";
411
+ CurrencyCode2["MYR"] = "MYR";
412
+ CurrencyCode2["MZN"] = "MZN";
413
+ CurrencyCode2["NAD"] = "NAD";
414
+ CurrencyCode2["NGN"] = "NGN";
415
+ CurrencyCode2["NIO"] = "NIO";
416
+ CurrencyCode2["NOK"] = "NOK";
417
+ CurrencyCode2["NPR"] = "NPR";
418
+ CurrencyCode2["NZD"] = "NZD";
419
+ CurrencyCode2["OMR"] = "OMR";
420
+ CurrencyCode2["PAB"] = "PAB";
421
+ CurrencyCode2["PEN"] = "PEN";
422
+ CurrencyCode2["PGK"] = "PGK";
423
+ CurrencyCode2["PHP"] = "PHP";
424
+ CurrencyCode2["PKR"] = "PKR";
425
+ CurrencyCode2["PLN"] = "PLN";
426
+ CurrencyCode2["PYG"] = "PYG";
427
+ CurrencyCode2["QAR"] = "QAR";
428
+ CurrencyCode2["RON"] = "RON";
429
+ CurrencyCode2["RSD"] = "RSD";
430
+ CurrencyCode2["RUB"] = "RUB";
431
+ CurrencyCode2["RWF"] = "RWF";
432
+ CurrencyCode2["SAR"] = "SAR";
433
+ CurrencyCode2["SBD"] = "SBD";
434
+ CurrencyCode2["SCR"] = "SCR";
435
+ CurrencyCode2["SDG"] = "SDG";
436
+ CurrencyCode2["SEK"] = "SEK";
437
+ CurrencyCode2["SGD"] = "SGD";
438
+ CurrencyCode2["SHP"] = "SHP";
439
+ CurrencyCode2["SLE"] = "SLE";
440
+ CurrencyCode2["SLL"] = "SLL";
441
+ CurrencyCode2["SOS"] = "SOS";
442
+ CurrencyCode2["SRD"] = "SRD";
443
+ CurrencyCode2["SSP"] = "SSP";
444
+ CurrencyCode2["STN"] = "STN";
445
+ CurrencyCode2["SVC"] = "SVC";
446
+ CurrencyCode2["SYP"] = "SYP";
447
+ CurrencyCode2["SZL"] = "SZL";
448
+ CurrencyCode2["THB"] = "THB";
449
+ CurrencyCode2["TJS"] = "TJS";
450
+ CurrencyCode2["TMT"] = "TMT";
451
+ CurrencyCode2["TND"] = "TND";
452
+ CurrencyCode2["TOP"] = "TOP";
453
+ CurrencyCode2["TRY"] = "TRY";
454
+ CurrencyCode2["TTD"] = "TTD";
455
+ CurrencyCode2["TWD"] = "TWD";
456
+ CurrencyCode2["TZS"] = "TZS";
457
+ CurrencyCode2["UAH"] = "UAH";
458
+ CurrencyCode2["UGX"] = "UGX";
459
+ CurrencyCode2["USD"] = "USD";
460
+ CurrencyCode2["USN"] = "USN";
461
+ CurrencyCode2["UYI"] = "UYI";
462
+ CurrencyCode2["UYU"] = "UYU";
463
+ CurrencyCode2["UYW"] = "UYW";
464
+ CurrencyCode2["UZS"] = "UZS";
465
+ CurrencyCode2["VED"] = "VED";
466
+ CurrencyCode2["VES"] = "VES";
467
+ CurrencyCode2["VND"] = "VND";
468
+ CurrencyCode2["VUV"] = "VUV";
469
+ CurrencyCode2["WST"] = "WST";
470
+ CurrencyCode2["XAF"] = "XAF";
471
+ CurrencyCode2["XAG"] = "XAG";
472
+ CurrencyCode2["XAU"] = "XAU";
473
+ CurrencyCode2["XBA"] = "XBA";
474
+ CurrencyCode2["XBB"] = "XBB";
475
+ CurrencyCode2["XBC"] = "XBC";
476
+ CurrencyCode2["XBD"] = "XBD";
477
+ CurrencyCode2["XCD"] = "XCD";
478
+ CurrencyCode2["XDR"] = "XDR";
479
+ CurrencyCode2["XOF"] = "XOF";
480
+ CurrencyCode2["XPD"] = "XPD";
481
+ CurrencyCode2["XPF"] = "XPF";
482
+ CurrencyCode2["XPT"] = "XPT";
483
+ CurrencyCode2["XSU"] = "XSU";
484
+ CurrencyCode2["XTS"] = "XTS";
485
+ CurrencyCode2["XUA"] = "XUA";
486
+ CurrencyCode2["XXX"] = "XXX";
487
+ CurrencyCode2["YER"] = "YER";
488
+ CurrencyCode2["ZAR"] = "ZAR";
489
+ CurrencyCode2["ZMW"] = "ZMW";
490
+ CurrencyCode2["ZWL"] = "ZWL";
491
+ return CurrencyCode2;
492
+ })(CurrencyCode || {});
493
+
494
+ // src/types/payment.ts
495
+ var ProductName = /* @__PURE__ */ ((ProductName2) => {
496
+ ProductName2["ONE_TIME_PAYMENT"] = "ONE_TIME_PAYMENT";
497
+ ProductName2["MINI_PROGRAM_PAYMENT"] = "MINI_PROGRAM_PAYMENT";
498
+ ProductName2["DIRECT_PAYMENT"] = "DIRECT_PAYMENT";
499
+ return ProductName2;
500
+ })(ProductName || {});
501
+ var SubscriptionProductName = /* @__PURE__ */ ((SubscriptionProductName2) => {
502
+ SubscriptionProductName2["SUBSCRIPTION"] = "SUBSCRIPTION";
503
+ SubscriptionProductName2["MINI_PROGRAM_SUBSCRIPTION"] = "MINI_PROGRAM_SUBSCRIPTION";
504
+ return SubscriptionProductName2;
505
+ })(SubscriptionProductName || {});
506
+
507
+ // src/types/order.ts
508
+ var UserTerminalType = /* @__PURE__ */ ((UserTerminalType2) => {
509
+ UserTerminalType2["WEB"] = "WEB";
510
+ UserTerminalType2["APP"] = "APP";
511
+ UserTerminalType2["IN_WALLET_APP"] = "IN_WALLET_APP";
512
+ UserTerminalType2["IN_MINI_PROGRAM"] = "IN_MINI_PROGRAM";
513
+ return UserTerminalType2;
514
+ })(UserTerminalType || {});
515
+ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
516
+ OrderStatus2["PAY_IN_PROGRESS"] = "PAY_IN_PROGRESS";
517
+ OrderStatus2["AUTHORIZATION_REQUIRED"] = "AUTHORIZATION_REQUIRED";
518
+ OrderStatus2["AUTHED_WAITING_CAPTURE"] = "AUTHED_WAITING_CAPTURE";
519
+ OrderStatus2["PAY_SUCCESS"] = "PAY_SUCCESS";
520
+ OrderStatus2["ORDER_CLOSE"] = "ORDER_CLOSE";
521
+ OrderStatus2["CAPTURE_IN_PROGRESS"] = "CAPTURE_IN_PROGRESS";
522
+ return OrderStatus2;
523
+ })(OrderStatus || {});
524
+ var OrderActionType = /* @__PURE__ */ ((OrderActionType2) => {
525
+ OrderActionType2["WEB"] = "WEB";
526
+ OrderActionType2["DEEPLINK"] = "DEEPLINK";
527
+ return OrderActionType2;
528
+ })(OrderActionType || {});
529
+ var PayMethodUserAccountType = /* @__PURE__ */ ((PayMethodUserAccountType2) => {
530
+ PayMethodUserAccountType2["EMAIL"] = "EMAIL";
531
+ PayMethodUserAccountType2["PHONE_NO"] = "PHONE_NO";
532
+ PayMethodUserAccountType2["ACCOUNT_ID"] = "ACCOUNT_ID";
533
+ return PayMethodUserAccountType2;
534
+ })(PayMethodUserAccountType || {});
535
+ var CaptureMode = /* @__PURE__ */ ((CaptureMode2) => {
536
+ CaptureMode2["MANUAL_CAPTURE"] = "manualCapture";
537
+ return CaptureMode2;
538
+ })(CaptureMode || {});
539
+ var MerchantInitiatedMode = /* @__PURE__ */ ((MerchantInitiatedMode2) => {
540
+ MerchantInitiatedMode2["SCHEDULED"] = "scheduled";
541
+ MerchantInitiatedMode2["UNSCHEDULED"] = "unscheduled";
542
+ return MerchantInitiatedMode2;
543
+ })(MerchantInitiatedMode || {});
544
+ var ThreeDsDecision = /* @__PURE__ */ ((ThreeDsDecision2) => {
545
+ ThreeDsDecision2["FORCE"] = "3DS_FORCE";
546
+ ThreeDsDecision2["ATTEMPT"] = "3DS_ATTEMPT";
547
+ ThreeDsDecision2["NO_3DS"] = "NO_3DS";
548
+ return ThreeDsDecision2;
549
+ })(ThreeDsDecision || {});
550
+
551
+ // src/types/refund.ts
552
+ var RefundStatus = /* @__PURE__ */ ((RefundStatus2) => {
553
+ RefundStatus2["REFUND_IN_PROGRESS"] = "REFUND_IN_PROGRESS";
554
+ RefundStatus2["ORDER_PARTIALLY_REFUNDED"] = "ORDER_PARTIALLY_REFUNDED";
555
+ RefundStatus2["ORDER_FULLY_REFUNDED"] = "ORDER_FULLY_REFUNDED";
556
+ RefundStatus2["ORDER_REFUND_FAILED"] = "ORDER_REFUND_FAILED";
557
+ return RefundStatus2;
558
+ })(RefundStatus || {});
559
+
560
+ // src/types/subscription.ts
561
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
562
+ SubscriptionStatus2["AUTHORIZATION_REQUIRED"] = "AUTHORIZATION_REQUIRED";
563
+ SubscriptionStatus2["IN_PROGRESS"] = "IN_PROGRESS";
564
+ SubscriptionStatus2["ACTIVE"] = "ACTIVE";
565
+ SubscriptionStatus2["CLOSE"] = "CLOSE";
566
+ SubscriptionStatus2["MERCHANT_CANCELLED"] = "MERCHANT_CANCELLED";
567
+ SubscriptionStatus2["USER_CANCELLED"] = "USER_CANCELLED";
568
+ SubscriptionStatus2["CHANNEL_CANCELLED"] = "CHANNEL_CANCELLED";
569
+ SubscriptionStatus2["EXPIRED"] = "EXPIRED";
570
+ return SubscriptionStatus2;
571
+ })(SubscriptionStatus || {});
572
+ var PeriodType = /* @__PURE__ */ ((PeriodType2) => {
573
+ PeriodType2["DAILY"] = "DAILY";
574
+ PeriodType2["WEEKLY"] = "WEEKLY";
575
+ PeriodType2["MONTHLY"] = "MONTHLY";
576
+ return PeriodType2;
577
+ })(PeriodType || {});
578
+ var SubscriptionUserTerminalType = /* @__PURE__ */ ((SubscriptionUserTerminalType2) => {
579
+ SubscriptionUserTerminalType2["WEB"] = "WEB";
580
+ SubscriptionUserTerminalType2["APP"] = "APP";
581
+ return SubscriptionUserTerminalType2;
582
+ })(SubscriptionUserTerminalType || {});
583
+ var CashierLanguage = /* @__PURE__ */ ((CashierLanguage2) => {
584
+ CashierLanguage2["EN_HK"] = "en-HK";
585
+ CashierLanguage2["ZH_HANT_HK"] = "zh-Hant-HK";
586
+ CashierLanguage2["ZH_HANS_HK"] = "zh-Hans-HK";
587
+ return CashierLanguage2;
588
+ })(CashierLanguage || {});
589
+ var SubscriptionPayMethodUserAccountType = /* @__PURE__ */ ((SubscriptionPayMethodUserAccountType2) => {
590
+ SubscriptionPayMethodUserAccountType2["EMAIL"] = "EMAIL";
591
+ SubscriptionPayMethodUserAccountType2["PHONE_NO"] = "PHONE_NO";
592
+ SubscriptionPayMethodUserAccountType2["ACCOUNT_ID"] = "ACCOUNT_ID";
593
+ return SubscriptionPayMethodUserAccountType2;
594
+ })(SubscriptionPayMethodUserAccountType || {});
595
+ var SubscriptionOrderStatus = /* @__PURE__ */ ((SubscriptionOrderStatus2) => {
596
+ SubscriptionOrderStatus2["PAY_SUCCESS"] = "PAY_SUCCESS";
597
+ SubscriptionOrderStatus2["ORDER_CLOSE"] = "ORDER_CLOSE";
598
+ return SubscriptionOrderStatus2;
599
+ })(SubscriptionOrderStatus || {});
600
+ var SubscriptionEventType = /* @__PURE__ */ ((SubscriptionEventType2) => {
601
+ SubscriptionEventType2["SUBSCRIPTION_STATUS_NOTIFICATION"] = "SUBSCRIPTION_STATUS_NOTIFICATION";
602
+ SubscriptionEventType2["PAYMENT_NOTIFICATION"] = "PAYMENT_NOTIFICATION";
603
+ return SubscriptionEventType2;
604
+ })(SubscriptionEventType || {});
605
+ var SIGN_ALGORITHMS = "RSA-SHA256";
606
+ function signForRSA(body, privateKey, charSet = "utf8", onError) {
607
+ try {
608
+ const privateKeyDer = Buffer.from(privateKey, "base64");
609
+ const privateKeyPem = `-----BEGIN PRIVATE KEY-----
610
+ ${privateKeyDer.toString("base64").match(/.{1,64}/g)?.join("\n")}
611
+ -----END PRIVATE KEY-----`;
612
+ const signature = crypto__default.default.createSign(SIGN_ALGORITHMS);
613
+ signature.update(body, charSet);
614
+ const signed = signature.sign(privateKeyPem, "base64");
615
+ return signed;
616
+ } catch (e) {
617
+ onError?.(e instanceof Error ? e : new Error(String(e)));
618
+ return null;
619
+ }
620
+ }
621
+ function verify(body, sign, publicKey, charSet = "utf8", onError) {
622
+ try {
623
+ const publicKeyDer = Buffer.from(publicKey, "base64");
624
+ const publicKeyPem = `-----BEGIN PUBLIC KEY-----
625
+ ${publicKeyDer.toString("base64").match(/.{1,64}/g)?.join("\n")}
626
+ -----END PUBLIC KEY-----`;
627
+ const verifier = crypto__default.default.createVerify(SIGN_ALGORITHMS);
628
+ verifier.update(body, charSet);
629
+ const signatureBuffer = Buffer.from(sign, "base64");
630
+ return verifier.verify(publicKeyPem, signatureBuffer);
631
+ } catch (e) {
632
+ onError?.(e instanceof Error ? e : new Error(String(e)));
633
+ return false;
634
+ }
635
+ }
636
+ function createKeyPair() {
637
+ const { publicKey, privateKey } = crypto__default.default.generateKeyPairSync("rsa", {
638
+ modulusLength: 2048,
639
+ publicKeyEncoding: {
640
+ type: "spki",
641
+ format: "der"
642
+ },
643
+ privateKeyEncoding: {
644
+ type: "pkcs8",
645
+ format: "der"
646
+ }
647
+ });
648
+ const keyMap = {
649
+ PRIVATE_KEY_NAME: privateKey.toString("base64"),
650
+ PUBLIC_KEY_NAME: publicKey.toString("base64")
651
+ };
652
+ return keyMap;
653
+ }
654
+
655
+ // src/utils/webhook.ts
656
+ function verifyWebhookSignature(requestBody, signature, waffoPublicKey) {
657
+ try {
658
+ const isValid = verify(requestBody, signature, waffoPublicKey);
659
+ if (!isValid) {
660
+ return {
661
+ isValid: false,
662
+ error: "Signature verification failed"
663
+ };
664
+ }
665
+ const notification = JSON.parse(requestBody);
666
+ const eventType = notification.eventType;
667
+ return {
668
+ isValid: true,
669
+ notification,
670
+ eventType
671
+ };
672
+ } catch (error) {
673
+ return {
674
+ isValid: false,
675
+ error: `Failed to verify webhook: ${error.message}`
676
+ };
677
+ }
678
+ }
679
+ function buildWebhookResponse(status, merchantPrivateKey) {
680
+ const body = {
681
+ message: status
682
+ };
683
+ const bodyString = JSON.stringify(body);
684
+ const signature = signForRSA(bodyString, merchantPrivateKey);
685
+ if (!signature) {
686
+ throw new Error("Failed to sign webhook response");
687
+ }
688
+ return {
689
+ header: {
690
+ "Content-Type": "application/json",
691
+ "X-SIGNATURE": signature
692
+ },
693
+ body
694
+ };
695
+ }
696
+ function buildSuccessResponse(merchantPrivateKey) {
697
+ return buildWebhookResponse(
698
+ "success" /* SUCCESS */,
699
+ merchantPrivateKey
700
+ );
701
+ }
702
+ function buildFailedResponse(merchantPrivateKey) {
703
+ return buildWebhookResponse("failed" /* FAILED */, merchantPrivateKey);
704
+ }
705
+ function getWebhookEventType(notification) {
706
+ try {
707
+ const parsed = typeof notification === "string" ? JSON.parse(notification) : notification;
708
+ return parsed.eventType;
709
+ } catch {
710
+ return void 0;
711
+ }
712
+ }
713
+ function isPaymentNotification(notification) {
714
+ return notification.eventType === "PAYMENT_NOTIFICATION" /* PAYMENT_NOTIFICATION */;
715
+ }
716
+ function isRefundNotification(notification) {
717
+ return notification.eventType === "REFUND_NOTIFICATION" /* REFUND_NOTIFICATION */;
718
+ }
719
+ function isSubscriptionStatusNotification(notification) {
720
+ return notification.eventType === "SUBSCRIPTION_STATUS_NOTIFICATION" /* SUBSCRIPTION_STATUS_NOTIFICATION */;
721
+ }
722
+ function isSubscriptionPaymentNotification(notification) {
723
+ return notification.eventType === "PAYMENT_NOTIFICATION" /* PAYMENT_NOTIFICATION */ && "subscriptionId" in notification.result;
724
+ }
725
+
726
+ // src/core/httpClient.ts
727
+ var HttpClient = class {
728
+ /**
729
+ * Creates an HTTP client instance with the provided SDK configuration.
730
+ *
731
+ * Resolves environment-specific settings such as API base URL and public key.
732
+ *
733
+ * @param {WaffoConfig} config - Waffo SDK configuration object
734
+ * @param {string} config.apiKey - API key assigned by Waffo
735
+ * @param {string} config.privateKey - Merchant private key (Base64 encoded PKCS8 DER)
736
+ * @param {string} [config.waffoPublicKey] - Waffo public key for response verification
737
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment
738
+ * @param {number} [config.timeout=30000] - Request timeout in milliseconds
739
+ * @param {Logger} [config.logger] - Logger instance for debugging
740
+ *
741
+ * @example
742
+ * const client = new HttpClient({
743
+ * apiKey: 'your-api-key',
744
+ * privateKey: 'your-private-key',
745
+ * environment: Environment.SANDBOX,
746
+ * });
747
+ *
748
+ * @see {@link WaffoConfig} for configuration options
749
+ */
750
+ constructor(config) {
751
+ const environment = config.environment || "production" /* PRODUCTION */;
752
+ this.config = {
753
+ apiKey: config.apiKey,
754
+ privateKey: config.privateKey,
755
+ waffoPublicKey: config.waffoPublicKey || EnvironmentPublicKeys[environment],
756
+ baseUrl: EnvironmentUrls[environment],
757
+ timeout: config.timeout || 3e4,
758
+ logger: config.logger
759
+ };
760
+ this.config.logger?.debug("[Waffo SDK] HttpClient initialized", {
761
+ environment,
762
+ baseUrl: this.config.baseUrl,
763
+ timeout: this.config.timeout
764
+ });
765
+ }
766
+ /**
767
+ * Generates an RSA-SHA256 signature for the request body.
768
+ *
769
+ * @param {string} payload - Request body string to sign (JSON serialized)
770
+ * @returns {string} Base64 encoded RSA-SHA256 signature
771
+ * @throws {Error} "Failed to generate RSA signature" when signing fails
772
+ * @private
773
+ */
774
+ generateSignature(payload) {
775
+ const signature = signForRSA(payload, this.config.privateKey);
776
+ if (!signature) {
777
+ throw new Error("Failed to generate RSA signature");
778
+ }
779
+ return signature;
780
+ }
781
+ /**
782
+ * Verifies the RSA-SHA256 signature of the response body.
783
+ *
784
+ * Ensures the response has not been tampered with during transmission.
785
+ *
786
+ * @param {string} responseBody - Response body string (raw JSON)
787
+ * @param {string} signature - X-SIGNATURE header value (Base64 encoded)
788
+ * @returns {boolean} `true` if signature is valid, `false` otherwise
789
+ * @private
790
+ */
791
+ verifyResponseSignature(responseBody, signature) {
792
+ return verify(responseBody, signature, this.config.waffoPublicKey);
793
+ }
794
+ /**
795
+ * Sends an HTTP POST request with automatic signing and verification.
796
+ *
797
+ * **Request Flow:**
798
+ * 1. Serializes the request body to JSON
799
+ * 2. Signs the request body using RSA-SHA256
800
+ * 3. Sends the request with X-API-KEY and X-SIGNATURE headers
801
+ * 4. Verifies the response signature using Waffo's public key
802
+ * 5. Parses and returns the response in standardized format
803
+ *
804
+ * **Error Handling:**
805
+ * - Network errors: `{ success: false, error: message }`
806
+ * - Timeout: status code 408 (REQUEST_TIMEOUT)
807
+ * - Invalid signature: returns error
808
+ * - Business errors (code !== "0"): parsed and returned as errors
809
+ *
810
+ * @template T - Expected response data type
811
+ * @template B - Request body type (must extend object)
812
+ *
813
+ * @param {string} endpoint - API endpoint path (e.g., '/order/create')
814
+ * @param {RequestOptions<B>} [options={}] - Request options
815
+ * @param {B} [options.body] - Request body object (will be JSON serialized)
816
+ * @param {Record<string, string>} [options.headers] - Additional request headers
817
+ *
818
+ * @returns {Promise<ApiResponse<T>>} Response object with success status and data/error
819
+ *
820
+ * @example
821
+ * // Make a POST request
822
+ * const result = await httpClient.post<CreateOrderData>('/order/create', {
823
+ * body: {
824
+ * paymentRequestId: 'req-123',
825
+ * merchantOrderId: 'order-456',
826
+ * // ... other fields
827
+ * },
828
+ * });
829
+ *
830
+ * if (result.success) {
831
+ * console.log('Order created:', result.data.acquiringOrderId);
832
+ * } else {
833
+ * console.error('Error:', result.error);
834
+ * }
835
+ *
836
+ * @example
837
+ * // Handle timeout errors
838
+ * const result = await httpClient.post('/order/create', { body: params });
839
+ * if (!result.success && result.statusCode === HttpStatusCode.REQUEST_TIMEOUT) {
840
+ * console.log('Request timed out, please retry');
841
+ * }
842
+ *
843
+ * @see {@link ApiResponse} for the response format
844
+ * @see {@link RequestOptions} for request options
845
+ */
846
+ async post(endpoint, options = {}) {
847
+ const { body, headers = {} } = options;
848
+ const payload = body ? JSON.stringify(body) : "";
849
+ const signature = this.generateSignature(payload);
850
+ const url = `${this.config.baseUrl}${endpoint}`;
851
+ this.config.logger?.debug("[Waffo SDK] Sending request", {
852
+ method: "POST",
853
+ url,
854
+ body
855
+ });
856
+ const controller = new AbortController();
857
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
858
+ try {
859
+ const response = await fetch(url, {
860
+ method: "POST",
861
+ headers: {
862
+ "Content-Type": "application/json",
863
+ "X-API-KEY": this.config.apiKey,
864
+ "X-SIGNATURE": signature,
865
+ ...headers
866
+ },
867
+ body: payload || void 0,
868
+ signal: controller.signal
869
+ });
870
+ clearTimeout(timeoutId);
871
+ const statusCode = response.status;
872
+ const responseSignature = response.headers.get("X-SIGNATURE");
873
+ const responseBody = await response.text();
874
+ this.config.logger?.debug("[Waffo SDK] Received response", {
875
+ statusCode,
876
+ hasSignature: !!responseSignature,
877
+ body: responseBody
878
+ });
879
+ if (!responseSignature) {
880
+ this.config.logger?.warn(
881
+ "[Waffo SDK] Missing X-SIGNATURE in response headers"
882
+ );
883
+ return {
884
+ success: false,
885
+ statusCode,
886
+ error: "Missing X-SIGNATURE in response headers"
887
+ };
888
+ }
889
+ const isValid = this.verifyResponseSignature(
890
+ responseBody,
891
+ responseSignature
892
+ );
893
+ if (!isValid) {
894
+ this.config.logger?.warn("[Waffo SDK] Invalid response signature");
895
+ return {
896
+ success: false,
897
+ statusCode,
898
+ error: "Invalid response signature"
899
+ };
900
+ }
901
+ let parsedBody = null;
902
+ try {
903
+ parsedBody = JSON.parse(responseBody);
904
+ } catch {
905
+ }
906
+ const isWaffoFormat = (body2) => {
907
+ return body2 !== null && typeof body2 === "object" && "code" in body2;
908
+ };
909
+ if (!response.ok) {
910
+ const errorMsg = isWaffoFormat(parsedBody) && parsedBody.msg ? `[${parsedBody.code}] ${parsedBody.msg}` : `HTTP ${response.status}: ${response.statusText}`;
911
+ this.config.logger?.error("[Waffo SDK] HTTP error", {
912
+ statusCode,
913
+ error: errorMsg
914
+ });
915
+ return {
916
+ success: false,
917
+ statusCode,
918
+ error: errorMsg
919
+ };
920
+ }
921
+ if (isWaffoFormat(parsedBody) && parsedBody.code && parsedBody.code !== "0") {
922
+ const errorMsg = `[${parsedBody.code}] ${parsedBody.msg || "Unknown error"}`;
923
+ this.config.logger?.error("[Waffo SDK] Business error", {
924
+ code: parsedBody.code,
925
+ msg: parsedBody.msg
926
+ });
927
+ return {
928
+ success: false,
929
+ statusCode,
930
+ error: errorMsg
931
+ };
932
+ }
933
+ const data = isWaffoFormat(parsedBody) ? parsedBody.data : parsedBody;
934
+ this.config.logger?.debug("[Waffo SDK] Request successful", { data });
935
+ return { success: true, statusCode, data };
936
+ } catch (error) {
937
+ clearTimeout(timeoutId);
938
+ if (error instanceof Error && error.name === "AbortError") {
939
+ this.config.logger?.error("[Waffo SDK] Request timeout", {
940
+ timeout: this.config.timeout,
941
+ url
942
+ });
943
+ return {
944
+ success: false,
945
+ statusCode: 408 /* REQUEST_TIMEOUT */,
946
+ error: `Request timeout after ${this.config.timeout}ms`
947
+ };
948
+ }
949
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
950
+ this.config.logger?.error("[Waffo SDK] Request failed", {
951
+ error: errorMessage,
952
+ url
953
+ });
954
+ return {
955
+ success: false,
956
+ statusCode: 500 /* INTERNAL_SERVER_ERROR */,
957
+ error: errorMessage
958
+ };
959
+ }
960
+ }
961
+ };
962
+
963
+ // src/core/webhook.ts
964
+ var WebhookHandler = class {
965
+ /**
966
+ * Creates a webhook handler instance.
967
+ *
968
+ * Initializes the handler with SDK configuration and resolves
969
+ * environment-specific settings such as Waffo's public key.
970
+ *
971
+ * @param {WaffoConfig} config - Waffo SDK configuration object
972
+ * @param {string} config.privateKey - Merchant private key (Base64 encoded PKCS8 DER)
973
+ * @param {string} [config.waffoPublicKey] - Waffo public key for request verification
974
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment
975
+ *
976
+ * @example
977
+ * // Typically created automatically by Waffo SDK
978
+ * const waffo = new Waffo(config);
979
+ * // Access via: waffo.webhook
980
+ *
981
+ * @see {@link WaffoConfig} for configuration options
982
+ */
983
+ constructor(config) {
984
+ const environment = config.environment || "production" /* PRODUCTION */;
985
+ this.config = {
986
+ privateKey: config.privateKey,
987
+ waffoPublicKey: config.waffoPublicKey || EnvironmentPublicKeys[environment]
988
+ };
989
+ }
990
+ /**
991
+ * Processes an incoming webhook notification from Waffo.
992
+ *
993
+ * **Processing Flow:**
994
+ * 1. Verifies the request signature using Waffo's public key
995
+ * 2. Parses the notification and determines its type
996
+ * 3. Routes to the appropriate handler based on event type
997
+ * 4. Returns a signed response to acknowledge receipt
998
+ *
999
+ * **Supported Event Types:**
1000
+ * - `PAYMENT_NOTIFICATION` - Payment order status changes
1001
+ * - `REFUND_NOTIFICATION` - Refund status changes
1002
+ * - `SUBSCRIPTION_STATUS_NOTIFICATION` - Subscription status changes
1003
+ * - `PAYMENT_NOTIFICATION` with subscriptionId - Subscription payments
1004
+ *
1005
+ * @param {string} requestBody - Raw request body string (JSON)
1006
+ * @param {string} signature - X-SIGNATURE header value from Waffo
1007
+ * @param {WebhookHandlerOptions} options - Handler configuration options
1008
+ *
1009
+ * @returns {Promise<WebhookHandlerResult>} Result with success status and signed response
1010
+ *
1011
+ * @example
1012
+ * // Express.js endpoint
1013
+ * app.post('/webhook', async (req, res) => {
1014
+ * const result = await waffo.webhook.handle(
1015
+ * JSON.stringify(req.body),
1016
+ * req.headers['x-signature'],
1017
+ * {
1018
+ * onPayment: async ({ notification }) => {
1019
+ * const { orderStatus, acquiringOrderId } = notification.result;
1020
+ * await db.orders.updateStatus(acquiringOrderId, orderStatus);
1021
+ * },
1022
+ * onRefund: async ({ notification }) => {
1023
+ * const { refundStatus } = notification.result;
1024
+ * await db.refunds.update(notification.result);
1025
+ * },
1026
+ * onSubscriptionStatus: async ({ notification }) => {
1027
+ * await db.subscriptions.update(notification.result);
1028
+ * },
1029
+ * onSubscriptionPayment: async ({ notification }) => {
1030
+ * await db.payments.create(notification.result);
1031
+ * },
1032
+ * onError: async (error) => {
1033
+ * logger.error('Webhook error', error);
1034
+ * },
1035
+ * }
1036
+ * );
1037
+ *
1038
+ * // Return signed response to Waffo
1039
+ * res.set(result.response.header).json(result.response.body);
1040
+ * });
1041
+ *
1042
+ * @example
1043
+ * // Next.js API route
1044
+ * export async function POST(request: Request) {
1045
+ * const body = await request.text();
1046
+ * const signature = request.headers.get('x-signature') || '';
1047
+ *
1048
+ * const result = await waffo.webhook.handle(body, signature, {
1049
+ * onPayment: async (ctx) => { ... },
1050
+ * });
1051
+ *
1052
+ * return new Response(JSON.stringify(result.response.body), {
1053
+ * headers: result.response.header,
1054
+ * });
1055
+ * }
1056
+ *
1057
+ * @see {@link WebhookHandlerOptions} for handler configuration
1058
+ * @see {@link WebhookHandlerResult} for return type
1059
+ */
1060
+ async handle(requestBody, signature, options = {}) {
1061
+ const {
1062
+ onPayment,
1063
+ onRefund,
1064
+ onSubscriptionStatus,
1065
+ onSubscriptionPayment,
1066
+ onError
1067
+ } = options;
1068
+ try {
1069
+ const verificationResult = verifyWebhookSignature(
1070
+ requestBody,
1071
+ signature,
1072
+ this.config.waffoPublicKey
1073
+ );
1074
+ if (!verificationResult.isValid) {
1075
+ const error = new Error(
1076
+ verificationResult.error || "Signature verification failed"
1077
+ );
1078
+ await onError?.(error);
1079
+ return {
1080
+ success: false,
1081
+ response: buildWebhookResponse(
1082
+ "failed" /* FAILED */,
1083
+ this.config.privateKey
1084
+ ),
1085
+ error: verificationResult.error
1086
+ };
1087
+ }
1088
+ const { notification, eventType } = verificationResult;
1089
+ if (!notification || !eventType) {
1090
+ const error = new Error("Invalid notification format");
1091
+ await onError?.(error);
1092
+ return {
1093
+ success: false,
1094
+ response: buildWebhookResponse(
1095
+ "failed" /* FAILED */,
1096
+ this.config.privateKey
1097
+ ),
1098
+ error: "Invalid notification format"
1099
+ };
1100
+ }
1101
+ if (isSubscriptionPaymentNotification(notification)) {
1102
+ await onSubscriptionPayment?.({
1103
+ notification,
1104
+ rawBody: requestBody,
1105
+ eventType
1106
+ });
1107
+ } else if (isPaymentNotification(notification)) {
1108
+ await onPayment?.({
1109
+ notification,
1110
+ rawBody: requestBody,
1111
+ eventType
1112
+ });
1113
+ } else if (isRefundNotification(notification)) {
1114
+ await onRefund?.({
1115
+ notification,
1116
+ rawBody: requestBody,
1117
+ eventType
1118
+ });
1119
+ } else if (isSubscriptionStatusNotification(notification)) {
1120
+ await onSubscriptionStatus?.({
1121
+ notification,
1122
+ rawBody: requestBody,
1123
+ eventType
1124
+ });
1125
+ }
1126
+ return {
1127
+ success: true,
1128
+ response: buildWebhookResponse(
1129
+ "success" /* SUCCESS */,
1130
+ this.config.privateKey
1131
+ )
1132
+ };
1133
+ } catch (error) {
1134
+ const err = error instanceof Error ? error : new Error(String(error));
1135
+ await onError?.(err);
1136
+ return {
1137
+ success: false,
1138
+ response: buildWebhookResponse(
1139
+ "failed" /* FAILED */,
1140
+ this.config.privateKey
1141
+ ),
1142
+ error: err.message
1143
+ };
1144
+ }
1145
+ }
1146
+ };
1147
+
1148
+ // src/resources/base.ts
1149
+ var BaseResource = class {
1150
+ /**
1151
+ * Initializes the base resource with HTTP client and base path.
1152
+ *
1153
+ * @param {HttpClient} client - HTTP client instance
1154
+ * @param {string} basePath - Base path for API endpoints
1155
+ * @protected
1156
+ */
1157
+ constructor(client, basePath) {
1158
+ this.client = client;
1159
+ this.basePath = basePath;
1160
+ }
1161
+ };
1162
+
1163
+ // src/resources/order/resource.ts
1164
+ var OrderResource = class extends BaseResource {
1165
+ /**
1166
+ * Creates an Order resource instance.
1167
+ * @param {HttpClient} client - HTTP client instance
1168
+ */
1169
+ constructor(client) {
1170
+ super(client, "/order");
1171
+ }
1172
+ /**
1173
+ * Creates a new payment order.
1174
+ *
1175
+ * Supports multiple payment methods including e-wallet, credit card,
1176
+ * bank transfer, and more.
1177
+ *
1178
+ * @param {CreateOrderParams} params - Order creation parameters
1179
+ * @returns {Promise<ApiResponse<CreateOrderData>>} Order creation result
1180
+ *
1181
+ * @example
1182
+ * const result = await waffo.order.create({
1183
+ * paymentRequestId: 'req-' + Date.now(),
1184
+ * merchantOrderId: 'order-456',
1185
+ * orderCurrency: 'IDR',
1186
+ * orderAmount: '100000',
1187
+ * orderDescription: 'Product purchase',
1188
+ * merchantInfo: { merchantId: 'M001' },
1189
+ * userInfo: {
1190
+ * userId: 'U001',
1191
+ * userEmail: 'user@example.com',
1192
+ * userTerminal: 'WEB',
1193
+ * },
1194
+ * goodsInfo: {
1195
+ * goodsName: 'Premium Plan',
1196
+ * goodsUrl: 'https://example.com/product',
1197
+ * },
1198
+ * paymentInfo: {
1199
+ * productName: 'ONE_TIME_PAYMENT',
1200
+ * payMethodName: 'DANA',
1201
+ * },
1202
+ * notifyUrl: 'https://example.com/webhook',
1203
+ * successRedirectUrl: 'https://example.com/success',
1204
+ * });
1205
+ *
1206
+ * if (result.success) {
1207
+ * // Redirect user to payment page
1208
+ * const redirectUrl = result.data.orderAction?.webUrl;
1209
+ * }
1210
+ *
1211
+ * @see {@link CreateOrderParams} for all available parameters
1212
+ */
1213
+ async create(params) {
1214
+ const body = {
1215
+ ...params,
1216
+ orderRequestedAt: params.orderRequestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1217
+ };
1218
+ return this.client.post(
1219
+ `${this.basePath}/create`,
1220
+ { body }
1221
+ );
1222
+ }
1223
+ /**
1224
+ * Queries current order status and details.
1225
+ *
1226
+ * Provide either `paymentRequestId` or `acquiringOrderId` to identify the order.
1227
+ *
1228
+ * @param {InquiryOrderParams} params - Query parameters
1229
+ * @returns {Promise<ApiResponse<InquiryOrderData>>} Order details
1230
+ *
1231
+ * @example
1232
+ * // Query by acquiring order ID
1233
+ * const result = await waffo.order.inquiry({
1234
+ * acquiringOrderId: 'ACQ123456789',
1235
+ * });
1236
+ *
1237
+ * if (result.success) {
1238
+ * console.log('Order status:', result.data.orderStatus);
1239
+ * console.log('Amount:', result.data.orderAmount, result.data.orderCurrency);
1240
+ * }
1241
+ *
1242
+ * @example
1243
+ * // Query by payment request ID
1244
+ * const result = await waffo.order.inquiry({
1245
+ * paymentRequestId: 'req-123',
1246
+ * });
1247
+ *
1248
+ * @see {@link InquiryOrderData} for response structure
1249
+ */
1250
+ async inquiry(params) {
1251
+ return this.client.post(
1252
+ `${this.basePath}/inquiry`,
1253
+ { body: params }
1254
+ );
1255
+ }
1256
+ /**
1257
+ * Cancels an unpaid order.
1258
+ *
1259
+ * Only orders with status `AUTHORIZATION_REQUIRED` or `PAY_IN_PROGRESS` can be canceled.
1260
+ *
1261
+ * @param {CancelOrderParams} params - Cancel parameters
1262
+ * @returns {Promise<ApiResponse<CancelOrderData>>} Cancellation result
1263
+ *
1264
+ * @example
1265
+ * const result = await waffo.order.cancel({
1266
+ * acquiringOrderId: 'ACQ123456789',
1267
+ * merchantId: 'M001',
1268
+ * });
1269
+ *
1270
+ * if (result.success) {
1271
+ * console.log('Order canceled:', result.data.orderStatus);
1272
+ * // => 'ORDER_CLOSE'
1273
+ * }
1274
+ *
1275
+ * @see {@link CancelOrderData} for response structure
1276
+ */
1277
+ async cancel(params) {
1278
+ const body = {
1279
+ ...params,
1280
+ orderRequestedAt: params.orderRequestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1281
+ };
1282
+ return this.client.post(
1283
+ `${this.basePath}/cancel`,
1284
+ { body }
1285
+ );
1286
+ }
1287
+ /**
1288
+ * Initiates a refund request for a paid order.
1289
+ *
1290
+ * Supports both full and partial refunds. Multiple partial refunds can be
1291
+ * made until the total refunded amount equals the original order amount.
1292
+ *
1293
+ * @param {RefundOrderParams} params - Refund parameters
1294
+ * @returns {Promise<ApiResponse<CreateRefundData>>} Refund request result
1295
+ *
1296
+ * @example
1297
+ * // Full refund
1298
+ * const result = await waffo.order.refund({
1299
+ * refundRequestId: 'refund-' + Date.now(),
1300
+ * acquiringOrderId: 'ACQ123456789',
1301
+ * merchantId: 'M001',
1302
+ * refundAmount: '100000',
1303
+ * refundReason: 'Customer request',
1304
+ * refundNotifyUrl: 'https://example.com/refund-webhook',
1305
+ * });
1306
+ *
1307
+ * if (result.success) {
1308
+ * console.log('Refund status:', result.data.refundStatus);
1309
+ * console.log('Remaining refundable:', result.data.remainingRefundAmount);
1310
+ * }
1311
+ *
1312
+ * @example
1313
+ * // Partial refund
1314
+ * const result = await waffo.order.refund({
1315
+ * refundRequestId: 'refund-partial-123',
1316
+ * acquiringOrderId: 'ACQ123456789',
1317
+ * merchantId: 'M001',
1318
+ * refundAmount: '50000', // Partial amount
1319
+ * refundReason: 'Partial refund',
1320
+ * });
1321
+ *
1322
+ * @see {@link CreateRefundData} for response structure
1323
+ */
1324
+ async refund(params) {
1325
+ const body = {
1326
+ ...params,
1327
+ requestedAt: params.requestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1328
+ };
1329
+ return this.client.post(
1330
+ `${this.basePath}/refund`,
1331
+ { body }
1332
+ );
1333
+ }
1334
+ /**
1335
+ * Captures an authorized payment (manualCapture mode only).
1336
+ *
1337
+ * Converts an authorization to an actual charge. Supports both
1338
+ * partial and full capture amounts.
1339
+ *
1340
+ * @param {CaptureOrderParams} params - Capture parameters
1341
+ * @returns {Promise<ApiResponse<CaptureOrderData>>} Capture result
1342
+ *
1343
+ * @example
1344
+ * // Full capture
1345
+ * const result = await waffo.order.capture({
1346
+ * acquiringOrderId: 'ACQ123456789',
1347
+ * merchantId: 'M001',
1348
+ * captureAmount: '100000', // Full authorized amount
1349
+ * });
1350
+ *
1351
+ * if (result.success) {
1352
+ * console.log('Capture status:', result.data.orderStatus);
1353
+ * }
1354
+ *
1355
+ * @example
1356
+ * // Partial capture
1357
+ * const result = await waffo.order.capture({
1358
+ * acquiringOrderId: 'ACQ123456789',
1359
+ * merchantId: 'M001',
1360
+ * captureAmount: '75000', // Capture less than authorized
1361
+ * });
1362
+ *
1363
+ * @see {@link CaptureOrderData} for response structure
1364
+ */
1365
+ async capture(params) {
1366
+ const body = {
1367
+ ...params,
1368
+ captureRequestedAt: params.captureRequestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1369
+ };
1370
+ return this.client.post(
1371
+ `${this.basePath}/capture`,
1372
+ { body }
1373
+ );
1374
+ }
1375
+ };
1376
+
1377
+ // src/resources/refund/resource.ts
1378
+ var RefundResource = class extends BaseResource {
1379
+ /**
1380
+ * Creates a Refund resource instance.
1381
+ * @param {HttpClient} client - HTTP client instance
1382
+ */
1383
+ constructor(client) {
1384
+ super(client, "/refund");
1385
+ }
1386
+ /**
1387
+ * Queries current refund status and details.
1388
+ *
1389
+ * Provide either `refundRequestId` or `acquiringRefundOrderId` to identify the refund.
1390
+ *
1391
+ * @param {RefundInquiryParams} params - Query parameters
1392
+ * @returns {Promise<ApiResponse<InquiryRefundData>>} Refund details
1393
+ *
1394
+ * @example
1395
+ * // Query by refund request ID
1396
+ * const result = await waffo.refund.inquiry({
1397
+ * refundRequestId: 'refund-123',
1398
+ * });
1399
+ *
1400
+ * if (result.success) {
1401
+ * const { refundStatus, refundAmount, remainingRefundAmount } = result.data;
1402
+ * console.log(`Status: ${refundStatus}`);
1403
+ * console.log(`Refunded: ${refundAmount}`);
1404
+ * console.log(`Remaining: ${remainingRefundAmount}`);
1405
+ * }
1406
+ *
1407
+ * @example
1408
+ * // Query by acquiring refund order ID
1409
+ * const result = await waffo.refund.inquiry({
1410
+ * acquiringRefundOrderId: 'REF123456789',
1411
+ * });
1412
+ *
1413
+ * @see {@link InquiryRefundData} for response structure
1414
+ */
1415
+ async inquiry(params) {
1416
+ return this.client.post(
1417
+ `${this.basePath}/inquiry`,
1418
+ { body: params }
1419
+ );
1420
+ }
1421
+ };
1422
+
1423
+ // src/resources/subscription/resource.ts
1424
+ var SubscriptionResource = class extends BaseResource {
1425
+ /**
1426
+ * Creates a Subscription resource instance.
1427
+ * @param {HttpClient} client - HTTP client instance
1428
+ */
1429
+ constructor(client) {
1430
+ super(client, "/subscription");
1431
+ }
1432
+ /**
1433
+ * Creates a new subscription signing request for recurring payments.
1434
+ *
1435
+ * After creation, redirect the user to the signing URL to authorize
1436
+ * the recurring payment agreement.
1437
+ *
1438
+ * @param {CreateSubscriptionParams} params - Subscription creation parameters
1439
+ * @returns {Promise<ApiResponse<CreateSubscriptionData>>} Subscription creation result
1440
+ *
1441
+ * @example
1442
+ * const result = await waffo.subscription.create({
1443
+ * subscriptionRequest: 'sub-' + Date.now(),
1444
+ * currency: 'HKD',
1445
+ * amount: '99.00',
1446
+ * productInfo: {
1447
+ * description: 'Premium Monthly Plan',
1448
+ * periodType: 'MONTHLY',
1449
+ * periodInterval: '1',
1450
+ * numberOfPeriod: '12', // 12 months
1451
+ * },
1452
+ * merchantInfo: { merchantId: 'M001' },
1453
+ * userInfo: {
1454
+ * userId: 'U001',
1455
+ * userEmail: 'user@example.com',
1456
+ * },
1457
+ * goodsInfo: {
1458
+ * goodsId: 'PREMIUM-PLAN',
1459
+ * goodsName: 'Premium Plan',
1460
+ * goodsUrl: 'https://example.com/plan',
1461
+ * },
1462
+ * paymentInfo: {
1463
+ * productName: 'SUBSCRIPTION',
1464
+ * payMethodName: 'ALIPAY_HK',
1465
+ * },
1466
+ * notifyUrl: 'https://example.com/webhook',
1467
+ * successRedirectUrl: 'https://example.com/success',
1468
+ * });
1469
+ *
1470
+ * if (result.success) {
1471
+ * // Redirect user to subscription signing page
1472
+ * const signingUrl = result.data.subscriptionAction?.webUrl;
1473
+ * }
1474
+ *
1475
+ * @see {@link CreateSubscriptionData} for response structure
1476
+ */
1477
+ async create(params) {
1478
+ const body = {
1479
+ ...params,
1480
+ requestedAt: params.requestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1481
+ };
1482
+ return this.client.post(
1483
+ `${this.basePath}/create`,
1484
+ { body }
1485
+ );
1486
+ }
1487
+ /**
1488
+ * Queries subscription details and optionally payment history.
1489
+ *
1490
+ * @param {InquirySubscriptionParams} params - Query parameters
1491
+ * @returns {Promise<ApiResponse<InquirySubscriptionData>>} Subscription details
1492
+ *
1493
+ * @example
1494
+ * // Query subscription status
1495
+ * const result = await waffo.subscription.inquiry({
1496
+ * subscriptionId: 'SUB123456789',
1497
+ * });
1498
+ *
1499
+ * if (result.success) {
1500
+ * console.log('Status:', result.data.subscriptionStatus);
1501
+ * console.log('Next payment:', result.data.productInfo.nextPaymentDateTime);
1502
+ * }
1503
+ *
1504
+ * @example
1505
+ * // Query with payment history
1506
+ * const result = await waffo.subscription.inquiry({
1507
+ * subscriptionId: 'SUB123456789',
1508
+ * paymentDetails: '1', // Include payment history
1509
+ * });
1510
+ *
1511
+ * if (result.success && result.data.paymentDetails) {
1512
+ * result.data.paymentDetails.forEach(payment => {
1513
+ * console.log(`Period ${payment.period}: ${payment.orderStatus}`);
1514
+ * });
1515
+ * }
1516
+ *
1517
+ * @see {@link InquirySubscriptionData} for response structure
1518
+ */
1519
+ async inquiry(params) {
1520
+ return this.client.post(
1521
+ `${this.basePath}/inquiry`,
1522
+ { body: params }
1523
+ );
1524
+ }
1525
+ /**
1526
+ * Cancels an active subscription.
1527
+ *
1528
+ * Once canceled, no further recurring payments will be processed.
1529
+ *
1530
+ * @param {CancelSubscriptionParams} params - Cancel parameters
1531
+ * @returns {Promise<ApiResponse<CancelSubscriptionData>>} Cancellation result
1532
+ *
1533
+ * @example
1534
+ * const result = await waffo.subscription.cancel({
1535
+ * subscriptionId: 'SUB123456789',
1536
+ * merchantId: 'M001',
1537
+ * });
1538
+ *
1539
+ * if (result.success) {
1540
+ * console.log('Subscription canceled:', result.data.orderStatus);
1541
+ * // => 'MERCHANT_CANCELLED'
1542
+ * }
1543
+ *
1544
+ * @see {@link CancelSubscriptionData} for response structure
1545
+ */
1546
+ async cancel(params) {
1547
+ const body = {
1548
+ ...params,
1549
+ requestedAt: params.requestedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1550
+ };
1551
+ return this.client.post(
1552
+ `${this.basePath}/cancel`,
1553
+ { body }
1554
+ );
1555
+ }
1556
+ /**
1557
+ * Generates a temporary management URL for users to manage their subscription.
1558
+ *
1559
+ * The URL allows users to view subscription details and cancel if needed.
1560
+ * The URL expires after a certain period (check `expiredAt` in response).
1561
+ *
1562
+ * @param {ManageSubscriptionParams} params - Management parameters
1563
+ * @returns {Promise<ApiResponse<ManageSubscriptionData>>} Management URL and expiration
1564
+ *
1565
+ * @example
1566
+ * const result = await waffo.subscription.manage({
1567
+ * subscriptionId: 'SUB123456789',
1568
+ * });
1569
+ *
1570
+ * if (result.success) {
1571
+ * console.log('Management URL:', result.data.managementUrl);
1572
+ * console.log('Expires at:', result.data.expiredAt);
1573
+ * // Send URL to user via email or display in app
1574
+ * }
1575
+ *
1576
+ * @see {@link ManageSubscriptionData} for response structure
1577
+ */
1578
+ async manage(params) {
1579
+ return this.client.post(
1580
+ `${this.basePath}/manage`,
1581
+ { body: params }
1582
+ );
1583
+ }
1584
+ };
1585
+
1586
+ // src/resources/merchantconfig/resource.ts
1587
+ var MerchantConfigResource = class extends BaseResource {
1588
+ /**
1589
+ * Creates a Merchant Config resource instance.
1590
+ * @param {HttpClient} client - HTTP client instance
1591
+ */
1592
+ constructor(client) {
1593
+ super(client, "/merchantconfig");
1594
+ }
1595
+ /**
1596
+ * Queries merchant configuration including transaction limits.
1597
+ *
1598
+ * @param {MerchantConfigInquiryParams} params - Query parameters
1599
+ * @returns {Promise<ApiResponse<MerchantConfigInquiryData>>} Merchant configuration
1600
+ *
1601
+ * @example
1602
+ * const result = await waffo.merchantConfig.inquiry({
1603
+ * merchantId: 'M001',
1604
+ * });
1605
+ *
1606
+ * if (result.success) {
1607
+ * const { totalDailyLimit, remainingDailyLimit, transactionLimit } = result.data;
1608
+ *
1609
+ * // Limits are returned as currency -> value maps
1610
+ * console.log('Daily limit (USD):', totalDailyLimit?.['USD']);
1611
+ * console.log('Remaining (USD):', remainingDailyLimit?.['USD']);
1612
+ * console.log('Per transaction (USD):', transactionLimit?.['USD']);
1613
+ * }
1614
+ *
1615
+ * @see {@link MerchantConfigInquiryData} for response structure
1616
+ */
1617
+ async inquiry(params) {
1618
+ return this.client.post(`${this.basePath}/inquiry`, { body: params });
1619
+ }
1620
+ };
1621
+
1622
+ // src/resources/paymethodconfig/resource.ts
1623
+ var PayMethodConfigResource = class extends BaseResource {
1624
+ /**
1625
+ * Creates a Pay Method Config resource instance.
1626
+ * @param {HttpClient} client - HTTP client instance
1627
+ */
1628
+ constructor(client) {
1629
+ super(client, "/paymethodconfig");
1630
+ }
1631
+ /**
1632
+ * Queries available payment methods and their status.
1633
+ *
1634
+ * @param {PayMethodConfigInquiryParams} params - Query parameters
1635
+ * @returns {Promise<ApiResponse<PayMethodConfigInquiryData>>} Payment method details
1636
+ *
1637
+ * @example
1638
+ * const result = await waffo.payMethodConfig.inquiry({
1639
+ * merchantId: 'M001',
1640
+ * });
1641
+ *
1642
+ * if (result.success) {
1643
+ * result.data.payMethodDetails.forEach(method => {
1644
+ * const status = method.currentStatus === '1' ? 'Available' : 'Unavailable';
1645
+ * console.log(`${method.payMethodName} (${method.country}): ${status}`);
1646
+ *
1647
+ * // Check maintenance windows
1648
+ * if (method.fixedMaintenanceRules?.length) {
1649
+ * console.log(' Maintenance:', method.fixedMaintenanceRules);
1650
+ * }
1651
+ * });
1652
+ * }
1653
+ *
1654
+ * @example
1655
+ * // Filter available e-wallet methods
1656
+ * const ewallets = result.data.payMethodDetails.filter(
1657
+ * m => m.currentStatus === '1' && m.productName === 'ONE_TIME_PAYMENT'
1658
+ * );
1659
+ *
1660
+ * @see {@link PayMethodConfigInquiryData} for response structure
1661
+ */
1662
+ async inquiry(params) {
1663
+ return this.client.post(`${this.basePath}/inquiry`, { body: params });
1664
+ }
1665
+ };
1666
+
1667
+ // src/core/waffo.ts
1668
+ var Waffo = class {
1669
+ /**
1670
+ * Creates a new Waffo SDK instance.
1671
+ *
1672
+ * Initializes the SDK with the provided configuration. The SDK automatically
1673
+ * selects the appropriate API endpoint and public key based on the environment.
1674
+ *
1675
+ * @param {WaffoConfig} config - SDK configuration object
1676
+ * @param {string} config.apiKey - API key assigned by Waffo (required)
1677
+ * @param {string} config.privateKey - Merchant private key, Base64 encoded PKCS8 DER format (required)
1678
+ * @param {string} [config.waffoPublicKey] - Waffo public key for response verification (optional)
1679
+ * @param {Environment} [config.environment=Environment.PRODUCTION] - API environment (optional)
1680
+ * @param {number} [config.timeout=30000] - Request timeout in milliseconds (optional)
1681
+ * @param {Logger} [config.logger] - Logger instance for debugging (optional)
1682
+ *
1683
+ * @throws {Error} When API key or private key is missing or invalid
1684
+ *
1685
+ * @example
1686
+ * // Production configuration
1687
+ * const waffo = new Waffo({
1688
+ * apiKey: process.env.WAFFO_API_KEY,
1689
+ * privateKey: process.env.WAFFO_PRIVATE_KEY,
1690
+ * environment: Environment.PRODUCTION,
1691
+ * });
1692
+ *
1693
+ * @example
1694
+ * // Sandbox configuration with debugging
1695
+ * const waffo = new Waffo({
1696
+ * apiKey: 'sandbox-api-key',
1697
+ * privateKey: 'sandbox-private-key',
1698
+ * environment: Environment.SANDBOX,
1699
+ * timeout: 60000,
1700
+ * logger: console,
1701
+ * });
1702
+ *
1703
+ * @see {@link WaffoConfig} for configuration options
1704
+ * @see {@link Environment} for available environments
1705
+ */
1706
+ constructor(config) {
1707
+ this.httpClient = new HttpClient(config);
1708
+ this.webhook = new WebhookHandler(config);
1709
+ this.order = new OrderResource(this.httpClient);
1710
+ this.refund = new RefundResource(this.httpClient);
1711
+ this.subscription = new SubscriptionResource(this.httpClient);
1712
+ this.merchantConfig = new MerchantConfigResource(this.httpClient);
1713
+ this.payMethodConfig = new PayMethodConfigResource(this.httpClient);
1714
+ }
1715
+ /**
1716
+ * Generates a new 2048-bit RSA key pair for API signing and verification.
1717
+ *
1718
+ * **Generated key formats:**
1719
+ * - Private key: Base64 encoded PKCS8 DER format (for signing requests)
1720
+ * - Public key: Base64 encoded X509/SPKI DER format (for verification)
1721
+ *
1722
+ * **Usage:**
1723
+ * 1. Generate a key pair using this method
1724
+ * 2. Register the public key with Waffo via merchant dashboard
1725
+ * 3. Store the private key securely on your server
1726
+ * 4. Use the private key when initializing the SDK
1727
+ *
1728
+ * @static
1729
+ * @returns {KeyPair} Object containing the generated key pair
1730
+ *
1731
+ * @example
1732
+ * // Generate a new key pair
1733
+ * const keys = Waffo.generateKeyPair();
1734
+ * console.log('Private Key:', keys.privateKey);
1735
+ * console.log('Public Key:', keys.publicKey);
1736
+ *
1737
+ * // Use the private key to initialize SDK
1738
+ * const waffo = new Waffo({
1739
+ * apiKey: 'your-api-key',
1740
+ * privateKey: keys.privateKey,
1741
+ * });
1742
+ *
1743
+ * @see {@link KeyPair} for the return type structure
1744
+ */
1745
+ static generateKeyPair() {
1746
+ const keys = createKeyPair();
1747
+ return {
1748
+ privateKey: keys.PRIVATE_KEY_NAME,
1749
+ publicKey: keys.PUBLIC_KEY_NAME
1750
+ };
1751
+ }
1752
+ };
1753
+
1754
+ exports.CaptureMode = CaptureMode;
1755
+ exports.CashierLanguage = CashierLanguage;
1756
+ exports.CountryCode = CountryCode;
1757
+ exports.CurrencyCode = CurrencyCode;
1758
+ exports.Environment = Environment;
1759
+ exports.EnvironmentPublicKeys = EnvironmentPublicKeys;
1760
+ exports.EnvironmentUrls = EnvironmentUrls;
1761
+ exports.HttpClient = HttpClient;
1762
+ exports.HttpStatusCode = HttpStatusCode;
1763
+ exports.MerchantInitiatedMode = MerchantInitiatedMode;
1764
+ exports.OrderActionType = OrderActionType;
1765
+ exports.OrderStatus = OrderStatus;
1766
+ exports.PayMethodUserAccountType = PayMethodUserAccountType;
1767
+ exports.PeriodType = PeriodType;
1768
+ exports.ProductName = ProductName;
1769
+ exports.RefundStatus = RefundStatus;
1770
+ exports.SubscriptionEventType = SubscriptionEventType;
1771
+ exports.SubscriptionOrderStatus = SubscriptionOrderStatus;
1772
+ exports.SubscriptionPayMethodUserAccountType = SubscriptionPayMethodUserAccountType;
1773
+ exports.SubscriptionProductName = SubscriptionProductName;
1774
+ exports.SubscriptionStatus = SubscriptionStatus;
1775
+ exports.SubscriptionUserTerminalType = SubscriptionUserTerminalType;
1776
+ exports.ThreeDsDecision = ThreeDsDecision;
1777
+ exports.UserTerminalType = UserTerminalType;
1778
+ exports.Waffo = Waffo;
1779
+ exports.WebhookEventType = WebhookEventType;
1780
+ exports.WebhookHandler = WebhookHandler;
1781
+ exports.WebhookResponseStatus = WebhookResponseStatus;
1782
+ exports.buildFailedResponse = buildFailedResponse;
1783
+ exports.buildSuccessResponse = buildSuccessResponse;
1784
+ exports.buildWebhookResponse = buildWebhookResponse;
1785
+ exports.createKeyPair = createKeyPair;
1786
+ exports.getWebhookEventType = getWebhookEventType;
1787
+ exports.isPaymentNotification = isPaymentNotification;
1788
+ exports.isRefundNotification = isRefundNotification;
1789
+ exports.isSubscriptionPaymentNotification = isSubscriptionPaymentNotification;
1790
+ exports.isSubscriptionStatusNotification = isSubscriptionStatusNotification;
1791
+ exports.signForRSA = signForRSA;
1792
+ exports.verify = verify;
1793
+ exports.verifyWebhookSignature = verifyWebhookSignature;
1794
+ //# sourceMappingURL=index.js.map
1795
+ //# sourceMappingURL=index.js.map