@waffo/waffo-node 2.4.0 → 2.5.1
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/README.md +12 -6
- package/dist/index.d.mts +252 -24
- package/dist/index.d.ts +252 -24
- package/dist/index.js +63 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ interface WaffoLogger {
|
|
|
119
119
|
interface WaffoConfig {
|
|
120
120
|
/** API key provided by Waffo */
|
|
121
121
|
apiKey: string;
|
|
122
|
-
/** Merchant's private key for signing requests (Base64
|
|
122
|
+
/** Merchant's private key for signing requests (Base64 PKCS8 DER or unencrypted PKCS8 PEM) */
|
|
123
123
|
privateKey: string;
|
|
124
124
|
/** Waffo's public key for verifying responses (Base64 encoded X509) */
|
|
125
125
|
waffoPublicKey: string;
|
|
@@ -213,6 +213,11 @@ interface CreateSubscriptionParams {
|
|
|
213
213
|
orderExpiredAt?: string;
|
|
214
214
|
addressInfo?: SubscriptionAddressInfo;
|
|
215
215
|
riskData?: SubscriptionRiskData;
|
|
216
|
+
brandInfo?: SubscriptionBrandInfo;
|
|
217
|
+
subscriptionMode?: string;
|
|
218
|
+
acqMerchant?: Record<string, unknown>;
|
|
219
|
+
acqProduct?: Record<string, unknown>;
|
|
220
|
+
acqAgreements?: Record<string, unknown>[];
|
|
216
221
|
[key: string]: unknown;
|
|
217
222
|
}
|
|
218
223
|
/**
|
|
@@ -233,7 +238,19 @@ interface CreateSubscriptionData {
|
|
|
233
238
|
interface InquirySubscriptionParams {
|
|
234
239
|
subscriptionRequest?: string;
|
|
235
240
|
subscriptionId?: string;
|
|
236
|
-
paymentDetails?:
|
|
241
|
+
paymentDetails?: 0 | 1 | number;
|
|
242
|
+
[key: string]: unknown;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Subscription payment detail returned when inquiry paymentDetails=1.
|
|
246
|
+
*/
|
|
247
|
+
interface SubscriptionPaymentDetail {
|
|
248
|
+
acquiringOrderId?: string;
|
|
249
|
+
orderCurrency?: string;
|
|
250
|
+
orderAmount?: string;
|
|
251
|
+
orderStatus?: string;
|
|
252
|
+
orderUpdatedAt?: string;
|
|
253
|
+
period?: string;
|
|
237
254
|
[key: string]: unknown;
|
|
238
255
|
}
|
|
239
256
|
/**
|
|
@@ -258,7 +275,7 @@ interface InquirySubscriptionData {
|
|
|
258
275
|
failedReason?: string;
|
|
259
276
|
subscriptionManagementUrl?: string;
|
|
260
277
|
extendInfo?: string;
|
|
261
|
-
paymentDetails?:
|
|
278
|
+
paymentDetails?: SubscriptionPaymentDetail[];
|
|
262
279
|
goodsInfo?: {
|
|
263
280
|
goodsId?: string;
|
|
264
281
|
goodsName?: string;
|
|
@@ -273,7 +290,7 @@ interface InquirySubscriptionData {
|
|
|
273
290
|
* Cancel subscription request parameters.
|
|
274
291
|
*/
|
|
275
292
|
interface CancelSubscriptionParams {
|
|
276
|
-
subscriptionId
|
|
293
|
+
subscriptionId: string;
|
|
277
294
|
merchantId?: string;
|
|
278
295
|
requestedAt?: string;
|
|
279
296
|
[key: string]: unknown;
|
|
@@ -308,6 +325,99 @@ interface ManageSubscriptionData {
|
|
|
308
325
|
subscriptionStatus?: SubscriptionStatus;
|
|
309
326
|
[key: string]: unknown;
|
|
310
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Scheduled amount item for a specific subscription period.
|
|
330
|
+
*/
|
|
331
|
+
interface SubscriptionScheduledAmount {
|
|
332
|
+
/**
|
|
333
|
+
* Period number, for example "1".
|
|
334
|
+
*/
|
|
335
|
+
period?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Merchant subscription amount for this period.
|
|
338
|
+
*/
|
|
339
|
+
amount?: string;
|
|
340
|
+
[key: string]: unknown;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Product information for subscription update operations.
|
|
344
|
+
*/
|
|
345
|
+
interface SubscriptionUpdateProductInfo {
|
|
346
|
+
/**
|
|
347
|
+
* Updated trial period amount. Empty means no trial period.
|
|
348
|
+
*/
|
|
349
|
+
trialPeriodAmount?: string;
|
|
350
|
+
/**
|
|
351
|
+
* Scheduled amount list for each period.
|
|
352
|
+
*/
|
|
353
|
+
scheduledAmounts?: SubscriptionScheduledAmount[];
|
|
354
|
+
[key: string]: unknown;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Update subscription request parameters.
|
|
358
|
+
*/
|
|
359
|
+
interface UpdateSubscriptionParams {
|
|
360
|
+
/**
|
|
361
|
+
* Merchant subscription request ID. Provide subscriptionRequest or subscriptionId.
|
|
362
|
+
*/
|
|
363
|
+
subscriptionRequest?: string;
|
|
364
|
+
/**
|
|
365
|
+
* Waffo subscription ID. Provide subscriptionRequest or subscriptionId.
|
|
366
|
+
*/
|
|
367
|
+
subscriptionId?: string;
|
|
368
|
+
/**
|
|
369
|
+
* New merchant subscription amount. At least one of amount and
|
|
370
|
+
* productInfo.scheduledAmounts must be provided.
|
|
371
|
+
*/
|
|
372
|
+
amount?: string;
|
|
373
|
+
/**
|
|
374
|
+
* Product information containing trial or scheduled amount updates.
|
|
375
|
+
*/
|
|
376
|
+
productInfo?: SubscriptionUpdateProductInfo;
|
|
377
|
+
[key: string]: unknown;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Update subscription response data.
|
|
381
|
+
*/
|
|
382
|
+
interface UpdateSubscriptionData {
|
|
383
|
+
/**
|
|
384
|
+
* Waffo subscription ID.
|
|
385
|
+
*/
|
|
386
|
+
subscriptionId?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Subscription request ID sent from Merchant.
|
|
389
|
+
*/
|
|
390
|
+
subscriptionRequest?: string;
|
|
391
|
+
/**
|
|
392
|
+
* Previous trial period amount.
|
|
393
|
+
*/
|
|
394
|
+
previousTrialPeriodAmount?: string;
|
|
395
|
+
/**
|
|
396
|
+
* New trial period amount.
|
|
397
|
+
*/
|
|
398
|
+
newTrialPeriodAmount?: string;
|
|
399
|
+
/**
|
|
400
|
+
* Previous merchant subscription amount.
|
|
401
|
+
*/
|
|
402
|
+
previousAmount?: string;
|
|
403
|
+
/**
|
|
404
|
+
* New merchant subscription amount.
|
|
405
|
+
*/
|
|
406
|
+
newAmount?: string;
|
|
407
|
+
/**
|
|
408
|
+
* Previous scheduled amount list for each period.
|
|
409
|
+
*/
|
|
410
|
+
previousScheduledAmounts?: SubscriptionScheduledAmount[];
|
|
411
|
+
/**
|
|
412
|
+
* New scheduled amount list for each period.
|
|
413
|
+
*/
|
|
414
|
+
newScheduledAmounts?: SubscriptionScheduledAmount[];
|
|
415
|
+
/**
|
|
416
|
+
* The next period number when the new amount takes effect.
|
|
417
|
+
*/
|
|
418
|
+
nextEffectivePeriod?: string;
|
|
419
|
+
[key: string]: unknown;
|
|
420
|
+
}
|
|
311
421
|
/**
|
|
312
422
|
* Subscription status enum.
|
|
313
423
|
* Based on openapi.json SubscriptionInquiryResponse.subscriptionStatus.
|
|
@@ -382,6 +492,10 @@ interface ProductInfo {
|
|
|
382
492
|
* Current billing period number.
|
|
383
493
|
*/
|
|
384
494
|
currentPeriod?: string;
|
|
495
|
+
/**
|
|
496
|
+
* Scheduled amount list for each period.
|
|
497
|
+
*/
|
|
498
|
+
scheduledAmounts?: SubscriptionScheduledAmount[];
|
|
385
499
|
[key: string]: unknown;
|
|
386
500
|
}
|
|
387
501
|
/**
|
|
@@ -390,9 +504,11 @@ interface ProductInfo {
|
|
|
390
504
|
interface SubscriptionUserInfo {
|
|
391
505
|
userId: string;
|
|
392
506
|
userEmail: string;
|
|
507
|
+
userTerminal?: string;
|
|
393
508
|
userPhone?: string;
|
|
394
509
|
userFirstName?: string;
|
|
395
510
|
userLastName?: string;
|
|
511
|
+
userCreatedAt?: string;
|
|
396
512
|
userCountryCode?: string;
|
|
397
513
|
userBrowserIp?: string;
|
|
398
514
|
userAgent?: string;
|
|
@@ -405,12 +521,23 @@ interface SubscriptionPaymentInfo {
|
|
|
405
521
|
productName: string;
|
|
406
522
|
payMethodType?: string;
|
|
407
523
|
payMethodName?: string;
|
|
524
|
+
payMethodProperties?: string;
|
|
525
|
+
payMethodUserAccountType?: string;
|
|
526
|
+
payMethodUserAccountNo?: string;
|
|
527
|
+
payMethodUserAccessToken?: string;
|
|
528
|
+
cashierLanguage?: string;
|
|
529
|
+
cashierAppearance?: string;
|
|
408
530
|
[key: string]: unknown;
|
|
409
531
|
}
|
|
410
532
|
/**
|
|
411
533
|
* Address information for subscription.
|
|
412
534
|
*/
|
|
413
535
|
interface SubscriptionAddressInfo {
|
|
536
|
+
address?: string;
|
|
537
|
+
city?: string;
|
|
538
|
+
region?: string;
|
|
539
|
+
postcode?: string;
|
|
540
|
+
addressCountryCode?: string;
|
|
414
541
|
shippingAddress?: {
|
|
415
542
|
country?: string;
|
|
416
543
|
state?: string;
|
|
@@ -435,11 +562,28 @@ interface SubscriptionAddressInfo {
|
|
|
435
562
|
* Risk data for subscription.
|
|
436
563
|
*/
|
|
437
564
|
interface SubscriptionRiskData {
|
|
565
|
+
userType?: string;
|
|
566
|
+
userCategory?: string;
|
|
567
|
+
userLegalName?: string;
|
|
568
|
+
userDisplayName?: string;
|
|
569
|
+
userRegistrationIp?: string;
|
|
570
|
+
userLastSeenIp?: string;
|
|
571
|
+
userIsNew?: string;
|
|
572
|
+
userIsFirstPurchase?: string;
|
|
438
573
|
deviceType?: string;
|
|
439
574
|
deviceId?: string;
|
|
440
575
|
deviceTokenId?: string;
|
|
441
576
|
[key: string]: unknown;
|
|
442
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Brand display information for cashier.
|
|
580
|
+
*/
|
|
581
|
+
interface SubscriptionBrandInfo {
|
|
582
|
+
cashierLogoUrl?: string;
|
|
583
|
+
cashierDisplayName?: string;
|
|
584
|
+
cashierProductImageUrl?: string;
|
|
585
|
+
[key: string]: unknown;
|
|
586
|
+
}
|
|
443
587
|
/**
|
|
444
588
|
* Merchant information for subscription.
|
|
445
589
|
*/
|
|
@@ -517,6 +661,10 @@ interface SubscriptionChangeProductInfo {
|
|
|
517
661
|
* Trial period interval (max 12 characters).
|
|
518
662
|
*/
|
|
519
663
|
trialPeriodInterval?: string;
|
|
664
|
+
/**
|
|
665
|
+
* Scheduled amount list for each period.
|
|
666
|
+
*/
|
|
667
|
+
scheduledAmounts?: SubscriptionScheduledAmount[];
|
|
520
668
|
[key: string]: unknown;
|
|
521
669
|
}
|
|
522
670
|
/**
|
|
@@ -634,6 +782,10 @@ interface SubscriptionChangeParams {
|
|
|
634
782
|
userIsFirstPurchase?: string;
|
|
635
783
|
[key: string]: unknown;
|
|
636
784
|
};
|
|
785
|
+
/**
|
|
786
|
+
* Brand display information for cashier.
|
|
787
|
+
*/
|
|
788
|
+
brandInfo?: SubscriptionBrandInfo;
|
|
637
789
|
[key: string]: unknown;
|
|
638
790
|
}
|
|
639
791
|
/**
|
|
@@ -1231,6 +1383,11 @@ interface CreateOrderParams {
|
|
|
1231
1383
|
cardInfo?: CardInfo;
|
|
1232
1384
|
riskData?: RiskData;
|
|
1233
1385
|
paymentTokenData?: PaymentTokenData;
|
|
1386
|
+
brandInfo?: BrandInfo;
|
|
1387
|
+
productDetail?: ProductDetail;
|
|
1388
|
+
acqOrderExtSubscriptionInfo?: AcqOrderExtSubscriptionInfo;
|
|
1389
|
+
channelId?: string;
|
|
1390
|
+
innerCardData?: WaffoTokenCardData;
|
|
1234
1391
|
userCurrency?: string;
|
|
1235
1392
|
successRedirectUrl?: string;
|
|
1236
1393
|
failedRedirectUrl?: string;
|
|
@@ -1356,9 +1513,9 @@ interface RefundOrderData {
|
|
|
1356
1513
|
interface CaptureOrderParams {
|
|
1357
1514
|
paymentRequestId?: string;
|
|
1358
1515
|
acquiringOrderId?: string;
|
|
1359
|
-
merchantId
|
|
1516
|
+
merchantId?: string;
|
|
1360
1517
|
captureRequestedAt?: string;
|
|
1361
|
-
captureAmount
|
|
1518
|
+
captureAmount: string;
|
|
1362
1519
|
[key: string]: unknown;
|
|
1363
1520
|
}
|
|
1364
1521
|
/**
|
|
@@ -1407,7 +1564,16 @@ interface PaymentInfo {
|
|
|
1407
1564
|
payMethodType?: string;
|
|
1408
1565
|
payMethodName?: string;
|
|
1409
1566
|
payMethodProperties?: string;
|
|
1567
|
+
payMethodResponse?: string;
|
|
1568
|
+
userPaymentAccessToken?: string;
|
|
1569
|
+
payMethodUserAccountNo?: string;
|
|
1570
|
+
payMethodUserAccountType?: string;
|
|
1571
|
+
payOption?: string;
|
|
1572
|
+
cashierLanguage?: string;
|
|
1573
|
+
cashierAppearance?: string;
|
|
1574
|
+
payMethodCountry?: string;
|
|
1410
1575
|
captureMode?: string;
|
|
1576
|
+
merchantInitiatedMode?: string;
|
|
1411
1577
|
[key: string]: unknown;
|
|
1412
1578
|
}
|
|
1413
1579
|
/**
|
|
@@ -1476,6 +1642,42 @@ interface PaymentTokenData {
|
|
|
1476
1642
|
tokenId?: string;
|
|
1477
1643
|
[key: string]: unknown;
|
|
1478
1644
|
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Brand display information for cashier.
|
|
1647
|
+
*/
|
|
1648
|
+
interface BrandInfo {
|
|
1649
|
+
cashierLogoUrl?: string;
|
|
1650
|
+
cashierDisplayName?: string;
|
|
1651
|
+
cashierProductImageUrl?: string;
|
|
1652
|
+
[key: string]: unknown;
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Product detail extension payload.
|
|
1656
|
+
*/
|
|
1657
|
+
interface ProductDetail {
|
|
1658
|
+
subscriptionInfo?: SubscriptionInfo;
|
|
1659
|
+
[key: string]: unknown;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Subscription extension information for an acquiring order.
|
|
1663
|
+
*/
|
|
1664
|
+
interface AcqOrderExtSubscriptionInfo {
|
|
1665
|
+
subscriptionId?: string;
|
|
1666
|
+
periodNo?: number;
|
|
1667
|
+
merchantRequest?: string;
|
|
1668
|
+
subscriptionEvent?: string;
|
|
1669
|
+
[key: string]: unknown;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Tokenized card data used for direct card payment flows.
|
|
1673
|
+
*/
|
|
1674
|
+
interface WaffoTokenCardData {
|
|
1675
|
+
cardBinDataList?: Record<string, unknown>[];
|
|
1676
|
+
maskedCardInfo?: string;
|
|
1677
|
+
cardBin?: string;
|
|
1678
|
+
cardExpiry?: string;
|
|
1679
|
+
[key: string]: unknown;
|
|
1680
|
+
}
|
|
1479
1681
|
/**
|
|
1480
1682
|
* Refund user information.
|
|
1481
1683
|
*/
|
|
@@ -1622,6 +1824,7 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1622
1824
|
private static readonly PATH_INQUIRY;
|
|
1623
1825
|
private static readonly PATH_CANCEL;
|
|
1624
1826
|
private static readonly PATH_MANAGE;
|
|
1827
|
+
private static readonly PATH_UPDATE;
|
|
1625
1828
|
private static readonly PATH_CHANGE;
|
|
1626
1829
|
private static readonly PATH_CHANGE_INQUIRY;
|
|
1627
1830
|
/**
|
|
@@ -1660,6 +1863,18 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1660
1863
|
* @throws WaffoUnknownStatusError for network errors
|
|
1661
1864
|
*/
|
|
1662
1865
|
manage(params: ManageSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<ManageSubscriptionData>>;
|
|
1866
|
+
/**
|
|
1867
|
+
* Updates an existing subscription amount or scheduled period amounts.
|
|
1868
|
+
*
|
|
1869
|
+
* Provide either subscriptionRequest or subscriptionId. At least one of amount
|
|
1870
|
+
* or productInfo.scheduledAmounts must be provided.
|
|
1871
|
+
*
|
|
1872
|
+
* @param params - Subscription update parameters
|
|
1873
|
+
* @param options - Optional request options
|
|
1874
|
+
* @returns API response with update result
|
|
1875
|
+
* @throws WaffoUnknownStatusError for network errors
|
|
1876
|
+
*/
|
|
1877
|
+
update(params: UpdateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<UpdateSubscriptionData>>;
|
|
1663
1878
|
/**
|
|
1664
1879
|
* Changes (upgrades/downgrades) an existing subscription.
|
|
1665
1880
|
*
|
|
@@ -1763,6 +1978,8 @@ interface InquiryRefundData {
|
|
|
1763
1978
|
userCurrency?: string;
|
|
1764
1979
|
finalDealAmount?: string;
|
|
1765
1980
|
remainingRefundAmount?: string;
|
|
1981
|
+
merchantUserId?: string;
|
|
1982
|
+
subscriptionInfo?: SubscriptionInfo;
|
|
1766
1983
|
userInfo?: RefundUserInfo;
|
|
1767
1984
|
refundCompletedAt?: string;
|
|
1768
1985
|
refundSource?: string;
|
|
@@ -1832,7 +2049,6 @@ interface InquiryMerchantConfigData {
|
|
|
1832
2049
|
*/
|
|
1833
2050
|
interface InquiryPayMethodConfigParams {
|
|
1834
2051
|
merchantId: string;
|
|
1835
|
-
payMethodType?: string;
|
|
1836
2052
|
[key: string]: unknown;
|
|
1837
2053
|
}
|
|
1838
2054
|
/**
|
|
@@ -1840,21 +2056,33 @@ interface InquiryPayMethodConfigParams {
|
|
|
1840
2056
|
*/
|
|
1841
2057
|
interface InquiryPayMethodConfigData {
|
|
1842
2058
|
merchantId?: string;
|
|
1843
|
-
|
|
2059
|
+
payMethodDetails?: PayMethodDetail[];
|
|
1844
2060
|
[key: string]: unknown;
|
|
1845
2061
|
}
|
|
1846
2062
|
/**
|
|
1847
|
-
* Pay method
|
|
2063
|
+
* Pay method detail.
|
|
1848
2064
|
*/
|
|
1849
|
-
interface
|
|
1850
|
-
|
|
2065
|
+
interface PayMethodDetail {
|
|
2066
|
+
productName?: string;
|
|
1851
2067
|
payMethodName?: string;
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
2068
|
+
country?: string;
|
|
2069
|
+
currentStatus?: string;
|
|
2070
|
+
fixedMaintenanceRules?: FixedMaintenanceRule[];
|
|
2071
|
+
fixedMaintenanceTimezone?: string;
|
|
2072
|
+
[key: string]: unknown;
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Fixed maintenance rule for a payment method.
|
|
2076
|
+
*/
|
|
2077
|
+
interface FixedMaintenanceRule {
|
|
2078
|
+
startRule?: string;
|
|
2079
|
+
endRule?: string;
|
|
1856
2080
|
[key: string]: unknown;
|
|
1857
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @deprecated Use PayMethodDetail.
|
|
2084
|
+
*/
|
|
2085
|
+
type PayMethodInfo = PayMethodDetail;
|
|
1858
2086
|
|
|
1859
2087
|
/**
|
|
1860
2088
|
* Merchant config resource for querying merchant configuration.
|
|
@@ -1898,8 +2126,8 @@ declare class MerchantConfigResource extends BaseResource {
|
|
|
1898
2126
|
*
|
|
1899
2127
|
* if (response.isSuccess()) {
|
|
1900
2128
|
* const data = response.getData();
|
|
1901
|
-
* data?.
|
|
1902
|
-
* console.log(`${method.payMethodName}: ${method.
|
|
2129
|
+
* data?.payMethodDetails?.forEach(method => {
|
|
2130
|
+
* console.log(`${method.payMethodName}: ${method.currentStatus}`);
|
|
1903
2131
|
* });
|
|
1904
2132
|
* }
|
|
1905
2133
|
* ```
|
|
@@ -2160,7 +2388,7 @@ declare class WaffoUnknownStatusError extends Error {
|
|
|
2160
2388
|
* Result of key pair generation.
|
|
2161
2389
|
*/
|
|
2162
2390
|
interface KeyPairResult {
|
|
2163
|
-
/** Base64 encoded PKCS8 private key */
|
|
2391
|
+
/** Base64 encoded PKCS8 DER private key */
|
|
2164
2392
|
privateKey: string;
|
|
2165
2393
|
/** Base64 encoded X509 public key */
|
|
2166
2394
|
publicKey: string;
|
|
@@ -2169,16 +2397,16 @@ interface KeyPairResult {
|
|
|
2169
2397
|
* Signs data using RSA-SHA256.
|
|
2170
2398
|
*
|
|
2171
2399
|
* @param data - The data to sign (UTF-8 string)
|
|
2172
|
-
* @param
|
|
2400
|
+
* @param privateKeyInput - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2173
2401
|
* @returns Base64 encoded signature
|
|
2174
|
-
* @throws WaffoError if signing fails (S0003)
|
|
2402
|
+
* @throws WaffoError if the private key is invalid (S0007) or signing fails (S0003)
|
|
2175
2403
|
*
|
|
2176
2404
|
* @example
|
|
2177
2405
|
* ```typescript
|
|
2178
2406
|
* const signature = sign('{"amount":"100.00"}', privateKey);
|
|
2179
2407
|
* ```
|
|
2180
2408
|
*/
|
|
2181
|
-
declare function sign(data: string,
|
|
2409
|
+
declare function sign(data: string, privateKeyInput: string): string;
|
|
2182
2410
|
/**
|
|
2183
2411
|
* Verifies a signature using RSA-SHA256.
|
|
2184
2412
|
*
|
|
@@ -2197,12 +2425,12 @@ declare function sign(data: string, base64PrivateKey: string): string;
|
|
|
2197
2425
|
*/
|
|
2198
2426
|
declare function verify(data: string, base64Signature: string, base64PublicKey: string): boolean;
|
|
2199
2427
|
/**
|
|
2200
|
-
* Validates a Base64 encoded PKCS8 private key.
|
|
2428
|
+
* Validates a Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key.
|
|
2201
2429
|
*
|
|
2202
2430
|
* This method attempts to parse the key to ensure it's a valid RSA private key.
|
|
2203
2431
|
* Use this at startup to fail fast if the private key is invalid.
|
|
2204
2432
|
*
|
|
2205
|
-
* @param base64PrivateKey - Base64 encoded PKCS8 private key
|
|
2433
|
+
* @param base64PrivateKey - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2206
2434
|
* @throws WaffoError if the key is invalid (S0007)
|
|
2207
2435
|
*
|
|
2208
2436
|
* @example
|
|
@@ -2253,4 +2481,4 @@ declare const RsaUtils: {
|
|
|
2253
2481
|
generateKeyPair: typeof generateKeyPair;
|
|
2254
2482
|
};
|
|
2255
2483
|
|
|
2256
|
-
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUserInfo, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
|
2484
|
+
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type FixedMaintenanceRule, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodDetail, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionChangeData, type SubscriptionChangeInquiryData, type SubscriptionChangeInquiryParams, type SubscriptionChangeParams, type SubscriptionChangeProductInfo, type SubscriptionChangeStatus, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentDetail, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
package/dist/index.js
CHANGED
|
@@ -114,18 +114,18 @@ var WaffoUnknownStatusError = class _WaffoUnknownStatusError extends Error {
|
|
|
114
114
|
// src/utils/rsa-utils.ts
|
|
115
115
|
var ALGORITHM = "RSA-SHA256";
|
|
116
116
|
var KEY_SIZE = 2048;
|
|
117
|
-
|
|
117
|
+
var PKCS8_PEM_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
118
|
+
var PEM_HEADER_PREFIX = "-----BEGIN ";
|
|
119
|
+
var INVALID_PRIVATE_KEY_FORMAT_MESSAGE = "Invalid private key format. Please provide an unencrypted PKCS#8 private key.";
|
|
120
|
+
function sign(data, privateKeyInput) {
|
|
118
121
|
try {
|
|
119
|
-
const
|
|
122
|
+
const privateKey = parsePrivateKey(privateKeyInput);
|
|
120
123
|
const signer = crypto__namespace.createSign(ALGORITHM);
|
|
121
124
|
signer.update(data, "utf8");
|
|
122
|
-
const signature = signer.sign(
|
|
123
|
-
key: privateKeyBuffer,
|
|
124
|
-
format: "der",
|
|
125
|
-
type: "pkcs8"
|
|
126
|
-
});
|
|
125
|
+
const signature = signer.sign(privateKey);
|
|
127
126
|
return signature.toString("base64");
|
|
128
127
|
} catch (error) {
|
|
128
|
+
if (error instanceof WaffoError) throw error;
|
|
129
129
|
throw new WaffoError(
|
|
130
130
|
WaffoErrorCode.SIGN_FAILED,
|
|
131
131
|
`Failed to sign data: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -159,29 +159,43 @@ function validatePrivateKey(base64PrivateKey) {
|
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
161
|
try {
|
|
162
|
-
|
|
163
|
-
crypto__namespace.createPrivateKey({
|
|
164
|
-
key: keyBuffer,
|
|
165
|
-
format: "der",
|
|
166
|
-
type: "pkcs8"
|
|
167
|
-
});
|
|
162
|
+
parsePrivateKey(base64PrivateKey);
|
|
168
163
|
} catch (error) {
|
|
169
164
|
if (error instanceof WaffoError) throw error;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
throw new WaffoError(
|
|
166
|
+
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
167
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
168
|
+
error instanceof Error ? error : void 0
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function parsePrivateKey(privateKeyInput) {
|
|
173
|
+
try {
|
|
174
|
+
const trimmed = privateKeyInput.trim();
|
|
175
|
+
const key = trimmed.startsWith(PKCS8_PEM_HEADER) ? crypto__namespace.createPrivateKey(trimmed) : parseDerPrivateKey(trimmed);
|
|
176
|
+
if (key.asymmetricKeyType !== "rsa") {
|
|
177
|
+
throw new Error("private key is not RSA");
|
|
177
178
|
}
|
|
179
|
+
return key;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error instanceof WaffoError) throw error;
|
|
178
182
|
throw new WaffoError(
|
|
179
183
|
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
180
|
-
|
|
184
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
181
185
|
error instanceof Error ? error : void 0
|
|
182
186
|
);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
189
|
+
function parseDerPrivateKey(trimmedPrivateKey) {
|
|
190
|
+
if (trimmedPrivateKey.startsWith(PEM_HEADER_PREFIX)) {
|
|
191
|
+
throw new Error("unsupported PEM private key");
|
|
192
|
+
}
|
|
193
|
+
return crypto__namespace.createPrivateKey({
|
|
194
|
+
key: Buffer.from(trimmedPrivateKey, "base64"),
|
|
195
|
+
format: "der",
|
|
196
|
+
type: "pkcs8"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
185
199
|
function validatePublicKey(base64PublicKey) {
|
|
186
200
|
if (!base64PublicKey || base64PublicKey.trim() === "") {
|
|
187
201
|
throw new WaffoError(
|
|
@@ -463,7 +477,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
|
|
|
463
477
|
var HEADER_CONTENT_TYPE = "content-type";
|
|
464
478
|
var CONTENT_TYPE_JSON = "application/json";
|
|
465
479
|
var API_VERSION = "1.0.0";
|
|
466
|
-
var SDK_VERSION = "waffo-node/2.
|
|
480
|
+
var SDK_VERSION = "waffo-node/2.5.1";
|
|
467
481
|
var WaffoHttpClient = class {
|
|
468
482
|
baseUrl;
|
|
469
483
|
apiKey;
|
|
@@ -475,6 +489,8 @@ var WaffoHttpClient = class {
|
|
|
475
489
|
logger;
|
|
476
490
|
httpTransport;
|
|
477
491
|
constructor(config) {
|
|
492
|
+
RsaUtils.validatePrivateKey(config.privateKey);
|
|
493
|
+
RsaUtils.validatePublicKey(config.waffoPublicKey);
|
|
478
494
|
this.baseUrl = EnvironmentBaseUrl[config.environment];
|
|
479
495
|
this.apiKey = config.apiKey;
|
|
480
496
|
this.privateKey = config.privateKey;
|
|
@@ -613,7 +629,7 @@ var WaffoHttpClient = class {
|
|
|
613
629
|
isNetworkError(error) {
|
|
614
630
|
if (!(error instanceof Error)) return false;
|
|
615
631
|
const message = error.message.toLowerCase();
|
|
616
|
-
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
632
|
+
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
617
633
|
}
|
|
618
634
|
};
|
|
619
635
|
|
|
@@ -902,6 +918,9 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
902
918
|
* @throws WaffoUnknownStatusError for network errors
|
|
903
919
|
*/
|
|
904
920
|
async capture(params, options) {
|
|
921
|
+
if (!params.captureRequestedAt) {
|
|
922
|
+
params.captureRequestedAt = getCurrentTimestamp();
|
|
923
|
+
}
|
|
905
924
|
return this.httpClient.post(
|
|
906
925
|
this.getPath(_OrderResource.PATH_CAPTURE),
|
|
907
926
|
params,
|
|
@@ -916,6 +935,7 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
916
935
|
static PATH_INQUIRY = "/inquiry";
|
|
917
936
|
static PATH_CANCEL = "/cancel";
|
|
918
937
|
static PATH_MANAGE = "/manage";
|
|
938
|
+
static PATH_UPDATE = "/update";
|
|
919
939
|
static PATH_CHANGE = "/change";
|
|
920
940
|
static PATH_CHANGE_INQUIRY = "/change/inquiry";
|
|
921
941
|
/**
|
|
@@ -984,6 +1004,24 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
984
1004
|
options
|
|
985
1005
|
);
|
|
986
1006
|
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Updates an existing subscription amount or scheduled period amounts.
|
|
1009
|
+
*
|
|
1010
|
+
* Provide either subscriptionRequest or subscriptionId. At least one of amount
|
|
1011
|
+
* or productInfo.scheduledAmounts must be provided.
|
|
1012
|
+
*
|
|
1013
|
+
* @param params - Subscription update parameters
|
|
1014
|
+
* @param options - Optional request options
|
|
1015
|
+
* @returns API response with update result
|
|
1016
|
+
* @throws WaffoUnknownStatusError for network errors
|
|
1017
|
+
*/
|
|
1018
|
+
async update(params, options) {
|
|
1019
|
+
return this.httpClient.post(
|
|
1020
|
+
this.getPath(_SubscriptionResource.PATH_UPDATE),
|
|
1021
|
+
params,
|
|
1022
|
+
options
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
987
1025
|
/**
|
|
988
1026
|
* Changes (upgrades/downgrades) an existing subscription.
|
|
989
1027
|
*
|
|
@@ -1150,8 +1188,8 @@ var Waffo = class _Waffo {
|
|
|
1150
1188
|
* @param config - SDK configuration
|
|
1151
1189
|
*/
|
|
1152
1190
|
constructor(config) {
|
|
1153
|
-
this.config = config;
|
|
1154
|
-
this.httpClient = new WaffoHttpClient(config);
|
|
1191
|
+
this.config = createWaffoConfig(config);
|
|
1192
|
+
this.httpClient = new WaffoHttpClient(this.config);
|
|
1155
1193
|
}
|
|
1156
1194
|
/**
|
|
1157
1195
|
* Creates a Waffo SDK instance from environment variables.
|