@waffo/waffo-node 3.0.1 → 3.2.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 +112 -20
- package/dist/index.d.mts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +88 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -73
- 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 9405bd4 -->
|
|
4
4
|
|
|
5
5
|
**English** | [中文](README_CN.md)
|
|
6
6
|
|
|
@@ -58,6 +58,7 @@ Official Node.js/TypeScript SDK for [Waffo Payment Platform](https://www.waffo.c
|
|
|
58
58
|
- [Support](#support)
|
|
59
59
|
- [License](#license)
|
|
60
60
|
- [Development & Testing](#development-testing)
|
|
61
|
+
- [Open Business Values and Custom Events](#open-business-values-and-custom-events)
|
|
61
62
|
|
|
62
63
|
## Requirements
|
|
63
64
|
|
|
@@ -527,6 +528,41 @@ if (response.isSuccess()) {
|
|
|
527
528
|
}
|
|
528
529
|
```
|
|
529
530
|
|
|
531
|
+
<!-- sdk-sync:start:Update%20Subscription -->
|
|
532
|
+
#### Update Subscription
|
|
533
|
+
|
|
534
|
+
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.
|
|
535
|
+
|
|
536
|
+
```typescript
|
|
537
|
+
const response = await waffo.subscription().update({
|
|
538
|
+
subscriptionId: 'subscription_id',
|
|
539
|
+
amount: '129.00', // New per-period amount from the next billing period
|
|
540
|
+
productInfo: {
|
|
541
|
+
trialPeriodAmount: '0',
|
|
542
|
+
scheduledAmounts: [
|
|
543
|
+
{ period: '2', amount: '99.00' }, // Per-period override
|
|
544
|
+
{ period: '3', amount: '129.00' },
|
|
545
|
+
],
|
|
546
|
+
},
|
|
547
|
+
topupInfo: {
|
|
548
|
+
topupRequest: 'mimo-topup-001', // Idempotency key for this top-up
|
|
549
|
+
topupAmount: '30.00', // Amount charged immediately
|
|
550
|
+
description: 'Seat add-on 3 seats',
|
|
551
|
+
orderExpiredAt: '2030-01-01T00:00:00Z',
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
if (response.isSuccess()) {
|
|
556
|
+
const data = response.getData();
|
|
557
|
+
console.log('Previous Amount:', data.previousAmount);
|
|
558
|
+
console.log('New Amount:', data.newAmount);
|
|
559
|
+
console.log('Next Effective Period:', data.nextEffectivePeriod);
|
|
560
|
+
console.log('Top-up Order:', data.topupInfo?.acquiringOrderId);
|
|
561
|
+
console.log('Top-up Status:', data.topupInfo?.topupStatus);
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
<!-- sdk-sync:end:Update%20Subscription -->
|
|
565
|
+
|
|
530
566
|
### Subscription Change (Upgrade/Downgrade)
|
|
531
567
|
|
|
532
568
|
Change an existing subscription to a new plan (upgrade or downgrade).
|
|
@@ -963,6 +999,7 @@ These two notification types share the same payload structure:
|
|
|
963
999
|
}
|
|
964
1000
|
```
|
|
965
1001
|
|
|
1002
|
+
<!-- sdk-sync:start:Payment%20Method%20Types -->
|
|
966
1003
|
## Payment Method Types
|
|
967
1004
|
|
|
968
1005
|
### payMethodType Reference
|
|
@@ -978,31 +1015,32 @@ These two notification types share the same payload structure:
|
|
|
978
1015
|
|
|
979
1016
|
### Usage Examples
|
|
980
1017
|
|
|
981
|
-
|
|
982
|
-
// Specify type only, let user choose on checkout page
|
|
983
|
-
paymentInfo: {
|
|
984
|
-
payMethodType: 'CREDITCARD',
|
|
985
|
-
}
|
|
1018
|
+
Specify a type and let the user choose on the checkout page:
|
|
986
1019
|
|
|
987
|
-
|
|
988
|
-
paymentInfo: {
|
|
989
|
-
|
|
990
|
-
payMethodName: 'CC_VISA',
|
|
991
|
-
}
|
|
1020
|
+
```json
|
|
1021
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD"}}
|
|
1022
|
+
```
|
|
992
1023
|
|
|
993
|
-
|
|
994
|
-
paymentInfo: {
|
|
995
|
-
payMethodType: 'CREDITCARD,DEBITCARD',
|
|
996
|
-
}
|
|
1024
|
+
Specify an exact payment method:
|
|
997
1025
|
|
|
998
|
-
|
|
999
|
-
paymentInfo: {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1026
|
+
```json
|
|
1027
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD", "payMethodName": "CC_VISA"}}
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
Combine multiple types:
|
|
1031
|
+
|
|
1032
|
+
```json
|
|
1033
|
+
{"paymentInfo": {"payMethodType": "CREDITCARD,DEBITCARD"}}
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
Select an e-wallet channel:
|
|
1037
|
+
|
|
1038
|
+
```json
|
|
1039
|
+
{"paymentInfo": {"payMethodType": "EWALLET", "payMethodName": "GCASH"}}
|
|
1003
1040
|
```
|
|
1004
1041
|
|
|
1005
1042
|
> **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).
|
|
1043
|
+
<!-- sdk-sync:end:Payment%20Method%20Types -->
|
|
1006
1044
|
|
|
1007
1045
|
## Advanced Configuration
|
|
1008
1046
|
|
|
@@ -1171,6 +1209,60 @@ const signature = RsaUtils.sign(data, privateKey);
|
|
|
1171
1209
|
const isValid = RsaUtils.verify(data, signature, publicKey);
|
|
1172
1210
|
```
|
|
1173
1211
|
|
|
1212
|
+
<!-- sdk-sync:start:Open%20Business%20Values%20and%20Custom%20Events -->
|
|
1213
|
+
## Open Business Values and Custom Events
|
|
1214
|
+
|
|
1215
|
+
Business fields accept arbitrary strings and preserve their original value, including new statuses, currencies, products, periods and actions. The known constants are convenience values. A parsed response or a successful API code does not establish payment success; compare the relevant business status explicitly.
|
|
1216
|
+
|
|
1217
|
+
### Read protocol values without changing existing calls
|
|
1218
|
+
|
|
1219
|
+
These offline examples show the real SDK model/accessor APIs. `FUTURE_STATUS` is synthetic and does not declare server support. Parsing or API code success does not establish business success.
|
|
1220
|
+
|
|
1221
|
+
```typescript
|
|
1222
|
+
// Existing aliases/getData stay compatible; getData can contain future strings.
|
|
1223
|
+
// getOpenData/OpenBusinessValues opt into open strings: handle a default branch.
|
|
1224
|
+
// create/change preserve required fields; concrete eventType types stay fixed.
|
|
1225
|
+
import { ApiResponse, type InquirySubscriptionData } from '@waffo/waffo-node';
|
|
1226
|
+
|
|
1227
|
+
const source = JSON.parse('{"subscriptionStatus":"ACTIVE","paymentDetails":[{"orderStatus":"INIT"}]}');
|
|
1228
|
+
const response = ApiResponse.success<InquirySubscriptionData>(source);
|
|
1229
|
+
const data = response.getOpenData();
|
|
1230
|
+
console.log(data?.subscriptionStatus, data?.paymentDetails?.[0]?.orderStatus);
|
|
1231
|
+
if (data?.subscriptionStatus === 'FUTURE_STATUS') {
|
|
1232
|
+
console.warn('Unsupported business status:', data.subscriptionStatus);
|
|
1233
|
+
}
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
`WebhookEventType` and concrete built-in notification types remain the known event catalogue. Unknown events return a signed failure unless your application registers that exact name. Register before serving callbacks; custom registrations are per instance, case-sensitive, and a later registration replaces the same name. Built-in names use their dedicated methods. Blank names and invalid callbacks/configuration fail at registration with `S0006`; PHP rejects non-callable arguments with its native `TypeError`.
|
|
1237
|
+
|
|
1238
|
+
Java, Python and PHP custom callbacks must complete synchronously; PHP Promise/generator callbacks are unsupported. Python rejects async functions at registration and returns failure for an unexpected awaitable result. Node.js explicitly supports Promise callbacks.
|
|
1239
|
+
|
|
1240
|
+
The examples below take the **raw, unmodified UTF-8 body file** as their first argument and `WAFFO_WEBHOOK_SIGNATURE` as the request signature. Set `WAFFO_API_KEY`, `WAFFO_PRIVATE_KEY`, `WAFFO_PUBLIC_KEY` and Java/Python's `WAFFO_MERCHANT_ID` using your authorized configuration. They print the signed response header/body; in your HTTP adapter send those bytes with HTTP 200 and the `X-SIGNATURE` header. `EXAMPLE_CUSTOM_NOTIFICATION` is an offline example name: replace it and implement your business action against the event's real contract. Reject/throw/return an error if processing fails; Node.js awaits the callback, and Go converts callback errors or panics into failure responses.
|
|
1241
|
+
|
|
1242
|
+
```typescript
|
|
1243
|
+
import { readFileSync } from 'node:fs';
|
|
1244
|
+
import { WebhookHandler, Environment } from '@waffo/waffo-node';
|
|
1245
|
+
|
|
1246
|
+
async function main() {
|
|
1247
|
+
const handler = new WebhookHandler({
|
|
1248
|
+
apiKey: process.env.WAFFO_API_KEY!,
|
|
1249
|
+
privateKey: process.env.WAFFO_PRIVATE_KEY!,
|
|
1250
|
+
waffoPublicKey: process.env.WAFFO_PUBLIC_KEY!,
|
|
1251
|
+
environment: Environment.SANDBOX,
|
|
1252
|
+
}).onEvent('EXAMPLE_CUSTOM_NOTIFICATION', async notification => {
|
|
1253
|
+
// Validate the event's documented fields and perform your business action here.
|
|
1254
|
+
console.error('Handled custom event:', notification.eventType);
|
|
1255
|
+
});
|
|
1256
|
+
const body = readFileSync(process.argv[2], 'utf8');
|
|
1257
|
+
const result = await handler.handleWebhook(body, process.env.WAFFO_WEBHOOK_SIGNATURE ?? '');
|
|
1258
|
+
if (!result.success) console.error(result.error);
|
|
1259
|
+
console.log('X-SIGNATURE: ' + result.responseSignature);
|
|
1260
|
+
console.log(result.responseBody);
|
|
1261
|
+
}
|
|
1262
|
+
main().catch(error => { console.error(error); process.exitCode = 1; });
|
|
1263
|
+
```
|
|
1264
|
+
<!-- sdk-sync:end:Open%20Business%20Values%20and%20Custom%20Events -->
|
|
1265
|
+
|
|
1174
1266
|
## Handling New API Fields (ExtraParams)
|
|
1175
1267
|
|
|
1176
1268
|
When Waffo API adds new fields that are not yet defined in the SDK, you can use the ExtraParams feature to access these fields without waiting for an SDK update.
|
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
|
/**
|
|
@@ -1569,6 +1607,7 @@ declare class WebhookHandler {
|
|
|
1569
1607
|
private subscriptionPaymentHandler?;
|
|
1570
1608
|
private subscriptionPeriodChangedHandler?;
|
|
1571
1609
|
private subscriptionChangeHandler?;
|
|
1610
|
+
private readonly customEventHandlers;
|
|
1572
1611
|
constructor(config: WaffoConfig);
|
|
1573
1612
|
/**
|
|
1574
1613
|
* Registers a handler for payment notifications.
|
|
@@ -1595,6 +1634,8 @@ declare class WebhookHandler {
|
|
|
1595
1634
|
* Registers a handler for subscription change notifications.
|
|
1596
1635
|
*/
|
|
1597
1636
|
onSubscriptionChange(handler: SubscriptionChangeHandler): this;
|
|
1637
|
+
/** Registers an exact custom event name before receiving webhooks. Later registration replaces the same name. */
|
|
1638
|
+
onEvent(eventType: string, handler: (notification: BaseNotification & Record<string, unknown>) => void | Promise<void>): this;
|
|
1598
1639
|
/**
|
|
1599
1640
|
* Processes a webhook notification.
|
|
1600
1641
|
*
|
|
@@ -1629,6 +1670,11 @@ declare class WebhookHandler {
|
|
|
1629
1670
|
private createFailedResult;
|
|
1630
1671
|
}
|
|
1631
1672
|
|
|
1673
|
+
/** Optional view for JSON business data that preserves future protocol strings. */
|
|
1674
|
+
type OpenBusinessValues<T> = T extends string ? string : T extends object ? {
|
|
1675
|
+
[K in keyof T]: K extends 'eventType' ? T[K] : OpenBusinessValues<T[K]>;
|
|
1676
|
+
} : T;
|
|
1677
|
+
|
|
1632
1678
|
/**
|
|
1633
1679
|
* Generic API response wrapper.
|
|
1634
1680
|
*
|
|
@@ -1679,6 +1725,8 @@ declare class ApiResponse<T> {
|
|
|
1679
1725
|
* @returns The response data, or undefined if the response is an error
|
|
1680
1726
|
*/
|
|
1681
1727
|
getData(): T | undefined;
|
|
1728
|
+
/** Returns the same JSON data with business string literals opened to future values. */
|
|
1729
|
+
getOpenData(): OpenBusinessValues<T> | undefined;
|
|
1682
1730
|
/**
|
|
1683
1731
|
* Gets the error message.
|
|
1684
1732
|
*
|
|
@@ -1700,6 +1748,7 @@ declare class ApiResponse<T> {
|
|
|
1700
1748
|
getDataOrThrow(): T;
|
|
1701
1749
|
}
|
|
1702
1750
|
|
|
1751
|
+
type MerchantIdPath = 'merchantInfo.merchantId' | 'merchantId' | null;
|
|
1703
1752
|
/**
|
|
1704
1753
|
* HTTP client for making requests to the Waffo API.
|
|
1705
1754
|
*
|
|
@@ -1726,10 +1775,11 @@ declare class WaffoHttpClient {
|
|
|
1726
1775
|
* @param path - API endpoint path (e.g., "/order/create")
|
|
1727
1776
|
* @param request - Request body
|
|
1728
1777
|
* @param options - Per-request options
|
|
1778
|
+
* @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
|
|
1729
1779
|
* @returns API response
|
|
1730
1780
|
* @throws WaffoUnknownStatusError for network errors or unknown status
|
|
1731
1781
|
*/
|
|
1732
|
-
post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
|
|
1782
|
+
post<T extends object, R>(path: string, request: T, options?: RequestOptions, merchantIdPath?: MerchantIdPath): Promise<ApiResponse<R>>;
|
|
1733
1783
|
/**
|
|
1734
1784
|
* Parses the API response body.
|
|
1735
1785
|
*/
|
|
@@ -1889,6 +1939,7 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1889
1939
|
* @returns API response with subscription data
|
|
1890
1940
|
* @throws WaffoUnknownStatusError for network errors
|
|
1891
1941
|
*/
|
|
1942
|
+
create(params: OpenBusinessValues<CreateSubscriptionParams>, options?: RequestOptions): Promise<ApiResponse<CreateSubscriptionData>>;
|
|
1892
1943
|
create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<CreateSubscriptionData>>;
|
|
1893
1944
|
/**
|
|
1894
1945
|
* Queries an existing subscription.
|
|
@@ -1970,6 +2021,7 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1970
2021
|
* }
|
|
1971
2022
|
* ```
|
|
1972
2023
|
*/
|
|
2024
|
+
change(params: OpenBusinessValues<SubscriptionChangeParams>, options?: RequestOptions): Promise<ApiResponse<SubscriptionChangeData>>;
|
|
1973
2025
|
change(params: SubscriptionChangeParams, options?: RequestOptions): Promise<ApiResponse<SubscriptionChangeData>>;
|
|
1974
2026
|
/**
|
|
1975
2027
|
* Queries the status of a subscription change.
|
|
@@ -2618,4 +2670,4 @@ declare const RsaUtils: {
|
|
|
2618
2670
|
generateKeyPair: typeof generateKeyPair;
|
|
2619
2671
|
};
|
|
2620
2672
|
|
|
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 };
|
|
2673
|
+
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, type OpenBusinessValues, 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
|
/**
|
|
@@ -1569,6 +1607,7 @@ declare class WebhookHandler {
|
|
|
1569
1607
|
private subscriptionPaymentHandler?;
|
|
1570
1608
|
private subscriptionPeriodChangedHandler?;
|
|
1571
1609
|
private subscriptionChangeHandler?;
|
|
1610
|
+
private readonly customEventHandlers;
|
|
1572
1611
|
constructor(config: WaffoConfig);
|
|
1573
1612
|
/**
|
|
1574
1613
|
* Registers a handler for payment notifications.
|
|
@@ -1595,6 +1634,8 @@ declare class WebhookHandler {
|
|
|
1595
1634
|
* Registers a handler for subscription change notifications.
|
|
1596
1635
|
*/
|
|
1597
1636
|
onSubscriptionChange(handler: SubscriptionChangeHandler): this;
|
|
1637
|
+
/** Registers an exact custom event name before receiving webhooks. Later registration replaces the same name. */
|
|
1638
|
+
onEvent(eventType: string, handler: (notification: BaseNotification & Record<string, unknown>) => void | Promise<void>): this;
|
|
1598
1639
|
/**
|
|
1599
1640
|
* Processes a webhook notification.
|
|
1600
1641
|
*
|
|
@@ -1629,6 +1670,11 @@ declare class WebhookHandler {
|
|
|
1629
1670
|
private createFailedResult;
|
|
1630
1671
|
}
|
|
1631
1672
|
|
|
1673
|
+
/** Optional view for JSON business data that preserves future protocol strings. */
|
|
1674
|
+
type OpenBusinessValues<T> = T extends string ? string : T extends object ? {
|
|
1675
|
+
[K in keyof T]: K extends 'eventType' ? T[K] : OpenBusinessValues<T[K]>;
|
|
1676
|
+
} : T;
|
|
1677
|
+
|
|
1632
1678
|
/**
|
|
1633
1679
|
* Generic API response wrapper.
|
|
1634
1680
|
*
|
|
@@ -1679,6 +1725,8 @@ declare class ApiResponse<T> {
|
|
|
1679
1725
|
* @returns The response data, or undefined if the response is an error
|
|
1680
1726
|
*/
|
|
1681
1727
|
getData(): T | undefined;
|
|
1728
|
+
/** Returns the same JSON data with business string literals opened to future values. */
|
|
1729
|
+
getOpenData(): OpenBusinessValues<T> | undefined;
|
|
1682
1730
|
/**
|
|
1683
1731
|
* Gets the error message.
|
|
1684
1732
|
*
|
|
@@ -1700,6 +1748,7 @@ declare class ApiResponse<T> {
|
|
|
1700
1748
|
getDataOrThrow(): T;
|
|
1701
1749
|
}
|
|
1702
1750
|
|
|
1751
|
+
type MerchantIdPath = 'merchantInfo.merchantId' | 'merchantId' | null;
|
|
1703
1752
|
/**
|
|
1704
1753
|
* HTTP client for making requests to the Waffo API.
|
|
1705
1754
|
*
|
|
@@ -1726,10 +1775,11 @@ declare class WaffoHttpClient {
|
|
|
1726
1775
|
* @param path - API endpoint path (e.g., "/order/create")
|
|
1727
1776
|
* @param request - Request body
|
|
1728
1777
|
* @param options - Per-request options
|
|
1778
|
+
* @param merchantIdPath - Contract path for merchantId, null for no injection, or omitted for legacy inference
|
|
1729
1779
|
* @returns API response
|
|
1730
1780
|
* @throws WaffoUnknownStatusError for network errors or unknown status
|
|
1731
1781
|
*/
|
|
1732
|
-
post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
|
|
1782
|
+
post<T extends object, R>(path: string, request: T, options?: RequestOptions, merchantIdPath?: MerchantIdPath): Promise<ApiResponse<R>>;
|
|
1733
1783
|
/**
|
|
1734
1784
|
* Parses the API response body.
|
|
1735
1785
|
*/
|
|
@@ -1889,6 +1939,7 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1889
1939
|
* @returns API response with subscription data
|
|
1890
1940
|
* @throws WaffoUnknownStatusError for network errors
|
|
1891
1941
|
*/
|
|
1942
|
+
create(params: OpenBusinessValues<CreateSubscriptionParams>, options?: RequestOptions): Promise<ApiResponse<CreateSubscriptionData>>;
|
|
1892
1943
|
create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<CreateSubscriptionData>>;
|
|
1893
1944
|
/**
|
|
1894
1945
|
* Queries an existing subscription.
|
|
@@ -1970,6 +2021,7 @@ declare class SubscriptionResource extends BaseResource {
|
|
|
1970
2021
|
* }
|
|
1971
2022
|
* ```
|
|
1972
2023
|
*/
|
|
2024
|
+
change(params: OpenBusinessValues<SubscriptionChangeParams>, options?: RequestOptions): Promise<ApiResponse<SubscriptionChangeData>>;
|
|
1973
2025
|
change(params: SubscriptionChangeParams, options?: RequestOptions): Promise<ApiResponse<SubscriptionChangeData>>;
|
|
1974
2026
|
/**
|
|
1975
2027
|
* Queries the status of a subscription change.
|
|
@@ -2618,4 +2670,4 @@ declare const RsaUtils: {
|
|
|
2618
2670
|
generateKeyPair: typeof generateKeyPair;
|
|
2619
2671
|
};
|
|
2620
2672
|
|
|
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 };
|
|
2673
|
+
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, type OpenBusinessValues, 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 };
|