@waffo/waffo-node 2.1.0 → 2.3.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/dist/index.d.ts CHANGED
@@ -170,1175 +170,1283 @@ interface RequestOptions {
170
170
  }
171
171
 
172
172
  /**
173
- * Webhook event types sent by Waffo.
173
+ * Subscription-related type definitions.
174
+ *
175
+ * Note: Full type definitions should be generated from openapi.json.
176
+ * These are placeholder interfaces for the SDK structure.
174
177
  */
175
- declare enum WebhookEventType {
176
- PAYMENT_NOTIFICATION = "PAYMENT_NOTIFICATION",
177
- REFUND_NOTIFICATION = "REFUND_NOTIFICATION",
178
- SUBSCRIPTION_STATUS_NOTIFICATION = "SUBSCRIPTION_STATUS_NOTIFICATION",
179
- SUBSCRIPTION_PAYMENT_NOTIFICATION = "SUBSCRIPTION_PAYMENT_NOTIFICATION",
180
- SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION = "SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION"
181
- }
182
178
  /**
183
- * Result of webhook handling.
179
+ * Create subscription request parameters.
184
180
  */
185
- interface WebhookResult {
186
- /** Whether the webhook was processed successfully */
187
- success: boolean;
188
- /** Response body to send back to Waffo */
189
- responseBody: string;
190
- /** Signature for the response body */
191
- responseSignature: string;
192
- /** Error message if processing failed */
193
- error?: string;
181
+ interface CreateSubscriptionParams {
182
+ /**
183
+ * Subscription request ID sent from Merchant (max 32 characters).
184
+ * Used for idempotent check.
185
+ */
186
+ subscriptionRequest: string;
187
+ merchantSubscriptionId: string;
188
+ currency: string;
189
+ amount: string;
190
+ notifyUrl: string;
191
+ productInfo: ProductInfo;
192
+ userInfo: SubscriptionUserInfo;
193
+ paymentInfo: SubscriptionPaymentInfo;
194
+ merchantInfo?: SubscriptionMerchantInfo;
195
+ goodsInfo?: {
196
+ goodsId: string;
197
+ goodsName: string;
198
+ goodsCategory?: string;
199
+ goodsUrl?: string;
200
+ goodsQuantity?: number;
201
+ [key: string]: unknown;
202
+ };
203
+ successRedirectUrl?: string;
204
+ failedRedirectUrl?: string;
205
+ cancelRedirectUrl?: string;
206
+ subscriptionManagementUrl?: string;
207
+ requestedAt?: string;
208
+ extendInfo?: string;
209
+ /**
210
+ * Order expiry time (ISO 8601 format, max 24 characters).
211
+ */
212
+ orderExpiredAt?: string;
213
+ [key: string]: unknown;
194
214
  }
195
215
  /**
196
- * Base notification interface.
216
+ * Create subscription response data.
197
217
  */
198
- interface BaseNotification {
199
- eventType: string;
218
+ interface CreateSubscriptionData {
219
+ subscriptionRequest?: string;
220
+ merchantSubscriptionId?: string;
221
+ subscriptionId?: string;
222
+ subscriptionStatus?: SubscriptionStatus;
223
+ subscriptionAction?: string;
224
+ [key: string]: unknown;
200
225
  }
201
226
  /**
202
- * Payment notification from Waffo.
227
+ * Inquiry subscription request parameters.
203
228
  */
204
- interface PaymentNotification extends BaseNotification {
205
- eventType: 'PAYMENT_NOTIFICATION';
206
- acquiringOrderId?: string;
207
- merchantOrderId?: string;
208
- paymentRequestId?: string;
209
- orderStatus?: string;
210
- orderAmount?: string;
211
- orderCurrency?: string;
212
- finalDealAmount?: string;
229
+ interface InquirySubscriptionParams {
230
+ subscriptionRequest?: string;
231
+ subscriptionId?: string;
232
+ merchantInfo?: SubscriptionMerchantInfo;
213
233
  [key: string]: unknown;
214
234
  }
215
235
  /**
216
- * Refund notification from Waffo.
236
+ * Inquiry subscription response data.
217
237
  */
218
- interface RefundNotification extends BaseNotification {
219
- eventType: 'REFUND_NOTIFICATION';
220
- acquiringRefundOrderId?: string;
221
- refundRequestId?: string;
222
- refundStatus?: string;
223
- refundAmount?: string;
238
+ interface InquirySubscriptionData {
239
+ subscriptionRequest?: string;
240
+ merchantSubscriptionId?: string;
241
+ subscriptionId?: string;
242
+ payMethodSubscriptionId?: string;
243
+ subscriptionStatus?: SubscriptionStatus;
244
+ subscriptionAction?: string;
245
+ currency?: string;
246
+ userCurrency?: string;
247
+ amount?: string;
248
+ productInfo?: ProductInfo;
224
249
  [key: string]: unknown;
225
250
  }
226
251
  /**
227
- * Subscription status notification from Waffo.
252
+ * Cancel subscription request parameters.
228
253
  */
229
- interface SubscriptionStatusNotification extends BaseNotification {
230
- eventType: 'SUBSCRIPTION_STATUS_NOTIFICATION';
254
+ interface CancelSubscriptionParams {
231
255
  subscriptionId?: string;
232
- subscriptionStatus?: string;
256
+ merchantId?: string;
257
+ requestedAt?: string;
233
258
  [key: string]: unknown;
234
259
  }
235
260
  /**
236
- * Subscription payment notification from Waffo.
261
+ * Cancel subscription response data.
237
262
  */
238
- interface SubscriptionPaymentNotification extends BaseNotification {
239
- eventType: 'SUBSCRIPTION_PAYMENT_NOTIFICATION';
263
+ interface CancelSubscriptionData {
264
+ subscriptionRequest?: string;
265
+ merchantSubscriptionId?: string;
240
266
  subscriptionId?: string;
241
- acquiringOrderId?: string;
242
- orderStatus?: string;
267
+ subscriptionStatus?: SubscriptionStatus;
243
268
  [key: string]: unknown;
244
269
  }
245
270
  /**
246
- * Subscription period changed notification from Waffo.
271
+ * Manage subscription request parameters.
247
272
  */
248
- interface SubscriptionPeriodChangedNotification extends BaseNotification {
249
- eventType: 'SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION';
273
+ interface ManageSubscriptionParams {
274
+ subscriptionId: string;
275
+ merchantId: string;
276
+ action: SubscriptionManageAction;
277
+ newAmount?: string;
278
+ newPeriodType?: PeriodType;
279
+ newPeriodValue?: number;
280
+ requestedAt?: string;
281
+ [key: string]: unknown;
282
+ }
283
+ /**
284
+ * Manage subscription response data.
285
+ */
286
+ interface ManageSubscriptionData {
250
287
  subscriptionId?: string;
288
+ subscriptionStatus?: SubscriptionStatus;
251
289
  [key: string]: unknown;
252
290
  }
253
- type PaymentHandler = (notification: PaymentNotification) => void | Promise<void>;
254
- type RefundHandler = (notification: RefundNotification) => void | Promise<void>;
255
- type SubscriptionStatusHandler = (notification: SubscriptionStatusNotification) => void | Promise<void>;
256
- type SubscriptionPaymentHandler = (notification: SubscriptionPaymentNotification) => void | Promise<void>;
257
- type SubscriptionPeriodChangedHandler = (notification: SubscriptionPeriodChangedNotification) => void | Promise<void>;
258
291
  /**
259
- * Webhook handler for processing Waffo webhook notifications.
260
- *
261
- * @example
262
- * ```typescript
263
- * // Setup handler
264
- * const handler = waffo.webhook()
265
- * .onPayment((notification) => {
266
- * console.log('Payment:', notification.orderStatus);
267
- * })
268
- * .onRefund((notification) => {
269
- * console.log('Refund:', notification.refundStatus);
270
- * });
271
- *
272
- * // Process webhook (e.g., in Express.js)
273
- * app.post('/webhook', async (req, res) => {
274
- * const body = req.body.toString();
275
- * const signature = req.headers['x-signature'];
276
- * const result = await handler.handleWebhook(body, signature);
277
- *
278
- * res.setHeader('X-SIGNATURE', result.responseSignature);
279
- * res.status(200).send(result.responseBody);
280
- * });
281
- * ```
292
+ * Subscription status enum.
293
+ * Based on openapi.json SubscriptionInquiryResponse.subscriptionStatus.
282
294
  */
283
- declare class WebhookHandler {
284
- private readonly waffoPublicKey;
285
- private readonly privateKey;
286
- private readonly logger?;
287
- private paymentHandler?;
288
- private refundHandler?;
289
- private subscriptionStatusHandler?;
290
- private subscriptionPaymentHandler?;
291
- private subscriptionPeriodChangedHandler?;
292
- constructor(config: WaffoConfig);
295
+ type SubscriptionStatus = 'AUTHORIZATION_REQUIRED' | 'IN_PROGRESS' | 'ACTIVE' | 'CLOSE' | 'MERCHANT_CANCELLED' | 'USER_CANCELLED' | 'CHANNEL_CANCELLED' | 'EXPIRED';
296
+ /**
297
+ * Subscription manage action enum.
298
+ */
299
+ type SubscriptionManageAction = 'PAUSE' | 'RESUME' | 'UPDATE_AMOUNT' | 'UPDATE_PERIOD';
300
+ /**
301
+ * Period type enum.
302
+ * Values: DAILY, WEEKLY, MONTHLY
303
+ */
304
+ type PeriodType = 'DAILY' | 'WEEKLY' | 'MONTHLY';
305
+ /**
306
+ * Product information for subscription.
307
+ * Based on openapi.json ProductInfo schema.
308
+ */
309
+ interface ProductInfo {
293
310
  /**
294
- * Registers a handler for payment notifications.
311
+ * Subscription product description (max 128 characters).
312
+ * Often appearing to user when asking user's confirmation.
295
313
  */
296
- onPayment(handler: PaymentHandler): this;
314
+ description: string;
297
315
  /**
298
- * Registers a handler for refund notifications.
316
+ * Subscription product period type: DAILY, WEEKLY, MONTHLY.
299
317
  */
300
- onRefund(handler: RefundHandler): this;
318
+ periodType: PeriodType;
301
319
  /**
302
- * Registers a handler for subscription status notifications.
320
+ * Period interval (max 12 characters).
321
+ * - DAILY: 1-365
322
+ * - WEEKLY: 1-4
323
+ * - MONTHLY: 1-12
303
324
  */
304
- onSubscriptionStatus(handler: SubscriptionStatusHandler): this;
325
+ periodInterval: string;
305
326
  /**
306
- * Registers a handler for subscription payment notifications.
327
+ * Number of billing periods until subscription ends (max 24 characters).
328
+ * Empty means no defined end period.
307
329
  */
308
- onSubscriptionPayment(handler: SubscriptionPaymentHandler): this;
330
+ numberOfPeriod?: string;
309
331
  /**
310
- * Registers a handler for subscription period changed notifications.
332
+ * Trial period amount (max 24 characters).
311
333
  */
312
- onSubscriptionPeriodChanged(handler: SubscriptionPeriodChangedHandler): this;
334
+ trialPeriodAmount?: string;
313
335
  /**
314
- * Processes a webhook notification.
315
- *
316
- * @param body - The raw webhook body
317
- * @param signature - The X-SIGNATURE header value
318
- * @returns Result with response body and signature
336
+ * Number of trial periods (max 12 characters).
319
337
  */
320
- handleWebhook(body: string, signature: string): Promise<WebhookResult>;
338
+ numberOfTrialPeriod?: string;
321
339
  /**
322
- * Verifies a webhook signature.
323
- *
324
- * @param body - The raw webhook body
325
- * @param signature - The X-SIGNATURE header value
326
- * @returns true if signature is valid
340
+ * Trial period type: DAILY, WEEKLY, MONTHLY.
341
+ * If omitted, uses periodType value by default.
327
342
  */
328
- verifySignature(body: string, signature: string): boolean;
343
+ trialPeriodType?: PeriodType;
329
344
  /**
330
- * Builds a success response with signature.
345
+ * Trial period interval (max 12 characters).
346
+ * If omitted, uses periodInterval value by default.
331
347
  */
332
- buildSuccessResponse(): {
333
- body: string;
334
- signature: string;
335
- };
348
+ trialPeriodInterval?: string;
336
349
  /**
337
- * Builds a failed response with signature.
350
+ * When the subscription starts (ISO 8601 format).
338
351
  */
339
- buildFailedResponse(message: string): {
340
- body: string;
341
- signature: string;
342
- };
343
- private createSuccessResult;
344
- private createFailedResult;
345
- }
346
-
347
- /**
348
- * Generic API response wrapper.
349
- *
350
- * All API responses are wrapped in this class for consistent handling.
351
- *
352
- * @example
353
- * ```typescript
354
- * const response = await waffo.order().create(params);
355
- *
356
- * if (response.isSuccess()) {
357
- * const data = response.getData();
358
- * console.log('Order ID:', data?.acquiringOrderId);
359
- * } else {
360
- * console.error(`Error [${response.code}]: ${response.getMessage()}`);
361
- * }
362
- * ```
363
- */
364
- declare class ApiResponse<T> {
365
- /** Response code. "0" indicates success, other values indicate errors. */
366
- readonly code: string;
367
- /** Response data (present when code is "0") */
368
- readonly data?: T;
369
- /** Error message (present when code is not "0") */
370
- readonly message?: string;
371
- private constructor();
352
+ startDateTime?: string;
372
353
  /**
373
- * Creates a successful response.
374
- *
375
- * @param data - The response data
354
+ * When the subscription ends (ISO 8601 format).
376
355
  */
377
- static success<T>(data?: T): ApiResponse<T>;
356
+ endDateTime?: string;
378
357
  /**
379
- * Creates an error response.
380
- *
381
- * @param code - The error code
382
- * @param message - The error message
358
+ * When the next payment is due (ISO 8601 format).
383
359
  */
384
- static error<T>(code: string, message?: string): ApiResponse<T>;
360
+ nextPaymentDateTime?: string;
385
361
  /**
386
- * Checks if the response indicates success.
387
- *
388
- * @returns true if the response code is "0"
362
+ * Current billing period number.
389
363
  */
390
- isSuccess(): boolean;
364
+ currentPeriod?: string;
365
+ [key: string]: unknown;
366
+ }
367
+ /**
368
+ * User information for subscription.
369
+ */
370
+ interface SubscriptionUserInfo {
371
+ userId: string;
372
+ userEmail: string;
373
+ userPhone?: string;
374
+ userFirstName?: string;
375
+ userLastName?: string;
376
+ userCountryCode?: string;
377
+ userBrowserIp?: string;
378
+ userAgent?: string;
379
+ [key: string]: unknown;
380
+ }
381
+ /**
382
+ * Payment information for subscription.
383
+ */
384
+ interface SubscriptionPaymentInfo {
385
+ productName: string;
386
+ payMethodType?: string;
387
+ payMethodName?: string;
388
+ [key: string]: unknown;
389
+ }
390
+ /**
391
+ * Merchant information for subscription.
392
+ */
393
+ interface SubscriptionMerchantInfo {
394
+ merchantId: string;
395
+ subMerchantId?: string;
396
+ [key: string]: unknown;
397
+ }
398
+ /**
399
+ * Subscription information in payment order response and webhook notifications.
400
+ */
401
+ interface SubscriptionInfo {
391
402
  /**
392
- * Gets the response data.
393
- *
394
- * @returns The response data, or undefined if the response is an error
403
+ * Subscription request ID (max 32 characters).
404
+ * @deprecated Use merchantRequest instead for consistency with OpenAPI spec.
395
405
  */
396
- getData(): T | undefined;
406
+ subscriptionRequest?: string;
397
407
  /**
398
- * Gets the error message.
399
- *
400
- * @returns The error message, or undefined if the response is successful
408
+ * Merchant request ID (max 32 characters).
409
+ * Same as subscriptionRequest, aligned with OpenAPI specification.
401
410
  */
402
- getMessage(): string | undefined;
411
+ merchantRequest?: string;
403
412
  /**
404
- * Gets the response code.
405
- *
406
- * @returns The response code
413
+ * Waffo subscription ID (max 64 characters).
407
414
  */
408
- getCode(): string;
415
+ subscriptionId?: string;
409
416
  /**
410
- * Gets the response data or throws an error.
411
- *
412
- * @returns The response data
413
- * @throws Error if the response is not successful or data is undefined
417
+ * Which period the subscription payment belongs to (max 12 characters).
414
418
  */
415
- getDataOrThrow(): T;
419
+ period?: string;
420
+ [key: string]: unknown;
416
421
  }
417
-
418
422
  /**
419
- * HTTP client for making requests to the Waffo API.
420
- *
421
- * Handles:
422
- * - Request signing with merchant's private key
423
- * - Response signature verification with Waffo's public key
424
- * - MerchantId auto-injection
425
- * - Error handling and timeout management
423
+ * Subscription change status values.
426
424
  */
427
- declare class WaffoHttpClient {
428
- private readonly baseUrl;
429
- private readonly apiKey;
430
- private readonly privateKey;
431
- private readonly waffoPublicKey;
432
- private readonly merchantId;
433
- private readonly connectTimeout;
434
- private readonly readTimeout;
435
- private readonly logger?;
436
- private readonly httpTransport;
437
- constructor(config: WaffoConfig);
425
+ type SubscriptionChangeStatus = 'IN_PROGRESS' | 'AUTHORIZATION_REQUIRED' | 'SUCCESS' | 'CLOSED';
426
+ /**
427
+ * Product information for subscription change operations.
428
+ * Contains billing period settings for the new subscription plan.
429
+ */
430
+ interface SubscriptionChangeProductInfo {
438
431
  /**
439
- * Sends a POST request to the Waffo API.
440
- *
441
- * @param path - API endpoint path (e.g., "/order/create")
442
- * @param request - Request body
443
- * @param options - Per-request options
444
- * @returns API response
445
- * @throws WaffoUnknownStatusError for network errors or unknown status
432
+ * Product description (max 128 characters).
446
433
  */
447
- post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
434
+ description: string;
448
435
  /**
449
- * Parses the API response body.
436
+ * Billing period type: DAILY, WEEKLY, MONTHLY.
450
437
  */
451
- private parseResponse;
438
+ periodType: PeriodType;
452
439
  /**
453
- * Auto-injects merchantId into the request if configured.
440
+ * Subscription amount for this product (max 12 characters).
454
441
  */
455
- private injectMerchantIdIfNeeded;
442
+ amount: string;
456
443
  /**
457
- * Checks if the error is a network-related error.
444
+ * Billing interval (max 12 characters).
458
445
  */
459
- private isNetworkError;
460
- }
461
-
462
- /**
463
- * Base class for API resources.
464
- */
465
- declare abstract class BaseResource {
466
- protected readonly httpClient: WaffoHttpClient;
467
- protected readonly basePath: string;
468
- constructor(httpClient: WaffoHttpClient, basePath: string);
446
+ periodInterval: string;
469
447
  /**
470
- * Gets the full path for an endpoint.
471
- *
472
- * @param endpoint - The endpoint (e.g., "/create")
473
- * @returns Full path (e.g., "/order/create")
448
+ * Total number of billing periods (max 24 characters, empty for unlimited).
474
449
  */
475
- protected getPath(endpoint: string): string;
450
+ numberOfPeriod?: string;
451
+ /**
452
+ * Trial period amount (max 24 characters).
453
+ */
454
+ trialPeriodAmount?: string;
455
+ /**
456
+ * Number of trial periods (max 12 characters).
457
+ */
458
+ numberOfTrialPeriod?: string;
459
+ /**
460
+ * Trial period type: DAILY, WEEKLY, MONTHLY.
461
+ */
462
+ trialPeriodType?: PeriodType;
463
+ /**
464
+ * Trial period interval (max 12 characters).
465
+ */
466
+ trialPeriodInterval?: string;
467
+ [key: string]: unknown;
476
468
  }
477
-
478
- /**
479
- * Order-related type definitions.
480
- *
481
- * Note: Full type definitions should be generated from openapi.json.
482
- * These are placeholder interfaces for the SDK structure.
483
- */
484
469
  /**
485
- * Create order request parameters.
470
+ * Subscription change request parameters.
486
471
  */
487
- interface CreateOrderParams {
488
- paymentRequestId: string;
489
- merchantOrderId: string;
490
- orderCurrency: string;
491
- orderAmount: string;
492
- orderDescription: string;
493
- notifyUrl: string;
494
- userInfo: UserInfo;
495
- paymentInfo: PaymentInfo;
496
- merchantInfo?: MerchantInfo;
497
- goodsInfo?: GoodsInfo;
498
- addressInfo?: AddressInfo;
499
- cardInfo?: CardInfo;
500
- riskData?: RiskData;
472
+ interface SubscriptionChangeParams {
473
+ /**
474
+ * New unique request ID for this change (max 32 characters).
475
+ */
476
+ subscriptionRequest: string;
477
+ /**
478
+ * New merchant subscription plan ID (max 64 characters).
479
+ */
480
+ merchantSubscriptionId?: string;
481
+ /**
482
+ * Original subscription request ID to be changed (max 32 characters).
483
+ */
484
+ originSubscriptionRequest: string;
485
+ /**
486
+ * Remaining amount from the original subscription (max 24 characters).
487
+ */
488
+ remainingAmount: string;
489
+ /**
490
+ * Subscription currency code (ISO 4217).
491
+ */
492
+ currency: string;
493
+ /**
494
+ * User payment currency (when different from merchant currency).
495
+ */
501
496
  userCurrency?: string;
497
+ /**
498
+ * Request time (ISO 8601 format). Auto-injected if not provided.
499
+ */
500
+ requestedAt?: string;
501
+ /**
502
+ * Redirect URL after successful subscription change.
503
+ */
502
504
  successRedirectUrl?: string;
505
+ /**
506
+ * Redirect URL after failed subscription change.
507
+ */
503
508
  failedRedirectUrl?: string;
509
+ /**
510
+ * Async notification URL for change notifications.
511
+ */
512
+ notifyUrl: string;
513
+ /**
514
+ * Redirect URL after user cancels.
515
+ */
504
516
  cancelRedirectUrl?: string;
505
- orderRequestedAt?: string;
506
- orderExpiredAt?: string;
517
+ /**
518
+ * Merchant-side subscription management URL.
519
+ */
520
+ subscriptionManagementUrl?: string;
521
+ /**
522
+ * Reserved extend info (JSON format).
523
+ */
507
524
  extendInfo?: string;
508
- metadata?: string;
509
- [key: string]: unknown;
510
- }
511
- /**
512
- * Create order response data.
513
- */
514
- interface CreateOrderData {
515
- paymentRequestId?: string;
516
- merchantOrderId?: string;
517
- acquiringOrderId?: string;
518
- orderStatus?: OrderStatus;
519
- orderAction?: string;
520
- [key: string]: unknown;
521
- }
522
- /**
523
- * Inquiry order request parameters.
524
- */
525
- interface InquiryOrderParams {
526
- paymentRequestId?: string;
527
- acquiringOrderId?: string;
528
- merchantInfo?: MerchantInfo;
529
- [key: string]: unknown;
530
- }
531
- /**
532
- * Inquiry order response data.
533
- */
534
- interface InquiryOrderData {
535
- paymentRequestId?: string;
536
- merchantOrderId?: string;
537
- acquiringOrderId?: string;
538
- orderStatus?: OrderStatus;
539
- orderCurrency?: string;
540
- orderAmount?: string;
541
- finalDealAmount?: string;
542
525
  /**
543
- * Refund expiry time (ISO 8601 format).
526
+ * Order expiry time (ISO 8601 format).
544
527
  */
545
- refundExpiryAt?: string;
528
+ orderExpiredAt?: string;
529
+ /**
530
+ * New subscription product information list.
531
+ */
532
+ productInfoList: SubscriptionChangeProductInfo[];
533
+ /**
534
+ * Merchant information.
535
+ */
536
+ merchantInfo?: SubscriptionMerchantInfo;
537
+ /**
538
+ * User information.
539
+ */
540
+ userInfo: SubscriptionUserInfo;
541
+ /**
542
+ * Goods information.
543
+ */
544
+ goodsInfo: {
545
+ goodsId: string;
546
+ goodsName: string;
547
+ goodsCategory?: string;
548
+ goodsUrl?: string;
549
+ appName?: string;
550
+ skuName?: string;
551
+ goodsUniquePrice?: string;
552
+ goodsQuantity?: number;
553
+ [key: string]: unknown;
554
+ };
555
+ /**
556
+ * Address information.
557
+ */
558
+ addressInfo?: {
559
+ address?: string;
560
+ city?: string;
561
+ region?: string;
562
+ postcode?: string;
563
+ addressCountryCode?: string;
564
+ [key: string]: unknown;
565
+ };
566
+ /**
567
+ * Payment method information.
568
+ */
569
+ paymentInfo: SubscriptionPaymentInfo;
570
+ /**
571
+ * Risk control auxiliary data.
572
+ */
573
+ riskData?: {
574
+ userType?: string;
575
+ userCategory?: string;
576
+ userLegalName?: string;
577
+ userDisplayName?: string;
578
+ userRegistrationIp?: string;
579
+ userLastSeenIp?: string;
580
+ userIsNew?: string;
581
+ userIsFirstPurchase?: string;
582
+ [key: string]: unknown;
583
+ };
546
584
  [key: string]: unknown;
547
585
  }
548
586
  /**
549
- * Cancel order request parameters.
587
+ * Subscription change response data.
550
588
  */
551
- interface CancelOrderParams {
552
- paymentRequestId?: string;
553
- acquiringOrderId?: string;
554
- merchantInfo?: MerchantInfo;
555
- orderRequestedAt?: string;
589
+ interface SubscriptionChangeData {
590
+ /**
591
+ * Original subscription request ID that was changed.
592
+ */
593
+ originSubscriptionRequest?: string;
594
+ /**
595
+ * New subscription request ID after the change.
596
+ */
597
+ subscriptionRequest?: string;
598
+ /**
599
+ * Merchant's new subscription plan ID.
600
+ */
601
+ merchantSubscriptionId?: string;
602
+ /**
603
+ * Current status of the subscription change.
604
+ */
605
+ subscriptionChangeStatus?: SubscriptionChangeStatus;
606
+ /**
607
+ * Action guide for user to complete authorization.
608
+ * When subscriptionChangeStatus = AUTHORIZATION_REQUIRED, contains webUrl.
609
+ */
610
+ subscriptionAction?: string;
611
+ /**
612
+ * New Waffo subscription ID.
613
+ */
614
+ subscriptionId?: string;
556
615
  [key: string]: unknown;
557
616
  }
558
617
  /**
559
- * Cancel order response data.
618
+ * Subscription change inquiry request parameters.
560
619
  */
561
- interface CancelOrderData {
562
- paymentRequestId?: string;
563
- merchantOrderId?: string;
564
- acquiringOrderId?: string;
565
- orderStatus?: OrderStatus;
620
+ interface SubscriptionChangeInquiryParams {
621
+ /**
622
+ * Original subscription request ID that was changed.
623
+ */
624
+ originSubscriptionRequest: string;
625
+ /**
626
+ * New subscription request ID after the change.
627
+ */
628
+ subscriptionRequest: string;
566
629
  [key: string]: unknown;
567
630
  }
568
631
  /**
569
- * Refund order request parameters.
632
+ * Subscription change inquiry response data.
570
633
  */
571
- interface RefundOrderParams {
572
- refundRequestId: string;
573
- paymentRequestId?: string;
574
- acquiringOrderId?: string;
575
- merchantRefundOrderId?: string;
576
- merchantInfo?: MerchantInfo;
577
- refundAmount: string;
578
- refundReason?: string;
634
+ interface SubscriptionChangeInquiryData {
635
+ /**
636
+ * New subscription request ID after the change.
637
+ */
638
+ subscriptionRequest?: string;
639
+ /**
640
+ * Original subscription request ID that was changed.
641
+ */
642
+ originSubscriptionRequest?: string;
643
+ /**
644
+ * Merchant's new subscription plan ID.
645
+ */
646
+ merchantSubscriptionId?: string;
647
+ /**
648
+ * New Waffo subscription ID.
649
+ */
650
+ subscriptionId?: string;
651
+ /**
652
+ * Current status of the subscription change.
653
+ */
654
+ subscriptionChangeStatus?: SubscriptionChangeStatus;
655
+ /**
656
+ * Action guide for user authorization.
657
+ */
658
+ subscriptionAction?: string;
659
+ /**
660
+ * Remaining amount from the original subscription.
661
+ */
662
+ remainingAmount?: string;
663
+ /**
664
+ * Subscription currency (ISO 4217).
665
+ */
666
+ currency?: string;
667
+ /**
668
+ * User payment currency.
669
+ */
670
+ userCurrency?: string;
671
+ /**
672
+ * Request time.
673
+ */
579
674
  requestedAt?: string;
580
- notifyUrl?: string;
581
- userInfo?: RefundUserInfo;
675
+ /**
676
+ * Subscription management URL.
677
+ */
678
+ subscriptionManagementUrl?: string;
679
+ /**
680
+ * Extended info.
681
+ */
582
682
  extendInfo?: string;
683
+ /**
684
+ * Order expiry time.
685
+ */
686
+ orderExpiredAt?: string;
687
+ /**
688
+ * Product information list.
689
+ */
690
+ productInfoList?: SubscriptionChangeProductInfo[];
691
+ /**
692
+ * Merchant information.
693
+ */
694
+ merchantInfo?: SubscriptionMerchantInfo;
695
+ /**
696
+ * User information.
697
+ */
698
+ userInfo?: SubscriptionUserInfo;
699
+ /**
700
+ * Goods information.
701
+ */
702
+ goodsInfo?: {
703
+ goodsId?: string;
704
+ goodsName?: string;
705
+ goodsCategory?: string;
706
+ goodsUrl?: string;
707
+ appName?: string;
708
+ skuName?: string;
709
+ goodsUniquePrice?: string;
710
+ goodsQuantity?: number;
711
+ [key: string]: unknown;
712
+ };
713
+ /**
714
+ * Address information.
715
+ */
716
+ addressInfo?: {
717
+ address?: string;
718
+ city?: string;
719
+ region?: string;
720
+ postcode?: string;
721
+ addressCountryCode?: string;
722
+ [key: string]: unknown;
723
+ };
724
+ /**
725
+ * Payment information.
726
+ */
727
+ paymentInfo?: SubscriptionPaymentInfo;
583
728
  [key: string]: unknown;
584
729
  }
730
+
585
731
  /**
586
- * Refund order response data.
732
+ * Webhook event types sent by Waffo.
587
733
  */
588
- interface RefundOrderData {
589
- refundRequestId?: string;
590
- merchantRefundOrderId?: string;
591
- acquiringOrderId?: string;
592
- acquiringRefundOrderId?: string;
593
- refundAmount?: string;
594
- refundStatus?: RefundStatus$1;
595
- remainingRefundAmount?: string;
596
- [key: string]: unknown;
734
+ declare enum WebhookEventType {
735
+ PAYMENT_NOTIFICATION = "PAYMENT_NOTIFICATION",
736
+ REFUND_NOTIFICATION = "REFUND_NOTIFICATION",
737
+ SUBSCRIPTION_STATUS_NOTIFICATION = "SUBSCRIPTION_STATUS_NOTIFICATION",
738
+ SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION = "SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION"
597
739
  }
598
740
  /**
599
- * Capture order request parameters.
741
+ * Result of webhook handling.
600
742
  */
601
- interface CaptureOrderParams {
602
- paymentRequestId?: string;
603
- acquiringOrderId?: string;
604
- merchantId: string;
605
- captureAmount?: string;
606
- [key: string]: unknown;
743
+ interface WebhookResult {
744
+ /** Whether the webhook was processed successfully */
745
+ success: boolean;
746
+ /** Response body to send back to Waffo */
747
+ responseBody: string;
748
+ /** Signature for the response body */
749
+ responseSignature: string;
750
+ /** Error message if processing failed */
751
+ error?: string;
607
752
  }
608
753
  /**
609
- * Capture order response data.
754
+ * Base notification interface.
610
755
  */
611
- interface CaptureOrderData {
612
- paymentRequestId?: string;
613
- merchantOrderId?: string;
614
- acquiringOrderId?: string;
615
- orderStatus?: OrderStatus;
616
- [key: string]: unknown;
756
+ interface BaseNotification {
757
+ eventType: string;
617
758
  }
618
759
  /**
619
- * Order status enum.
620
- */
621
- type OrderStatus = 'PAY_IN_PROGRESS' | 'AUTHORIZATION_REQUIRED' | 'AUTHED_WAITING_CAPTURE' | 'PAY_SUCCESS' | 'ORDER_CLOSE' | 'CAPTURE_IN_PROGRESS';
622
- /**
623
- * Refund status enum.
624
- */
625
- type RefundStatus$1 = 'REFUND_IN_PROGRESS' | 'ORDER_PARTIALLY_REFUNDED' | 'ORDER_FULLY_REFUNDED' | 'ORDER_REFUND_FAILED';
626
- /**
627
- * User information.
760
+ * Payment notification result payload (21 fields).
628
761
  */
629
- interface UserInfo {
630
- userId: string;
631
- userEmail: string;
632
- userPhone?: string;
633
- userFirstName?: string;
634
- userLastName?: string;
635
- userCreatedAt?: string;
636
- userTerminal?: string;
637
- userCountryCode?: string;
638
- userBrowserIp?: string;
639
- userAgent?: string;
762
+ interface PaymentNotificationResult {
763
+ paymentRequestId?: string;
764
+ merchantOrderId?: string;
765
+ acquiringOrderId?: string;
766
+ orderStatus?: string;
767
+ orderAction?: string;
768
+ orderCurrency?: string;
769
+ orderAmount?: string;
770
+ userCurrency?: string;
771
+ finalDealAmount?: string;
772
+ orderDescription?: string;
773
+ merchantInfo?: Record<string, unknown>;
774
+ userInfo?: Record<string, unknown>;
775
+ goodsInfo?: Record<string, unknown>;
776
+ addressInfo?: Record<string, unknown>;
777
+ paymentInfo?: Record<string, unknown>;
778
+ orderRequestedAt?: string;
779
+ orderExpiredAt?: string;
780
+ orderUpdatedAt?: string;
781
+ orderCompletedAt?: string;
782
+ orderFailedReason?: Record<string, unknown>;
783
+ extendInfo?: string;
640
784
  /**
641
- * User receipt URL (max 256 characters).
785
+ * The associated subscription info.
642
786
  */
643
- userReceiptUrl?: string;
644
- [key: string]: unknown;
645
- }
646
- /**
647
- * Payment information.
648
- */
649
- interface PaymentInfo {
650
- productName: string;
651
- payMethodType?: string;
652
- payMethodName?: string;
653
- payMethodProperties?: string;
787
+ subscriptionInfo?: SubscriptionInfo;
788
+ /**
789
+ * Refund expiry time (ISO 8601 format).
790
+ */
791
+ refundExpiryAt?: string;
792
+ /**
793
+ * The address of the merchant page to redirect to when user cancels the payment.
794
+ */
795
+ cancelRedirectUrl?: string;
654
796
  [key: string]: unknown;
655
797
  }
656
798
  /**
657
- * Merchant information.
799
+ * Refund notification result payload (17 fields).
658
800
  */
659
- interface MerchantInfo {
660
- merchantId: string;
661
- subMerchantId?: string;
801
+ interface RefundNotificationResult {
802
+ refundRequestId?: string;
803
+ merchantRefundOrderId?: string;
804
+ acquiringOrderId?: string;
805
+ acquiringRefundOrderId?: string;
806
+ origPaymentRequestId?: string;
807
+ refundAmount?: string;
808
+ refundStatus?: string;
809
+ remainingRefundAmount?: string;
810
+ userCurrency?: string;
811
+ finalDealAmount?: string;
812
+ refundReason?: string;
813
+ refundRequestedAt?: string;
814
+ refundUpdatedAt?: string;
815
+ refundCompletedAt?: string;
816
+ refundFailedReason?: Record<string, unknown>;
817
+ userInfo?: Record<string, unknown>;
818
+ extendInfo?: string;
819
+ /**
820
+ * Refund source. Possible values: MERCHANT, RDR, ETHOCA.
821
+ */
822
+ refundSource?: string;
662
823
  [key: string]: unknown;
663
824
  }
664
825
  /**
665
- * Goods information.
826
+ * Subscription notification result payload (20 fields).
827
+ * Shared by SubscriptionStatusNotification and SubscriptionPeriodChangedNotification.
666
828
  */
667
- interface GoodsInfo {
668
- goodsId?: string;
669
- goodsName?: string;
670
- goodsCategory?: string;
671
- goodsUrl?: string;
672
- appName?: string;
673
- skuName?: string;
674
- goodsUniquePrice?: string;
675
- goodsQuantity?: number;
829
+ interface SubscriptionNotificationResult {
830
+ subscriptionRequest?: string;
831
+ merchantSubscriptionId?: string;
832
+ subscriptionId?: string;
833
+ /**
834
+ * Payment method's subscription id.
835
+ */
836
+ payMethodSubscriptionId?: string;
837
+ subscriptionStatus?: string;
838
+ subscriptionAction?: string;
839
+ currency?: string;
840
+ amount?: string;
841
+ userCurrency?: string;
842
+ productInfo?: Record<string, unknown>;
843
+ merchantInfo?: Record<string, unknown>;
844
+ userInfo?: Record<string, unknown>;
845
+ goodsInfo?: Record<string, unknown>;
846
+ addressInfo?: Record<string, unknown>;
847
+ paymentInfo?: Record<string, unknown>;
848
+ requestedAt?: string;
849
+ updatedAt?: string;
850
+ failedReason?: Record<string, unknown>;
851
+ extendInfo?: string;
852
+ subscriptionManagementUrl?: string;
853
+ paymentDetails?: Record<string, unknown>[];
676
854
  [key: string]: unknown;
677
855
  }
678
856
  /**
679
- * Address information.
857
+ * Payment notification from Waffo.
680
858
  */
681
- interface AddressInfo {
682
- address?: string;
683
- city?: string;
684
- region?: string;
685
- postcode?: string;
686
- addressCountryCode?: string;
859
+ interface PaymentNotification extends BaseNotification {
860
+ eventType: 'PAYMENT_NOTIFICATION';
861
+ result?: PaymentNotificationResult;
687
862
  [key: string]: unknown;
688
863
  }
689
864
  /**
690
- * Card information.
865
+ * Refund notification from Waffo.
691
866
  */
692
- interface CardInfo {
693
- cardNumber?: string;
694
- cardExpiryYear?: number;
695
- cardExpiryMonth?: number;
696
- cardCvv?: string;
697
- cardHolderName?: string;
698
- threeDsDecision?: string;
867
+ interface RefundNotification extends BaseNotification {
868
+ eventType: 'REFUND_NOTIFICATION';
869
+ result?: RefundNotificationResult;
699
870
  [key: string]: unknown;
700
871
  }
701
872
  /**
702
- * Risk data.
873
+ * Subscription status notification from Waffo.
703
874
  */
704
- interface RiskData {
705
- userType?: string;
706
- userCategory?: string;
707
- userLegalName?: string;
708
- userDisplayName?: string;
709
- userRegistrationIp?: string;
710
- userLastSeenIp?: string;
711
- userIsNew?: string;
712
- userIsFirstPurchase?: string;
875
+ interface SubscriptionStatusNotification extends BaseNotification {
876
+ eventType: 'SUBSCRIPTION_STATUS_NOTIFICATION';
877
+ result?: SubscriptionNotificationResult;
713
878
  [key: string]: unknown;
714
879
  }
715
880
  /**
716
- * Refund user information.
881
+ * Subscription period changed notification from Waffo.
717
882
  */
718
- interface RefundUserInfo {
719
- userType?: string;
720
- userFirstName?: string;
721
- userLastName?: string;
722
- userEmail?: string;
723
- userPhone?: string;
883
+ interface SubscriptionPeriodChangedNotification extends BaseNotification {
884
+ eventType: 'SUBSCRIPTION_PERIOD_CHANGED_NOTIFICATION';
885
+ result?: SubscriptionNotificationResult;
724
886
  [key: string]: unknown;
725
887
  }
726
-
888
+ type PaymentHandler = (notification: PaymentNotification) => void | Promise<void>;
889
+ type RefundHandler = (notification: RefundNotification) => void | Promise<void>;
890
+ type SubscriptionStatusHandler = (notification: SubscriptionStatusNotification) => void | Promise<void>;
891
+ type SubscriptionPaymentHandler = (notification: SubscriptionStatusNotification) => void | Promise<void>;
892
+ type SubscriptionPeriodChangedHandler = (notification: SubscriptionPeriodChangedNotification) => void | Promise<void>;
727
893
  /**
728
- * Order resource for managing payment orders.
894
+ * Webhook handler for processing Waffo webhook notifications.
729
895
  *
730
896
  * @example
731
897
  * ```typescript
732
- * // Create an order
733
- * const response = await waffo.order().create({
734
- * paymentRequestId: 'unique-request-id',
735
- * merchantOrderId: 'order-123',
736
- * orderCurrency: 'USD',
737
- * orderAmount: '10.00',
738
- * orderDescription: 'Test order',
739
- * notifyUrl: 'https://example.com/webhook',
740
- * userInfo: {
741
- * userId: 'user-123',
742
- * userEmail: 'user@example.com',
743
- * },
744
- * paymentInfo: {
745
- * productName: 'Test Product',
746
- * },
747
- * });
898
+ * // Setup handler
899
+ * const handler = waffo.webhook()
900
+ * .onPayment((notification) => {
901
+ * console.log('Payment:', notification.result?.orderStatus);
902
+ * })
903
+ * .onRefund((notification) => {
904
+ * console.log('Refund:', notification.result?.refundStatus);
905
+ * });
748
906
  *
749
- * if (response.isSuccess()) {
750
- * console.log('Order created:', response.getData());
751
- * }
907
+ * // Process webhook (e.g., in Express.js)
908
+ * app.post('/webhook', async (req, res) => {
909
+ * const body = req.body.toString();
910
+ * const signature = req.headers['x-signature'];
911
+ * const result = await handler.handleWebhook(body, signature);
912
+ *
913
+ * res.setHeader('X-SIGNATURE', result.responseSignature);
914
+ * res.status(200).send(result.responseBody);
915
+ * });
752
916
  * ```
753
917
  */
754
- declare class OrderResource extends BaseResource {
755
- private static readonly PATH_CREATE;
756
- private static readonly PATH_INQUIRY;
757
- private static readonly PATH_CANCEL;
758
- private static readonly PATH_REFUND;
759
- private static readonly PATH_CAPTURE;
918
+ declare class WebhookHandler {
919
+ private readonly waffoPublicKey;
920
+ private readonly privateKey;
921
+ private readonly logger?;
922
+ private paymentHandler?;
923
+ private refundHandler?;
924
+ private subscriptionStatusHandler?;
925
+ private subscriptionPaymentHandler?;
926
+ private subscriptionPeriodChangedHandler?;
927
+ constructor(config: WaffoConfig);
760
928
  /**
761
- * Creates a new payment order.
762
- *
763
- * @param params - Order creation parameters
764
- * @param options - Optional request options
765
- * @returns API response with order data
766
- * @throws WaffoUnknownStatusError for network errors
929
+ * Registers a handler for payment notifications.
767
930
  */
768
- create(params: CreateOrderParams, options?: RequestOptions): Promise<ApiResponse<CreateOrderData>>;
931
+ onPayment(handler: PaymentHandler): this;
769
932
  /**
770
- * Queries an existing order.
771
- *
772
- * @param params - Order inquiry parameters
773
- * @param options - Optional request options
774
- * @returns API response with order data
775
- * @throws WaffoUnknownStatusError for network errors
933
+ * Registers a handler for refund notifications.
776
934
  */
777
- inquiry(params: InquiryOrderParams, options?: RequestOptions): Promise<ApiResponse<InquiryOrderData>>;
935
+ onRefund(handler: RefundHandler): this;
778
936
  /**
779
- * Cancels an existing order.
780
- *
781
- * @param params - Order cancellation parameters
782
- * @param options - Optional request options
783
- * @returns API response with cancellation result
784
- * @throws WaffoUnknownStatusError for network errors
937
+ * Registers a handler for subscription status notifications.
785
938
  */
786
- cancel(params: CancelOrderParams, options?: RequestOptions): Promise<ApiResponse<CancelOrderData>>;
939
+ onSubscriptionStatus(handler: SubscriptionStatusHandler): this;
787
940
  /**
788
- * Refunds an existing order.
789
- *
790
- * @param params - Order refund parameters
791
- * @param options - Optional request options
792
- * @returns API response with refund result
793
- * @throws WaffoUnknownStatusError for network errors
941
+ * Registers a fallback handler for SUBSCRIPTION_STATUS_NOTIFICATION events.
942
+ * Only called when onSubscriptionStatus handler is not registered.
794
943
  */
795
- refund(params: RefundOrderParams, options?: RequestOptions): Promise<ApiResponse<RefundOrderData>>;
944
+ onSubscriptionPayment(handler: SubscriptionPaymentHandler): this;
796
945
  /**
797
- * Captures an authorized order.
798
- *
799
- * @param params - Order capture parameters
800
- * @param options - Optional request options
801
- * @returns API response with capture result
802
- * @throws WaffoUnknownStatusError for network errors
946
+ * Registers a handler for subscription period changed notifications.
803
947
  */
804
- capture(params: CaptureOrderParams, options?: RequestOptions): Promise<ApiResponse<CaptureOrderData>>;
948
+ onSubscriptionPeriodChanged(handler: SubscriptionPeriodChangedHandler): this;
949
+ /**
950
+ * Processes a webhook notification.
951
+ *
952
+ * @param body - The raw webhook body
953
+ * @param signature - The X-SIGNATURE header value
954
+ * @returns Result with response body and signature
955
+ */
956
+ handleWebhook(body: string, signature: string): Promise<WebhookResult>;
957
+ /**
958
+ * Verifies a webhook signature.
959
+ *
960
+ * @param body - The raw webhook body
961
+ * @param signature - The X-SIGNATURE header value
962
+ * @returns true if signature is valid
963
+ */
964
+ verifySignature(body: string, signature: string): boolean;
965
+ /**
966
+ * Builds a success response with signature.
967
+ */
968
+ buildSuccessResponse(): {
969
+ body: string;
970
+ signature: string;
971
+ };
972
+ /**
973
+ * Builds a failed response with signature.
974
+ */
975
+ buildFailedResponse(message: string): {
976
+ body: string;
977
+ signature: string;
978
+ };
979
+ private createSuccessResult;
980
+ private createFailedResult;
805
981
  }
806
982
 
807
983
  /**
808
- * Subscription-related type definitions.
984
+ * Generic API response wrapper.
809
985
  *
810
- * Note: Full type definitions should be generated from openapi.json.
811
- * These are placeholder interfaces for the SDK structure.
986
+ * All API responses are wrapped in this class for consistent handling.
987
+ *
988
+ * @example
989
+ * ```typescript
990
+ * const response = await waffo.order().create(params);
991
+ *
992
+ * if (response.isSuccess()) {
993
+ * const data = response.getData();
994
+ * console.log('Order ID:', data?.acquiringOrderId);
995
+ * } else {
996
+ * console.error(`Error [${response.code}]: ${response.getMessage()}`);
997
+ * }
998
+ * ```
812
999
  */
1000
+ declare class ApiResponse<T> {
1001
+ /** Response code. "0" indicates success, other values indicate errors. */
1002
+ readonly code: string;
1003
+ /** Response data (present when code is "0") */
1004
+ readonly data?: T;
1005
+ /** Error message (present when code is not "0") */
1006
+ readonly message?: string;
1007
+ private constructor();
1008
+ /**
1009
+ * Creates a successful response.
1010
+ *
1011
+ * @param data - The response data
1012
+ */
1013
+ static success<T>(data?: T): ApiResponse<T>;
1014
+ /**
1015
+ * Creates an error response.
1016
+ *
1017
+ * @param code - The error code
1018
+ * @param message - The error message
1019
+ */
1020
+ static error<T>(code: string, message?: string): ApiResponse<T>;
1021
+ /**
1022
+ * Checks if the response indicates success.
1023
+ *
1024
+ * @returns true if the response code is "0"
1025
+ */
1026
+ isSuccess(): boolean;
1027
+ /**
1028
+ * Gets the response data.
1029
+ *
1030
+ * @returns The response data, or undefined if the response is an error
1031
+ */
1032
+ getData(): T | undefined;
1033
+ /**
1034
+ * Gets the error message.
1035
+ *
1036
+ * @returns The error message, or undefined if the response is successful
1037
+ */
1038
+ getMessage(): string | undefined;
1039
+ /**
1040
+ * Gets the response code.
1041
+ *
1042
+ * @returns The response code
1043
+ */
1044
+ getCode(): string;
1045
+ /**
1046
+ * Gets the response data or throws an error.
1047
+ *
1048
+ * @returns The response data
1049
+ * @throws Error if the response is not successful or data is undefined
1050
+ */
1051
+ getDataOrThrow(): T;
1052
+ }
1053
+
813
1054
  /**
814
- * Create subscription request parameters.
1055
+ * HTTP client for making requests to the Waffo API.
1056
+ *
1057
+ * Handles:
1058
+ * - Request signing with merchant's private key
1059
+ * - Response signature verification with Waffo's public key
1060
+ * - MerchantId auto-injection
1061
+ * - Error handling and timeout management
815
1062
  */
816
- interface CreateSubscriptionParams {
1063
+ declare class WaffoHttpClient {
1064
+ private readonly baseUrl;
1065
+ private readonly apiKey;
1066
+ private readonly privateKey;
1067
+ private readonly waffoPublicKey;
1068
+ private readonly merchantId;
1069
+ private readonly connectTimeout;
1070
+ private readonly readTimeout;
1071
+ private readonly logger?;
1072
+ private readonly httpTransport;
1073
+ constructor(config: WaffoConfig);
817
1074
  /**
818
- * Subscription request ID sent from Merchant (max 32 characters).
819
- * Used for idempotent check.
1075
+ * Sends a POST request to the Waffo API.
1076
+ *
1077
+ * @param path - API endpoint path (e.g., "/order/create")
1078
+ * @param request - Request body
1079
+ * @param options - Per-request options
1080
+ * @returns API response
1081
+ * @throws WaffoUnknownStatusError for network errors or unknown status
820
1082
  */
821
- subscriptionRequest: string;
822
- merchantSubscriptionId: string;
823
- currency: string;
824
- amount: string;
825
- notifyUrl: string;
826
- productInfo: ProductInfo;
827
- userInfo: SubscriptionUserInfo;
828
- paymentInfo: SubscriptionPaymentInfo;
829
- merchantInfo?: SubscriptionMerchantInfo;
830
- goodsInfo?: {
831
- goodsId: string;
832
- goodsName: string;
833
- goodsCategory?: string;
834
- goodsUrl?: string;
835
- goodsQuantity?: number;
836
- [key: string]: unknown;
837
- };
838
- successRedirectUrl?: string;
839
- failedRedirectUrl?: string;
840
- cancelRedirectUrl?: string;
841
- subscriptionManagementUrl?: string;
842
- requestedAt?: string;
843
- extendInfo?: string;
1083
+ post<T extends object, R>(path: string, request: T, options?: RequestOptions): Promise<ApiResponse<R>>;
844
1084
  /**
845
- * Order expiry time (ISO 8601 format, max 24 characters).
1085
+ * Parses the API response body.
846
1086
  */
847
- orderExpiredAt?: string;
848
- [key: string]: unknown;
1087
+ private parseResponse;
1088
+ /**
1089
+ * Auto-injects merchantId into the request if configured.
1090
+ */
1091
+ private injectMerchantIdIfNeeded;
1092
+ /**
1093
+ * Checks if the error is a network-related error.
1094
+ */
1095
+ private isNetworkError;
849
1096
  }
1097
+
850
1098
  /**
851
- * Create subscription response data.
1099
+ * Base class for API resources.
852
1100
  */
853
- interface CreateSubscriptionData {
854
- subscriptionRequest?: string;
855
- merchantSubscriptionId?: string;
856
- subscriptionId?: string;
857
- subscriptionStatus?: SubscriptionStatus;
858
- subscriptionAction?: string;
859
- [key: string]: unknown;
1101
+ declare abstract class BaseResource {
1102
+ protected readonly httpClient: WaffoHttpClient;
1103
+ protected readonly basePath: string;
1104
+ constructor(httpClient: WaffoHttpClient, basePath: string);
1105
+ /**
1106
+ * Gets the full path for an endpoint.
1107
+ *
1108
+ * @param endpoint - The endpoint (e.g., "/create")
1109
+ * @returns Full path (e.g., "/order/create")
1110
+ */
1111
+ protected getPath(endpoint: string): string;
860
1112
  }
1113
+
861
1114
  /**
862
- * Inquiry subscription request parameters.
1115
+ * Order-related type definitions.
1116
+ *
1117
+ * Note: Full type definitions should be generated from openapi.json.
1118
+ * These are placeholder interfaces for the SDK structure.
863
1119
  */
864
- interface InquirySubscriptionParams {
865
- subscriptionRequest?: string;
866
- subscriptionId?: string;
867
- merchantInfo?: SubscriptionMerchantInfo;
868
- [key: string]: unknown;
869
- }
1120
+
870
1121
  /**
871
- * Inquiry subscription response data.
1122
+ * Create order request parameters.
872
1123
  */
873
- interface InquirySubscriptionData {
874
- subscriptionRequest?: string;
875
- merchantSubscriptionId?: string;
876
- subscriptionId?: string;
877
- payMethodSubscriptionId?: string;
878
- subscriptionStatus?: SubscriptionStatus;
879
- subscriptionAction?: string;
880
- currency?: string;
1124
+ interface CreateOrderParams {
1125
+ paymentRequestId: string;
1126
+ merchantOrderId: string;
1127
+ orderCurrency: string;
1128
+ orderAmount: string;
1129
+ orderDescription: string;
1130
+ notifyUrl: string;
1131
+ userInfo: UserInfo;
1132
+ paymentInfo: PaymentInfo;
1133
+ merchantInfo?: MerchantInfo;
1134
+ goodsInfo?: GoodsInfo;
1135
+ addressInfo?: AddressInfo;
1136
+ cardInfo?: CardInfo;
1137
+ riskData?: RiskData;
881
1138
  userCurrency?: string;
882
- amount?: string;
883
- productInfo?: ProductInfo;
1139
+ successRedirectUrl?: string;
1140
+ failedRedirectUrl?: string;
1141
+ cancelRedirectUrl?: string;
1142
+ orderRequestedAt?: string;
1143
+ orderExpiredAt?: string;
1144
+ extendInfo?: string;
1145
+ metadata?: string;
884
1146
  [key: string]: unknown;
885
1147
  }
886
1148
  /**
887
- * Cancel subscription request parameters.
1149
+ * Create order response data.
888
1150
  */
889
- interface CancelSubscriptionParams {
890
- subscriptionRequest?: string;
891
- subscriptionId?: string;
892
- merchantInfo?: SubscriptionMerchantInfo;
893
- cancelReason?: string;
894
- requestedAt?: string;
1151
+ interface CreateOrderData {
1152
+ paymentRequestId?: string;
1153
+ merchantOrderId?: string;
1154
+ acquiringOrderId?: string;
1155
+ orderStatus?: OrderStatus;
1156
+ orderAction?: string;
895
1157
  [key: string]: unknown;
896
1158
  }
897
1159
  /**
898
- * Cancel subscription response data.
1160
+ * Inquiry order request parameters.
899
1161
  */
900
- interface CancelSubscriptionData {
901
- subscriptionRequest?: string;
902
- merchantSubscriptionId?: string;
903
- subscriptionId?: string;
904
- subscriptionStatus?: SubscriptionStatus;
1162
+ interface InquiryOrderParams {
1163
+ paymentRequestId?: string;
1164
+ acquiringOrderId?: string;
1165
+ merchantInfo?: MerchantInfo;
905
1166
  [key: string]: unknown;
906
1167
  }
907
1168
  /**
908
- * Manage subscription request parameters.
1169
+ * Inquiry order response data.
909
1170
  */
910
- interface ManageSubscriptionParams {
911
- subscriptionId: string;
912
- merchantId: string;
913
- action: SubscriptionManageAction;
914
- newAmount?: string;
915
- newPeriodType?: PeriodType;
916
- newPeriodValue?: number;
917
- requestedAt: string;
1171
+ interface InquiryOrderData {
1172
+ paymentRequestId?: string;
1173
+ merchantOrderId?: string;
1174
+ acquiringOrderId?: string;
1175
+ orderStatus?: OrderStatus;
1176
+ orderCurrency?: string;
1177
+ orderAmount?: string;
1178
+ finalDealAmount?: string;
1179
+ /**
1180
+ * Refund expiry time (ISO 8601 format).
1181
+ */
1182
+ refundExpiryAt?: string;
1183
+ /**
1184
+ * The associated subscription info.
1185
+ */
1186
+ subscriptionInfo?: SubscriptionInfo;
1187
+ /**
1188
+ * The address of the merchant page to redirect to when user cancels the payment.
1189
+ */
1190
+ cancelRedirectUrl?: string;
918
1191
  [key: string]: unknown;
919
1192
  }
920
1193
  /**
921
- * Manage subscription response data.
1194
+ * Cancel order request parameters.
922
1195
  */
923
- interface ManageSubscriptionData {
924
- subscriptionId?: string;
925
- subscriptionStatus?: SubscriptionStatus;
1196
+ interface CancelOrderParams {
1197
+ paymentRequestId?: string;
1198
+ acquiringOrderId?: string;
1199
+ merchantInfo?: MerchantInfo;
1200
+ orderRequestedAt?: string;
926
1201
  [key: string]: unknown;
927
1202
  }
928
1203
  /**
929
- * Subscription status enum.
930
- * Based on openapi.json SubscriptionInquiryResponse.subscriptionStatus.
1204
+ * Cancel order response data.
931
1205
  */
932
- type SubscriptionStatus = 'AUTHORIZATION_REQUIRED' | 'IN_PROGRESS' | 'ACTIVE' | 'CLOSE' | 'MERCHANT_CANCELLED' | 'USER_CANCELLED' | 'CHANNEL_CANCELLED' | 'EXPIRED';
1206
+ interface CancelOrderData {
1207
+ paymentRequestId?: string;
1208
+ merchantOrderId?: string;
1209
+ acquiringOrderId?: string;
1210
+ orderStatus?: OrderStatus;
1211
+ [key: string]: unknown;
1212
+ }
933
1213
  /**
934
- * Subscription manage action enum.
1214
+ * Refund order request parameters.
935
1215
  */
936
- type SubscriptionManageAction = 'PAUSE' | 'RESUME' | 'UPDATE_AMOUNT' | 'UPDATE_PERIOD';
1216
+ interface RefundOrderParams {
1217
+ refundRequestId: string;
1218
+ paymentRequestId?: string;
1219
+ acquiringOrderId?: string;
1220
+ merchantRefundOrderId?: string;
1221
+ merchantInfo?: MerchantInfo;
1222
+ refundAmount: string;
1223
+ refundReason?: string;
1224
+ requestedAt?: string;
1225
+ notifyUrl?: string;
1226
+ userInfo?: RefundUserInfo;
1227
+ extendInfo?: string;
1228
+ [key: string]: unknown;
1229
+ }
937
1230
  /**
938
- * Period type enum.
939
- * Values: DAILY, WEEKLY, MONTHLY
1231
+ * Refund order response data.
940
1232
  */
941
- type PeriodType = 'DAILY' | 'WEEKLY' | 'MONTHLY';
1233
+ interface RefundOrderData {
1234
+ refundRequestId?: string;
1235
+ merchantRefundOrderId?: string;
1236
+ acquiringOrderId?: string;
1237
+ acquiringRefundOrderId?: string;
1238
+ refundAmount?: string;
1239
+ refundStatus?: RefundStatus$1;
1240
+ remainingRefundAmount?: string;
1241
+ [key: string]: unknown;
1242
+ }
942
1243
  /**
943
- * Product information for subscription.
944
- * Based on openapi.json ProductInfo schema.
1244
+ * Capture order request parameters.
945
1245
  */
946
- interface ProductInfo {
947
- /**
948
- * Subscription product description (max 128 characters).
949
- * Often appearing to user when asking user's confirmation.
950
- */
951
- description: string;
952
- /**
953
- * Subscription product period type: DAILY, WEEKLY, MONTHLY.
954
- */
955
- periodType: PeriodType;
956
- /**
957
- * Period interval (max 12 characters).
958
- * - DAILY: 1-365
959
- * - WEEKLY: 1-4
960
- * - MONTHLY: 1-12
961
- */
962
- periodInterval: string;
963
- /**
964
- * Number of billing periods until subscription ends (max 24 characters).
965
- * Empty means no defined end period.
966
- */
967
- numberOfPeriod?: string;
968
- /**
969
- * Trial period amount (max 24 characters).
970
- */
971
- trialPeriodAmount?: string;
972
- /**
973
- * Number of trial periods (max 12 characters).
974
- */
975
- numberOfTrialPeriod?: string;
976
- /**
977
- * Trial period type: DAILY, WEEKLY, MONTHLY.
978
- * If omitted, uses periodType value by default.
979
- */
980
- trialPeriodType?: PeriodType;
981
- /**
982
- * Trial period interval (max 12 characters).
983
- * If omitted, uses periodInterval value by default.
984
- */
985
- trialPeriodInterval?: string;
986
- /**
987
- * When the subscription starts (ISO 8601 format).
988
- */
989
- startDateTime?: string;
990
- /**
991
- * When the subscription ends (ISO 8601 format).
992
- */
993
- endDateTime?: string;
994
- /**
995
- * When the next payment is due (ISO 8601 format).
996
- */
997
- nextPaymentDateTime?: string;
998
- /**
999
- * Current billing period number.
1000
- */
1001
- currentPeriod?: string;
1246
+ interface CaptureOrderParams {
1247
+ paymentRequestId?: string;
1248
+ acquiringOrderId?: string;
1249
+ merchantId: string;
1250
+ captureAmount?: string;
1002
1251
  [key: string]: unknown;
1003
1252
  }
1004
1253
  /**
1005
- * User information for subscription.
1254
+ * Capture order response data.
1006
1255
  */
1007
- interface SubscriptionUserInfo {
1256
+ interface CaptureOrderData {
1257
+ paymentRequestId?: string;
1258
+ merchantOrderId?: string;
1259
+ acquiringOrderId?: string;
1260
+ orderStatus?: OrderStatus;
1261
+ [key: string]: unknown;
1262
+ }
1263
+ /**
1264
+ * Order status enum.
1265
+ */
1266
+ type OrderStatus = 'PAY_IN_PROGRESS' | 'AUTHORIZATION_REQUIRED' | 'AUTHED_WAITING_CAPTURE' | 'PAY_SUCCESS' | 'ORDER_CLOSE' | 'CAPTURE_IN_PROGRESS';
1267
+ /**
1268
+ * Refund status enum.
1269
+ */
1270
+ type RefundStatus$1 = 'REFUND_IN_PROGRESS' | 'ORDER_PARTIALLY_REFUNDED' | 'ORDER_FULLY_REFUNDED' | 'ORDER_REFUND_FAILED';
1271
+ /**
1272
+ * User information.
1273
+ */
1274
+ interface UserInfo {
1008
1275
  userId: string;
1009
1276
  userEmail: string;
1010
1277
  userPhone?: string;
1011
1278
  userFirstName?: string;
1012
1279
  userLastName?: string;
1280
+ userCreatedAt?: string;
1281
+ userTerminal?: string;
1013
1282
  userCountryCode?: string;
1014
1283
  userBrowserIp?: string;
1015
1284
  userAgent?: string;
1285
+ /**
1286
+ * User receipt URL (max 256 characters).
1287
+ */
1288
+ userReceiptUrl?: string;
1016
1289
  [key: string]: unknown;
1017
1290
  }
1018
1291
  /**
1019
- * Payment information for subscription.
1292
+ * Payment information.
1020
1293
  */
1021
- interface SubscriptionPaymentInfo {
1294
+ interface PaymentInfo {
1022
1295
  productName: string;
1023
1296
  payMethodType?: string;
1024
1297
  payMethodName?: string;
1298
+ payMethodProperties?: string;
1025
1299
  [key: string]: unknown;
1026
1300
  }
1027
1301
  /**
1028
- * Merchant information for subscription.
1302
+ * Merchant information.
1029
1303
  */
1030
- interface SubscriptionMerchantInfo {
1304
+ interface MerchantInfo {
1031
1305
  merchantId: string;
1032
1306
  subMerchantId?: string;
1033
1307
  [key: string]: unknown;
1034
1308
  }
1035
1309
  /**
1036
- * Subscription change status values.
1310
+ * Goods information.
1037
1311
  */
1038
- type SubscriptionChangeStatus = 'IN_PROGRESS' | 'AUTHORIZATION_REQUIRED' | 'SUCCESS' | 'CLOSED';
1312
+ interface GoodsInfo {
1313
+ goodsId?: string;
1314
+ goodsName?: string;
1315
+ goodsCategory?: string;
1316
+ goodsUrl?: string;
1317
+ appName?: string;
1318
+ skuName?: string;
1319
+ goodsUniquePrice?: string;
1320
+ goodsQuantity?: number;
1321
+ [key: string]: unknown;
1322
+ }
1039
1323
  /**
1040
- * Product information for subscription change operations.
1041
- * Contains billing period settings for the new subscription plan.
1324
+ * Address information.
1042
1325
  */
1043
- interface SubscriptionChangeProductInfo {
1044
- /**
1045
- * Product description (max 128 characters).
1046
- */
1047
- description: string;
1048
- /**
1049
- * Billing period type: DAILY, WEEKLY, MONTHLY.
1050
- */
1051
- periodType: PeriodType;
1052
- /**
1053
- * Subscription amount for this product (max 12 characters).
1054
- */
1055
- amount: string;
1056
- /**
1057
- * Billing interval (max 12 characters).
1058
- */
1059
- periodInterval: string;
1060
- /**
1061
- * Total number of billing periods (max 24 characters, empty for unlimited).
1062
- */
1063
- numberOfPeriod?: string;
1064
- /**
1065
- * Trial period amount (max 24 characters).
1066
- */
1067
- trialPeriodAmount?: string;
1068
- /**
1069
- * Number of trial periods (max 12 characters).
1070
- */
1071
- numberOfTrialPeriod?: string;
1072
- /**
1073
- * Trial period type: DAILY, WEEKLY, MONTHLY.
1074
- */
1075
- trialPeriodType?: PeriodType;
1076
- /**
1077
- * Trial period interval (max 12 characters).
1078
- */
1079
- trialPeriodInterval?: string;
1326
+ interface AddressInfo {
1327
+ address?: string;
1328
+ city?: string;
1329
+ region?: string;
1330
+ postcode?: string;
1331
+ addressCountryCode?: string;
1080
1332
  [key: string]: unknown;
1081
1333
  }
1082
1334
  /**
1083
- * Subscription change request parameters.
1335
+ * Card information.
1084
1336
  */
1085
- interface SubscriptionChangeParams {
1086
- /**
1087
- * New unique request ID for this change (max 32 characters).
1088
- */
1089
- subscriptionRequest: string;
1090
- /**
1091
- * New merchant subscription plan ID (max 64 characters).
1092
- */
1093
- merchantSubscriptionId?: string;
1094
- /**
1095
- * Original subscription request ID to be changed (max 32 characters).
1096
- */
1097
- originSubscriptionRequest: string;
1098
- /**
1099
- * Remaining amount from the original subscription (max 24 characters).
1100
- */
1101
- remainingAmount: string;
1102
- /**
1103
- * Subscription currency code (ISO 4217).
1104
- */
1105
- currency: string;
1106
- /**
1107
- * User payment currency (when different from merchant currency).
1108
- */
1109
- userCurrency?: string;
1110
- /**
1111
- * Request time (ISO 8601 format).
1112
- */
1113
- requestedAt: string;
1114
- /**
1115
- * Redirect URL after successful subscription change.
1116
- */
1117
- successRedirectUrl?: string;
1118
- /**
1119
- * Redirect URL after failed subscription change.
1120
- */
1121
- failedRedirectUrl?: string;
1122
- /**
1123
- * Async notification URL for change notifications.
1124
- */
1125
- notifyUrl: string;
1126
- /**
1127
- * Redirect URL after user cancels.
1128
- */
1129
- cancelRedirectUrl?: string;
1130
- /**
1131
- * Merchant-side subscription management URL.
1132
- */
1133
- subscriptionManagementUrl?: string;
1134
- /**
1135
- * Reserved extend info (JSON format).
1136
- */
1137
- extendInfo?: string;
1138
- /**
1139
- * Order expiry time (ISO 8601 format).
1140
- */
1141
- orderExpiredAt?: string;
1142
- /**
1143
- * New subscription product information list.
1144
- */
1145
- productInfoList: SubscriptionChangeProductInfo[];
1146
- /**
1147
- * Merchant information.
1148
- */
1149
- merchantInfo?: SubscriptionMerchantInfo;
1150
- /**
1151
- * User information.
1152
- */
1153
- userInfo: SubscriptionUserInfo;
1154
- /**
1155
- * Goods information.
1156
- */
1157
- goodsInfo: {
1158
- goodsId: string;
1159
- goodsName: string;
1160
- goodsCategory?: string;
1161
- goodsUrl?: string;
1162
- appName?: string;
1163
- skuName?: string;
1164
- goodsUniquePrice?: string;
1165
- goodsQuantity?: number;
1166
- [key: string]: unknown;
1167
- };
1168
- /**
1169
- * Address information.
1170
- */
1171
- addressInfo?: {
1172
- address?: string;
1173
- city?: string;
1174
- region?: string;
1175
- postcode?: string;
1176
- addressCountryCode?: string;
1177
- [key: string]: unknown;
1178
- };
1179
- /**
1180
- * Payment method information.
1181
- */
1182
- paymentInfo: SubscriptionPaymentInfo;
1183
- /**
1184
- * Risk control auxiliary data.
1185
- */
1186
- riskData?: {
1187
- userType?: string;
1188
- userCategory?: string;
1189
- userLegalName?: string;
1190
- userDisplayName?: string;
1191
- userRegistrationIp?: string;
1192
- userLastSeenIp?: string;
1193
- userIsNew?: string;
1194
- userIsFirstPurchase?: string;
1195
- [key: string]: unknown;
1196
- };
1337
+ interface CardInfo {
1338
+ cardNumber?: string;
1339
+ cardExpiryYear?: number;
1340
+ cardExpiryMonth?: number;
1341
+ cardCvv?: string;
1342
+ cardHolderName?: string;
1343
+ threeDsDecision?: string;
1197
1344
  [key: string]: unknown;
1198
1345
  }
1199
1346
  /**
1200
- * Subscription change response data.
1347
+ * Risk data.
1201
1348
  */
1202
- interface SubscriptionChangeData {
1203
- /**
1204
- * Original subscription request ID that was changed.
1205
- */
1206
- originSubscriptionRequest?: string;
1207
- /**
1208
- * New subscription request ID after the change.
1209
- */
1210
- subscriptionRequest?: string;
1211
- /**
1212
- * Merchant's new subscription plan ID.
1213
- */
1214
- merchantSubscriptionId?: string;
1215
- /**
1216
- * Current status of the subscription change.
1217
- */
1218
- subscriptionChangeStatus?: SubscriptionChangeStatus;
1219
- /**
1220
- * Action guide for user to complete authorization.
1221
- * When subscriptionChangeStatus = AUTHORIZATION_REQUIRED, contains webUrl.
1222
- */
1223
- subscriptionAction?: string;
1224
- /**
1225
- * New Waffo subscription ID.
1226
- */
1227
- subscriptionId?: string;
1349
+ interface RiskData {
1350
+ userType?: string;
1351
+ userCategory?: string;
1352
+ userLegalName?: string;
1353
+ userDisplayName?: string;
1354
+ userRegistrationIp?: string;
1355
+ userLastSeenIp?: string;
1356
+ userIsNew?: string;
1357
+ userIsFirstPurchase?: string;
1228
1358
  [key: string]: unknown;
1229
1359
  }
1230
1360
  /**
1231
- * Subscription change inquiry request parameters.
1361
+ * Refund user information.
1232
1362
  */
1233
- interface SubscriptionChangeInquiryParams {
1234
- /**
1235
- * Original subscription request ID that was changed.
1236
- */
1237
- originSubscriptionRequest: string;
1238
- /**
1239
- * New subscription request ID after the change.
1240
- */
1241
- subscriptionRequest: string;
1363
+ interface RefundUserInfo {
1364
+ userType?: string;
1365
+ userFirstName?: string;
1366
+ userLastName?: string;
1367
+ userEmail?: string;
1368
+ userPhone?: string;
1242
1369
  [key: string]: unknown;
1243
1370
  }
1371
+
1244
1372
  /**
1245
- * Subscription change inquiry response data.
1373
+ * Order resource for managing payment orders.
1374
+ *
1375
+ * @example
1376
+ * ```typescript
1377
+ * // Create an order
1378
+ * const response = await waffo.order().create({
1379
+ * paymentRequestId: 'unique-request-id',
1380
+ * merchantOrderId: 'order-123',
1381
+ * orderCurrency: 'USD',
1382
+ * orderAmount: '10.00',
1383
+ * orderDescription: 'Test order',
1384
+ * notifyUrl: 'https://example.com/webhook',
1385
+ * userInfo: {
1386
+ * userId: 'user-123',
1387
+ * userEmail: 'user@example.com',
1388
+ * },
1389
+ * paymentInfo: {
1390
+ * productName: 'Test Product',
1391
+ * },
1392
+ * });
1393
+ *
1394
+ * if (response.isSuccess()) {
1395
+ * console.log('Order created:', response.getData());
1396
+ * }
1397
+ * ```
1246
1398
  */
1247
- interface SubscriptionChangeInquiryData {
1248
- /**
1249
- * New subscription request ID after the change.
1250
- */
1251
- subscriptionRequest?: string;
1252
- /**
1253
- * Original subscription request ID that was changed.
1254
- */
1255
- originSubscriptionRequest?: string;
1256
- /**
1257
- * Merchant's new subscription plan ID.
1258
- */
1259
- merchantSubscriptionId?: string;
1260
- /**
1261
- * New Waffo subscription ID.
1262
- */
1263
- subscriptionId?: string;
1264
- /**
1265
- * Current status of the subscription change.
1266
- */
1267
- subscriptionChangeStatus?: SubscriptionChangeStatus;
1268
- /**
1269
- * Action guide for user authorization.
1270
- */
1271
- subscriptionAction?: string;
1272
- /**
1273
- * Remaining amount from the original subscription.
1274
- */
1275
- remainingAmount?: string;
1276
- /**
1277
- * Subscription currency (ISO 4217).
1278
- */
1279
- currency?: string;
1280
- /**
1281
- * User payment currency.
1282
- */
1283
- userCurrency?: string;
1284
- /**
1285
- * Request time.
1286
- */
1287
- requestedAt?: string;
1288
- /**
1289
- * Subscription management URL.
1290
- */
1291
- subscriptionManagementUrl?: string;
1292
- /**
1293
- * Extended info.
1294
- */
1295
- extendInfo?: string;
1296
- /**
1297
- * Order expiry time.
1298
- */
1299
- orderExpiredAt?: string;
1300
- /**
1301
- * Product information list.
1302
- */
1303
- productInfoList?: SubscriptionChangeProductInfo[];
1399
+ declare class OrderResource extends BaseResource {
1400
+ private static readonly PATH_CREATE;
1401
+ private static readonly PATH_INQUIRY;
1402
+ private static readonly PATH_CANCEL;
1403
+ private static readonly PATH_REFUND;
1404
+ private static readonly PATH_CAPTURE;
1304
1405
  /**
1305
- * Merchant information.
1406
+ * Creates a new payment order.
1407
+ *
1408
+ * @param params - Order creation parameters
1409
+ * @param options - Optional request options
1410
+ * @returns API response with order data
1411
+ * @throws WaffoUnknownStatusError for network errors
1306
1412
  */
1307
- merchantInfo?: SubscriptionMerchantInfo;
1413
+ create(params: CreateOrderParams, options?: RequestOptions): Promise<ApiResponse<CreateOrderData>>;
1308
1414
  /**
1309
- * User information.
1415
+ * Queries an existing order.
1416
+ *
1417
+ * @param params - Order inquiry parameters
1418
+ * @param options - Optional request options
1419
+ * @returns API response with order data
1420
+ * @throws WaffoUnknownStatusError for network errors
1310
1421
  */
1311
- userInfo?: SubscriptionUserInfo;
1422
+ inquiry(params: InquiryOrderParams, options?: RequestOptions): Promise<ApiResponse<InquiryOrderData>>;
1312
1423
  /**
1313
- * Goods information.
1424
+ * Cancels an existing order.
1425
+ *
1426
+ * @param params - Order cancellation parameters
1427
+ * @param options - Optional request options
1428
+ * @returns API response with cancellation result
1429
+ * @throws WaffoUnknownStatusError for network errors
1314
1430
  */
1315
- goodsInfo?: {
1316
- goodsId?: string;
1317
- goodsName?: string;
1318
- goodsCategory?: string;
1319
- goodsUrl?: string;
1320
- appName?: string;
1321
- skuName?: string;
1322
- goodsUniquePrice?: string;
1323
- goodsQuantity?: number;
1324
- [key: string]: unknown;
1325
- };
1431
+ cancel(params: CancelOrderParams, options?: RequestOptions): Promise<ApiResponse<CancelOrderData>>;
1326
1432
  /**
1327
- * Address information.
1433
+ * Refunds an existing order.
1434
+ *
1435
+ * @param params - Order refund parameters
1436
+ * @param options - Optional request options
1437
+ * @returns API response with refund result
1438
+ * @throws WaffoUnknownStatusError for network errors
1328
1439
  */
1329
- addressInfo?: {
1330
- address?: string;
1331
- city?: string;
1332
- region?: string;
1333
- postcode?: string;
1334
- addressCountryCode?: string;
1335
- [key: string]: unknown;
1336
- };
1440
+ refund(params: RefundOrderParams, options?: RequestOptions): Promise<ApiResponse<RefundOrderData>>;
1337
1441
  /**
1338
- * Payment information.
1442
+ * Captures an authorized order.
1443
+ *
1444
+ * @param params - Order capture parameters
1445
+ * @param options - Optional request options
1446
+ * @returns API response with capture result
1447
+ * @throws WaffoUnknownStatusError for network errors
1339
1448
  */
1340
- paymentInfo?: SubscriptionPaymentInfo;
1341
- [key: string]: unknown;
1449
+ capture(params: CaptureOrderParams, options?: RequestOptions): Promise<ApiResponse<CaptureOrderData>>;
1342
1450
  }
1343
1451
 
1344
1452
  /**
@@ -1782,13 +1890,13 @@ declare class Waffo {
1782
1890
  * // Setup webhook handler
1783
1891
  * const handler = waffo.webhook()
1784
1892
  * .onPayment((notification) => {
1785
- * console.log('Payment:', notification.orderStatus);
1893
+ * console.log('Payment:', notification.result?.orderStatus);
1786
1894
  * })
1787
1895
  * .onRefund((notification) => {
1788
- * console.log('Refund:', notification.refundStatus);
1896
+ * console.log('Refund:', notification.result?.refundStatus);
1789
1897
  * })
1790
1898
  * .onSubscriptionStatus((notification) => {
1791
- * console.log('Subscription:', notification.subscriptionStatus);
1899
+ * console.log('Subscription:', notification.result?.subscriptionStatus);
1792
1900
  * });
1793
1901
  *
1794
1902
  * // In Express.js route handler
@@ -2007,4 +2115,4 @@ declare const RsaUtils: {
2007
2115
  generateKeyPair: typeof generateKeyPair;
2008
2116
  };
2009
2117
 
2010
- 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 PeriodType, type ProductInfo, type RefundNotification, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionPaymentInfo, type SubscriptionPaymentNotification, 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 };
2118
+ 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 };