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