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