@waffo/waffo-node 3.0.1 → 3.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/README.md +57 -20
- package/dist/index.d.mts +42 -2
- package/dist/index.d.ts +42 -2
- package/dist/index.js +57 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Waffo Node.js SDK
|
|
2
2
|
|
|
3
|
-
<!-- Synced with waffo-sdk/README.md @ commit
|
|
3
|
+
<!-- Synced with waffo-sdk/README.md @ commit 53f0d42 -->
|
|
4
4
|
|
|
5
5
|
**English** | [中文](README_CN.md)
|
|
6
6
|
|
|
@@ -527,6 +527,41 @@ if (response.isSuccess()) {
|
|
|
527
527
|
}
|
|
528
528
|
```
|
|
529
529
|
|
|
530
|
+
<!-- sdk-sync:start:Update%20Subscription -->
|
|
531
|
+
#### Update Subscription
|
|
532
|
+
|
|
533
|
+
Update the billing amounts of an active subscription without re-authorization. Provide `subscriptionRequest` or `subscriptionId`. To charge a seat add-on immediately, include `topupInfo`; the updated billing amounts take effect from the next billing period.
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
const response = await waffo.subscription().update({
|
|
537
|
+
subscriptionId: 'subscription_id',
|
|
538
|
+
amount: '129.00', // New per-period amount from the next billing period
|
|
539
|
+
productInfo: {
|
|
540
|
+
trialPeriodAmount: '0',
|
|
541
|
+
scheduledAmounts: [
|
|
542
|
+
{ period: '2', amount: '99.00' }, // Per-period override
|
|
543
|
+
{ period: '3', amount: '129.00' },
|
|
544
|
+
],
|
|
545
|
+
},
|
|
546
|
+
topupInfo: {
|
|
547
|
+
topupRequest: 'mimo-topup-001', // Idempotency key for this top-up
|
|
548
|
+
topupAmount: '30.00', // Amount charged immediately
|
|
549
|
+
description: 'Seat add-on 3 seats',
|
|
550
|
+
orderExpiredAt: '2030-01-01T00:00:00Z',
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
if (response.isSuccess()) {
|
|
555
|
+
const data = response.getData();
|
|
556
|
+
console.log('Previous Amount:', data.previousAmount);
|
|
557
|
+
console.log('New Amount:', data.newAmount);
|
|
558
|
+
console.log('Next Effective Period:', data.nextEffectivePeriod);
|
|
559
|
+
console.log('Top-up Order:', data.topupInfo?.acquiringOrderId);
|
|
560
|
+
console.log('Top-up Status:', data.topupInfo?.topupStatus);
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
<!-- sdk-sync:end:Update%20Subscription -->
|
|
564
|
+
|
|
530
565
|
### Subscription Change (Upgrade/Downgrade)
|
|
531
566
|
|
|
532
567
|
Change an existing subscription to a new plan (upgrade or downgrade).
|
|
@@ -963,6 +998,7 @@ These two notification types share the same payload structure:
|
|
|
963
998
|
}
|
|
964
999
|
```
|
|
965
1000
|
|
|
1001
|
+
<!-- sdk-sync:start:Payment%20Method%20Types -->
|
|
966
1002
|
## Payment Method Types
|
|
967
1003
|
|
|
968
1004
|
### payMethodType Reference
|
|
@@ -978,31 +1014,32 @@ These two notification types share the same payload structure:
|
|
|
978
1014
|
|
|
979
1015
|
### Usage Examples
|
|
980
1016
|
|
|
981
|
-
|
|
982
|
-
// Specify type only, let user choose on checkout page
|
|
983
|
-
paymentInfo: {
|
|
984
|
-
payMethodType: 'CREDITCARD',
|
|
985
|
-
}
|
|
1017
|
+
Specify a type and let the user choose on the checkout page:
|
|
986
1018
|
|
|
987
|
-
|
|
988
|
-
paymentInfo: {
|
|
989
|
-
|
|
990
|
-
payMethodName: 'CC_VISA',
|
|
991
|
-
}
|
|
1019
|
+
```json
|
|
1020
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD"}}
|
|
1021
|
+
```
|
|
992
1022
|
|
|
993
|
-
|
|
994
|
-
paymentInfo: {
|
|
995
|
-
payMethodType: 'CREDITCARD,DEBITCARD',
|
|
996
|
-
}
|
|
1023
|
+
Specify an exact payment method:
|
|
997
1024
|
|
|
998
|
-
|
|
999
|
-
paymentInfo: {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1025
|
+
```json
|
|
1026
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD", "payMethodName": "CC_VISA"}}
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
Combine multiple types:
|
|
1030
|
+
|
|
1031
|
+
```json
|
|
1032
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD,DEBITCARD"}}
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
Select an e-wallet channel:
|
|
1036
|
+
|
|
1037
|
+
```json
|
|
1038
|
+
{"paymentInfo": {"payMethodType": "EWALLET", "payMethodName": "GCASH"}}
|
|
1003
1039
|
```
|
|
1004
1040
|
|
|
1005
1041
|
> **Note**: For available `ProductName`, `PayMethodType`, `PayMethodName` values, merchants can log in to [Waffo Portal](https://dashboard.waffo.com) to view contracted payment methods (Home → Service → Pay-in).
|
|
1042
|
+
<!-- sdk-sync:end:Payment%20Method%20Types -->
|
|
1006
1043
|
|
|
1007
1044
|
## Advanced Configuration
|
|
1008
1045
|
|
package/dist/index.d.mts
CHANGED
|
@@ -371,6 +371,20 @@ interface SubscriptionUpdateProductInfo {
|
|
|
371
371
|
scheduledAmounts?: SubscriptionScheduledAmount[];
|
|
372
372
|
[key: string]: unknown;
|
|
373
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Seat add-on top-up information for a subscription update.
|
|
376
|
+
*/
|
|
377
|
+
interface SubscriptionUpdateTopupInfo {
|
|
378
|
+
/** Idempotency key for this top-up. */
|
|
379
|
+
topupRequest?: string;
|
|
380
|
+
/** Top-up amount charged for the current period. */
|
|
381
|
+
topupAmount?: string;
|
|
382
|
+
/** Description shown on cashier and billing. */
|
|
383
|
+
description?: string;
|
|
384
|
+
/** Cashier session expiry time in ISO 8601 format. */
|
|
385
|
+
orderExpiredAt?: string;
|
|
386
|
+
[key: string]: unknown;
|
|
387
|
+
}
|
|
374
388
|
/**
|
|
375
389
|
* Update subscription request parameters.
|
|
376
390
|
*/
|
|
@@ -392,6 +406,26 @@ interface UpdateSubscriptionParams {
|
|
|
392
406
|
* Product information containing trial or scheduled amount updates.
|
|
393
407
|
*/
|
|
394
408
|
productInfo?: SubscriptionUpdateProductInfo;
|
|
409
|
+
/**
|
|
410
|
+
* Seat add-on top-up information.
|
|
411
|
+
*/
|
|
412
|
+
topupInfo?: SubscriptionUpdateTopupInfo;
|
|
413
|
+
[key: string]: unknown;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Seat add-on top-up result returned by subscription update.
|
|
417
|
+
*/
|
|
418
|
+
interface SubscriptionUpdateTopupData {
|
|
419
|
+
/** Waffo acquiring order ID for the top-up charge. */
|
|
420
|
+
acquiringOrderId?: string;
|
|
421
|
+
/** Idempotency key echoed from the request. */
|
|
422
|
+
topupRequest?: string;
|
|
423
|
+
/** Top-up amount charged for the current period. */
|
|
424
|
+
topupAmount?: string;
|
|
425
|
+
/** Top-up charge order status. */
|
|
426
|
+
topupStatus?: string;
|
|
427
|
+
/** Structured order action used to redirect the user to cashier. */
|
|
428
|
+
topupAction?: string;
|
|
395
429
|
[key: string]: unknown;
|
|
396
430
|
}
|
|
397
431
|
/**
|
|
@@ -434,6 +468,10 @@ interface UpdateSubscriptionData {
|
|
|
434
468
|
* The next period number when the new amount takes effect.
|
|
435
469
|
*/
|
|
436
470
|
nextEffectivePeriod?: string;
|
|
471
|
+
/**
|
|
472
|
+
* Seat add-on top-up result when the request carries topupInfo.
|
|
473
|
+
*/
|
|
474
|
+
topupInfo?: SubscriptionUpdateTopupData;
|
|
437
475
|
[key: string]: unknown;
|
|
438
476
|
}
|
|
439
477
|
/**
|
|
@@ -1700,6 +1738,7 @@ declare class ApiResponse<T> {
|
|
|
1700
1738
|
getDataOrThrow(): T;
|
|
1701
1739
|
}
|
|
1702
1740
|
|
|
1741
|
+
type MerchantIdPath = 'merchantInfo.merchantId' | 'merchantId' | null;
|
|
1703
1742
|
/**
|
|
1704
1743
|
* HTTP client for making requests to the Waffo API.
|
|
1705
1744
|
*
|
|
@@ -1726,10 +1765,11 @@ declare class WaffoHttpClient {
|
|
|
1726
1765
|
* @param path - API endpoint path (e.g., "/order/create")
|
|
1727
1766
|
* @param request - Request body
|
|
1728
1767
|
* @param options - Per-request options
|
|
1768
|
+
* @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
|
|
1729
1769
|
* @returns API response
|
|
1730
1770
|
* @throws WaffoUnknownStatusError for network errors or unknown status
|
|
1731
1771
|
*/
|
|
1732
|
-
post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
|
|
1772
|
+
post<T extends object, R>(path: string, request: T, options?: RequestOptions, merchantIdPath?: MerchantIdPath): Promise<ApiResponse<R>>;
|
|
1733
1773
|
/**
|
|
1734
1774
|
* Parses the API response body.
|
|
1735
1775
|
*/
|
|
@@ -2618,4 +2658,4 @@ declare const RsaUtils: {
|
|
|
2618
2658
|
generateKeyPair: typeof generateKeyPair;
|
|
2619
2659
|
};
|
|
2620
2660
|
|
|
2621
|
-
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 PromotionInfo, 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, type SubscriptionPromotionInfo, 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, type WalletInquiryData, type WalletInquiryParams, WalletResource, WebhookEventType, WebhookHandler, type WebhookResult, type X402Info };
|
|
2661
|
+
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 PromotionInfo, 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, type SubscriptionPromotionInfo, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUpdateTopupData, type SubscriptionUpdateTopupInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, type WalletInquiryData, type WalletInquiryParams, WalletResource, WebhookEventType, WebhookHandler, type WebhookResult, type X402Info };
|
package/dist/index.d.ts
CHANGED
|
@@ -371,6 +371,20 @@ interface SubscriptionUpdateProductInfo {
|
|
|
371
371
|
scheduledAmounts?: SubscriptionScheduledAmount[];
|
|
372
372
|
[key: string]: unknown;
|
|
373
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Seat add-on top-up information for a subscription update.
|
|
376
|
+
*/
|
|
377
|
+
interface SubscriptionUpdateTopupInfo {
|
|
378
|
+
/** Idempotency key for this top-up. */
|
|
379
|
+
topupRequest?: string;
|
|
380
|
+
/** Top-up amount charged for the current period. */
|
|
381
|
+
topupAmount?: string;
|
|
382
|
+
/** Description shown on cashier and billing. */
|
|
383
|
+
description?: string;
|
|
384
|
+
/** Cashier session expiry time in ISO 8601 format. */
|
|
385
|
+
orderExpiredAt?: string;
|
|
386
|
+
[key: string]: unknown;
|
|
387
|
+
}
|
|
374
388
|
/**
|
|
375
389
|
* Update subscription request parameters.
|
|
376
390
|
*/
|
|
@@ -392,6 +406,26 @@ interface UpdateSubscriptionParams {
|
|
|
392
406
|
* Product information containing trial or scheduled amount updates.
|
|
393
407
|
*/
|
|
394
408
|
productInfo?: SubscriptionUpdateProductInfo;
|
|
409
|
+
/**
|
|
410
|
+
* Seat add-on top-up information.
|
|
411
|
+
*/
|
|
412
|
+
topupInfo?: SubscriptionUpdateTopupInfo;
|
|
413
|
+
[key: string]: unknown;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Seat add-on top-up result returned by subscription update.
|
|
417
|
+
*/
|
|
418
|
+
interface SubscriptionUpdateTopupData {
|
|
419
|
+
/** Waffo acquiring order ID for the top-up charge. */
|
|
420
|
+
acquiringOrderId?: string;
|
|
421
|
+
/** Idempotency key echoed from the request. */
|
|
422
|
+
topupRequest?: string;
|
|
423
|
+
/** Top-up amount charged for the current period. */
|
|
424
|
+
topupAmount?: string;
|
|
425
|
+
/** Top-up charge order status. */
|
|
426
|
+
topupStatus?: string;
|
|
427
|
+
/** Structured order action used to redirect the user to cashier. */
|
|
428
|
+
topupAction?: string;
|
|
395
429
|
[key: string]: unknown;
|
|
396
430
|
}
|
|
397
431
|
/**
|
|
@@ -434,6 +468,10 @@ interface UpdateSubscriptionData {
|
|
|
434
468
|
* The next period number when the new amount takes effect.
|
|
435
469
|
*/
|
|
436
470
|
nextEffectivePeriod?: string;
|
|
471
|
+
/**
|
|
472
|
+
* Seat add-on top-up result when the request carries topupInfo.
|
|
473
|
+
*/
|
|
474
|
+
topupInfo?: SubscriptionUpdateTopupData;
|
|
437
475
|
[key: string]: unknown;
|
|
438
476
|
}
|
|
439
477
|
/**
|
|
@@ -1700,6 +1738,7 @@ declare class ApiResponse<T> {
|
|
|
1700
1738
|
getDataOrThrow(): T;
|
|
1701
1739
|
}
|
|
1702
1740
|
|
|
1741
|
+
type MerchantIdPath = 'merchantInfo.merchantId' | 'merchantId' | null;
|
|
1703
1742
|
/**
|
|
1704
1743
|
* HTTP client for making requests to the Waffo API.
|
|
1705
1744
|
*
|
|
@@ -1726,10 +1765,11 @@ declare class WaffoHttpClient {
|
|
|
1726
1765
|
* @param path - API endpoint path (e.g., "/order/create")
|
|
1727
1766
|
* @param request - Request body
|
|
1728
1767
|
* @param options - Per-request options
|
|
1768
|
+
* @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
|
|
1729
1769
|
* @returns API response
|
|
1730
1770
|
* @throws WaffoUnknownStatusError for network errors or unknown status
|
|
1731
1771
|
*/
|
|
1732
|
-
post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
|
|
1772
|
+
post<T extends object, R>(path: string, request: T, options?: RequestOptions, merchantIdPath?: MerchantIdPath): Promise<ApiResponse<R>>;
|
|
1733
1773
|
/**
|
|
1734
1774
|
* Parses the API response body.
|
|
1735
1775
|
*/
|
|
@@ -2618,4 +2658,4 @@ declare const RsaUtils: {
|
|
|
2618
2658
|
generateKeyPair: typeof generateKeyPair;
|
|
2619
2659
|
};
|
|
2620
2660
|
|
|
2621
|
-
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 PromotionInfo, 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, type SubscriptionPromotionInfo, 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, type WalletInquiryData, type WalletInquiryParams, WalletResource, WebhookEventType, WebhookHandler, type WebhookResult, type X402Info };
|
|
2661
|
+
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 PromotionInfo, 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, type SubscriptionPromotionInfo, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUpdateTopupData, type SubscriptionUpdateTopupInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, type WalletInquiryData, type WalletInquiryParams, WalletResource, WebhookEventType, WebhookHandler, type WebhookResult, type X402Info };
|
package/dist/index.js
CHANGED
|
@@ -477,7 +477,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
|
|
|
477
477
|
var HEADER_CONTENT_TYPE = "content-type";
|
|
478
478
|
var CONTENT_TYPE_JSON = "application/json";
|
|
479
479
|
var API_VERSION = "1.0.0";
|
|
480
|
-
var SDK_VERSION = "waffo-node/3.0
|
|
480
|
+
var SDK_VERSION = "waffo-node/3.1.0";
|
|
481
481
|
var WaffoHttpClient = class {
|
|
482
482
|
baseUrl;
|
|
483
483
|
apiKey;
|
|
@@ -507,15 +507,16 @@ var WaffoHttpClient = class {
|
|
|
507
507
|
* @param path - API endpoint path (e.g., "/order/create")
|
|
508
508
|
* @param request - Request body
|
|
509
509
|
* @param options - Per-request options
|
|
510
|
+
* @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
|
|
510
511
|
* @returns API response
|
|
511
512
|
* @throws WaffoUnknownStatusError for network errors or unknown status
|
|
512
513
|
*/
|
|
513
|
-
async post(path, request, options) {
|
|
514
|
+
async post(path, request, options, merchantIdPath) {
|
|
514
515
|
const url = this.baseUrl + path;
|
|
515
516
|
const effectiveConnectTimeout = options?.connectTimeout ?? this.connectTimeout;
|
|
516
517
|
const effectiveReadTimeout = options?.readTimeout ?? this.readTimeout;
|
|
517
518
|
try {
|
|
518
|
-
this.injectMerchantIdIfNeeded(request);
|
|
519
|
+
this.injectMerchantIdIfNeeded(request, merchantIdPath);
|
|
519
520
|
const requestBody = JSON.stringify(request);
|
|
520
521
|
const signature = RsaUtils.sign(requestBody, this.privateKey);
|
|
521
522
|
this.logger?.debug(`Request URL: ${url}`);
|
|
@@ -608,9 +609,24 @@ var WaffoHttpClient = class {
|
|
|
608
609
|
/**
|
|
609
610
|
* Auto-injects merchantId into the request if configured.
|
|
610
611
|
*/
|
|
611
|
-
injectMerchantIdIfNeeded(request) {
|
|
612
|
+
injectMerchantIdIfNeeded(request, merchantIdPath) {
|
|
612
613
|
if (!this.merchantId) return;
|
|
613
614
|
const req = request;
|
|
615
|
+
if (merchantIdPath === null) return;
|
|
616
|
+
if (merchantIdPath === "merchantInfo.merchantId") {
|
|
617
|
+
const merchantInfo = typeof req.merchantInfo === "object" && req.merchantInfo !== null ? req.merchantInfo : {};
|
|
618
|
+
if (!merchantInfo.merchantId) {
|
|
619
|
+
merchantInfo.merchantId = this.merchantId;
|
|
620
|
+
}
|
|
621
|
+
req.merchantInfo = merchantInfo;
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (merchantIdPath === "merchantId") {
|
|
625
|
+
if (!req.merchantId) {
|
|
626
|
+
req.merchantId = this.merchantId;
|
|
627
|
+
}
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
614
630
|
if (typeof req.merchantInfo === "object" && req.merchantInfo !== null) {
|
|
615
631
|
const info = req.merchantInfo;
|
|
616
632
|
if (!info.merchantId) {
|
|
@@ -855,7 +871,8 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
855
871
|
return this.httpClient.post(
|
|
856
872
|
this.getPath(_OrderResource.PATH_CREATE),
|
|
857
873
|
params,
|
|
858
|
-
options
|
|
874
|
+
options,
|
|
875
|
+
"merchantInfo.merchantId"
|
|
859
876
|
);
|
|
860
877
|
}
|
|
861
878
|
/**
|
|
@@ -870,7 +887,8 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
870
887
|
return this.httpClient.post(
|
|
871
888
|
this.getPath(_OrderResource.PATH_INQUIRY),
|
|
872
889
|
params,
|
|
873
|
-
options
|
|
890
|
+
options,
|
|
891
|
+
null
|
|
874
892
|
);
|
|
875
893
|
}
|
|
876
894
|
/**
|
|
@@ -888,7 +906,8 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
888
906
|
return this.httpClient.post(
|
|
889
907
|
this.getPath(_OrderResource.PATH_CANCEL),
|
|
890
908
|
params,
|
|
891
|
-
options
|
|
909
|
+
options,
|
|
910
|
+
"merchantId"
|
|
892
911
|
);
|
|
893
912
|
}
|
|
894
913
|
/**
|
|
@@ -906,7 +925,8 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
906
925
|
return this.httpClient.post(
|
|
907
926
|
this.getPath(_OrderResource.PATH_REFUND),
|
|
908
927
|
params,
|
|
909
|
-
options
|
|
928
|
+
options,
|
|
929
|
+
"merchantId"
|
|
910
930
|
);
|
|
911
931
|
}
|
|
912
932
|
/**
|
|
@@ -924,7 +944,8 @@ var OrderResource = class _OrderResource extends BaseResource {
|
|
|
924
944
|
return this.httpClient.post(
|
|
925
945
|
this.getPath(_OrderResource.PATH_CAPTURE),
|
|
926
946
|
params,
|
|
927
|
-
options
|
|
947
|
+
options,
|
|
948
|
+
"merchantId"
|
|
928
949
|
);
|
|
929
950
|
}
|
|
930
951
|
};
|
|
@@ -953,7 +974,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
953
974
|
return this.httpClient.post(
|
|
954
975
|
this.getPath(_SubscriptionResource.PATH_CREATE),
|
|
955
976
|
params,
|
|
956
|
-
options
|
|
977
|
+
options,
|
|
978
|
+
"merchantInfo.merchantId"
|
|
957
979
|
);
|
|
958
980
|
}
|
|
959
981
|
/**
|
|
@@ -968,7 +990,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
968
990
|
return this.httpClient.post(
|
|
969
991
|
this.getPath(_SubscriptionResource.PATH_INQUIRY),
|
|
970
992
|
params,
|
|
971
|
-
options
|
|
993
|
+
options,
|
|
994
|
+
null
|
|
972
995
|
);
|
|
973
996
|
}
|
|
974
997
|
/**
|
|
@@ -986,7 +1009,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
986
1009
|
return this.httpClient.post(
|
|
987
1010
|
this.getPath(_SubscriptionResource.PATH_CANCEL),
|
|
988
1011
|
params,
|
|
989
|
-
options
|
|
1012
|
+
options,
|
|
1013
|
+
"merchantId"
|
|
990
1014
|
);
|
|
991
1015
|
}
|
|
992
1016
|
/**
|
|
@@ -1001,7 +1025,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
1001
1025
|
return this.httpClient.post(
|
|
1002
1026
|
this.getPath(_SubscriptionResource.PATH_MANAGE),
|
|
1003
1027
|
params,
|
|
1004
|
-
options
|
|
1028
|
+
options,
|
|
1029
|
+
null
|
|
1005
1030
|
);
|
|
1006
1031
|
}
|
|
1007
1032
|
/**
|
|
@@ -1019,7 +1044,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
1019
1044
|
return this.httpClient.post(
|
|
1020
1045
|
this.getPath(_SubscriptionResource.PATH_UPDATE),
|
|
1021
1046
|
params,
|
|
1022
|
-
options
|
|
1047
|
+
options,
|
|
1048
|
+
null
|
|
1023
1049
|
);
|
|
1024
1050
|
}
|
|
1025
1051
|
/**
|
|
@@ -1070,7 +1096,8 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
1070
1096
|
return this.httpClient.post(
|
|
1071
1097
|
this.getPath(_SubscriptionResource.PATH_CHANGE),
|
|
1072
1098
|
params,
|
|
1073
|
-
options
|
|
1099
|
+
options,
|
|
1100
|
+
"merchantInfo.merchantId"
|
|
1074
1101
|
);
|
|
1075
1102
|
}
|
|
1076
1103
|
/**
|
|
@@ -1101,11 +1128,16 @@ var SubscriptionResource = class _SubscriptionResource extends BaseResource {
|
|
|
1101
1128
|
return await this.httpClient.post(
|
|
1102
1129
|
this.getPath(_SubscriptionResource.PATH_CHANGE_INQUIRY),
|
|
1103
1130
|
params,
|
|
1104
|
-
options
|
|
1131
|
+
options,
|
|
1132
|
+
null
|
|
1105
1133
|
);
|
|
1106
1134
|
} catch (error) {
|
|
1107
1135
|
if (error && typeof error === "object" && "errorCode" in error) {
|
|
1108
|
-
|
|
1136
|
+
const unknownStatus = error;
|
|
1137
|
+
return ApiResponse.error(
|
|
1138
|
+
String(unknownStatus.errorCode),
|
|
1139
|
+
String(unknownStatus.message || "Unknown error")
|
|
1140
|
+
);
|
|
1109
1141
|
}
|
|
1110
1142
|
throw error;
|
|
1111
1143
|
}
|
|
@@ -1127,7 +1159,8 @@ var RefundResource = class _RefundResource extends BaseResource {
|
|
|
1127
1159
|
return this.httpClient.post(
|
|
1128
1160
|
this.getPath(_RefundResource.PATH_INQUIRY),
|
|
1129
1161
|
params,
|
|
1130
|
-
options
|
|
1162
|
+
options,
|
|
1163
|
+
null
|
|
1131
1164
|
);
|
|
1132
1165
|
}
|
|
1133
1166
|
};
|
|
@@ -1147,7 +1180,8 @@ var MerchantConfigResource = class _MerchantConfigResource extends BaseResource
|
|
|
1147
1180
|
return this.httpClient.post(
|
|
1148
1181
|
this.getPath(_MerchantConfigResource.PATH_INQUIRY),
|
|
1149
1182
|
params,
|
|
1150
|
-
options
|
|
1183
|
+
options,
|
|
1184
|
+
"merchantId"
|
|
1151
1185
|
);
|
|
1152
1186
|
}
|
|
1153
1187
|
};
|
|
@@ -1167,7 +1201,8 @@ var PayMethodConfigResource = class _PayMethodConfigResource extends BaseResourc
|
|
|
1167
1201
|
return this.httpClient.post(
|
|
1168
1202
|
this.getPath(_PayMethodConfigResource.PATH_INQUIRY),
|
|
1169
1203
|
params,
|
|
1170
|
-
options
|
|
1204
|
+
options,
|
|
1205
|
+
"merchantId"
|
|
1171
1206
|
);
|
|
1172
1207
|
}
|
|
1173
1208
|
};
|
|
@@ -1187,7 +1222,8 @@ var WalletResource = class _WalletResource extends BaseResource {
|
|
|
1187
1222
|
return this.httpClient.post(
|
|
1188
1223
|
this.getPath(_WalletResource.PATH_INQUIRY),
|
|
1189
1224
|
params,
|
|
1190
|
-
options
|
|
1225
|
+
options,
|
|
1226
|
+
"merchantInfo.merchantId"
|
|
1191
1227
|
);
|
|
1192
1228
|
}
|
|
1193
1229
|
};
|