@tosspayments/tosspayments-sdk 2.5.0 → 2.7.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/types/index.d.ts +211 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tosspayments/tosspayments-sdk",
3
3
  "description": "TossPayments.js Tosspayments SDK.",
4
- "version": "2.5.0",
4
+ "version": "2.7.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "types": "types/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@rollup/plugin-commonjs": "^21.0.1",
27
27
  "@rollup/plugin-typescript": "^8.3.0",
28
28
  "@tosspayments/sdk-loader": "workspace:packages/sdk-loader",
29
- "@tosspayments/standard-public-interfaces": "2.5.0",
29
+ "@tosspayments/standard-public-interfaces": "2.9.0",
30
30
  "happy-dom": "^14.12.3",
31
31
  "prettier": "^2.0.2",
32
32
  "rollup": "^2.60.0",
package/types/index.d.ts CHANGED
@@ -421,6 +421,62 @@ type WidgetPaymentResult = {
421
421
  amount: Amount;
422
422
  };
423
423
 
424
+ interface WidgetPaymentRequestWindow extends WidgetPaymentRequest {
425
+ /**
426
+ * 결제 금액 정보입니다.
427
+ */
428
+ amount: Amount;
429
+ }
430
+ interface WidgetPaymentRequestWindowOptions {
431
+ /**
432
+ * 결제위젯 UI의 variantKey 정보입니다. [결제위젯 어드민](https://dashboard.tosspayments.com/payment-widget-service/)에서 확인할 수 있어요.
433
+ */
434
+ variantKey?: {
435
+ /**
436
+ * 결제수단 UI의 variantKey입니다.
437
+ */
438
+ paymentMethod?: string | null;
439
+ /**
440
+ * 약관 UI의 variantKey입니다.
441
+ */
442
+ agreement?: string | null;
443
+ } | null;
444
+ }
445
+
446
+ interface WidgetPaymentWindow {
447
+ /**
448
+ * 결제창의 이벤트를 구독합니다.
449
+ *
450
+ * @param {'paymentRequest'} eventName 구독할 이벤트입니다. `paymentRequest` 이벤트로 구매자의 결제 요청을 수신하세요.
451
+ * @param {function} callback 이벤트가 일어나면 호출되는 콜백 함수입니다.
452
+ *
453
+ * @example
454
+ * ```javascript
455
+ * paymentWindow.on('paymentRequest', ({ paymentMethod }) => {
456
+ * // 결제 요청 처리
457
+ * });
458
+ * ```
459
+ *
460
+ * @throws {@link PublicError.Widgets.InvalidEventParameterError} eventName이 유효하지 않은 경우
461
+ * @throws {@link PublicError.Widgets.InvalidCallbackParameterError} callback이 유효하지 않은 경우
462
+ * @throws {@link PublicError.Widgets.UnknownError} 알 수 없는 오류가 발생한 경우
463
+ */
464
+ on: (eventName: 'paymentRequest', callback: (params: {
465
+ paymentMethod: WidgetSelectedPaymentMethod;
466
+ }) => Promise<void>) => void;
467
+ /**
468
+ * 결제창을 제거합니다.
469
+ *
470
+ * @example
471
+ * ```javascript
472
+ * await paymentWindow.destroy();
473
+ * ```
474
+ *
475
+ * @throws {@link PublicError.Widgets.UnknownError} 알 수 없는 오류가 발생한 경우
476
+ */
477
+ destroy: () => Promise<void>;
478
+ }
479
+
424
480
  /**
425
481
  * 결제 UI 위젯을 렌더링합니다
426
482
  * @param {object} params 결제 UI 렌더링 정보입니다.
@@ -584,6 +640,135 @@ type RequestPaymentWithRedirection$1 = (paymentRequest: WithRedirection<WidgetPa
584
640
  */
585
641
  type SetAmount = (amount: Amount) => Promise<void>;
586
642
 
643
+ /**
644
+ * 결제창을 통해 결제를 요청합니다
645
+ * @docsDefaultSignature RequestPaymentWindowWithRedirection
646
+ *
647
+ * @param {WidgetPaymentRequestWindow} paymentRequest - 결제 요청 정보입니다.
648
+ * @param {WidgetPaymentRequestWindowOptions} options - 위젯 결제창 옵션입니다.
649
+ *
650
+ * @returns 결제 결과
651
+ *
652
+ *
653
+ * @throws {@link PublicError.Widgets.UserCancelError} 사용자가 결제를 취소한 경우
654
+ * @throws {@link PublicError.Widgets.InvalidVariantKeyError} variantKey 가 유효하지 않은 경우
655
+ * @throws {@link PublicError.Widgets.ProviderStatusUnhealthyError} 결제 기관의 시스템에 문제가 있을 때
656
+ * @throws {@link PublicError.Widgets.UnsupportedTestPhasePaymentMethodError} 테스트 환경을 지원하지 않는 결제수단을 선택한 경우
657
+ * @throws {@link PublicError.Widgets.IncorrectSuccessUrlFormatError} successUrl이 유효하지 않은 경우
658
+ * @throws {@link PublicError.Widgets.IncorrectFailUrlFormatError} failUrl이 유효하지 않은 경우
659
+ * @throws {@link PublicError.Widgets.PaymentRequestFailError} 결제 요청에 실패한 경우
660
+ * @throws {@link PublicError.Widgets.NotSupportedPromiseError} promise 방식을 지원하지 않는 환경인 경우
661
+ * @throws {@link PublicError.Widgets.InvalidMethodTransactionError} 이미 다른 명령을 수행 중인 경우
662
+ * @throws {@link PublicError.Widgets.InvalidMetadataError} metadata가 올바르지 않은 경우
663
+ * @throws {@link PublicError.Widgets.InvalidParametersError} 파라미터가 올바르지 않은 경우
664
+ * @throws {@link PublicError.Widgets.BelowZeroAmountError} 결제 금액이 0원 미만인 경우
665
+ * @throws {@link PublicError.Widgets.UnknownError} 알 수 없는 오류가 발생한 경우
666
+ */
667
+ type RequestPaymentWindow = RequestPaymentWindowWithPromise & RequestPaymentWindowWithRedirection;
668
+ /**
669
+ * @docsAlias Promise 방식
670
+ * @returns `WidgetPaymentResult` 객체가 응답됩니다. 객체 필드를 확인하고 [결제 승인 API](/reference#결제-승인)를 호출해야 결제가 최종적으로 완료돼요.
671
+ * @param {WidgetPaymentRequestWindow} paymentRequest 결제 요청 정보입니다.
672
+ * @param {WidgetPaymentRequestWindowOptions} options 위젯 결제창 옵션입니다.
673
+ *
674
+ * @example
675
+ * ```js
676
+ * widgets.requestPaymentWindow(
677
+ * {
678
+ * orderId: generateRandomString(),
679
+ * orderName: "토스 티셔츠 외 2건",
680
+ * customerEmail: "customer123@gmail.com",
681
+ * customerName: "김토스",
682
+ * },
683
+ * {
684
+ * variantKey: {
685
+ * paymentMethod: "CUSTOM-1",
686
+ * agreement: "AGREEMENT",
687
+ * },
688
+ * }
689
+ * );
690
+ * ```
691
+ *
692
+ */
693
+ type RequestPaymentWindowWithPromise = (paymentRequest: WidgetPaymentRequestWindow, options?: WidgetPaymentRequestWindowOptions) => Promise<WidgetPaymentResult>;
694
+ /**
695
+ * @docsAlias Redirect 방식
696
+ *
697
+ * @returns 결제 요청이 성공하면 파라미터로 설정한 `successUrl`로 이동해요. 쿼리 파라미터의 `amount` 값이 메서드 파라미터로 설정한 `amount`와 같은지 반드시 확인하고 [결제 승인 API](/reference#결제-승인)를 호출해서 결제를 완료하세요.
698
+ * ```plain theme="grey" copyable="false"
699
+ * {successUrl}?paymentType={PAYMENT_TYPE}&amount={AMOUNT}&orderId={ORDER_ID}&paymentKey={PAYMENT_KEY}
700
+ * ```
701
+ * 결제 요청이 실패하면 파라미터로 설정한 `failUrl`로 이동해요. 쿼리 파라미터로 에러 코드와 메시지를 확인하세요.
702
+ * ```plain theme="grey" copyable="false"
703
+ * {failUrl}?code={ERROR_CODE}&message={ERROR_MESSAGE}&orderId={ORDER_ID}
704
+ * ```
705
+ * Redirect 방식에서는 URL이 이동하기 때문에 `void`가 응답됩니다.
706
+
707
+ * @param {WidgetPaymentRequestWindow} paymentRequest 결제 요청 정보입니다.
708
+ * @param {WidgetPaymentRequestWindowOptions} options 위젯 결제창 옵션입니다.
709
+ *
710
+ * @example
711
+ * ```js
712
+ * widgets.requestPaymentWindow(
713
+ * {
714
+ * orderId: generateRandomString(),
715
+ * orderName: "토스 티셔츠 외 2건",
716
+ * successUrl: window.location.origin + "/success.html",
717
+ * failUrl: window.location.origin + "/fail.html",
718
+ * customerEmail: "customer123@gmail.com",
719
+ * customerName: "김토스",
720
+ * },
721
+ * {
722
+ * variantKey: {
723
+ * paymentMethod: "CUSTOM-1",
724
+ * agreement: "AGREEMENT",
725
+ * },
726
+ * }
727
+ * );
728
+ * ```
729
+ */
730
+ type RequestPaymentWindowWithRedirection = (paymentRequest: WithRedirection<WidgetPaymentRequestWindow>, options?: WidgetPaymentRequestWindowOptions) => Promise<void>;
731
+
732
+ /**
733
+ * 결제창을 렌더링합니다
734
+ * @param {object} params 결제창 렌더링 정보입니다.
735
+ *
736
+ * @returns 반환되는 결제창 객체로 아래 메서드를 호출할 수 있어요.
737
+ *
738
+ * @example
739
+ * ```javascript
740
+ * const paymentWindow = await widgets.renderPaymentWindow({
741
+ * variantKey: {
742
+ * paymentMethod: "CUSTOM-1",
743
+ * agreement: "AGREEMENT",
744
+ * },
745
+ * });
746
+ * ```
747
+ *
748
+ * @throws {@link PublicError.Widgets.PaymentWindowAlreadyRenderedError} 이미 결제창이 렌더링 된 경우
749
+ * @throws {@link PublicError.Widgets.UserCancelError} 사용자가 결제창 렌더링을 취소한 경우
750
+ * @throws {@link PublicError.Widgets.NotSetupAmountError} 결제금액이 설정되지 않은 경우
751
+ * @throws {@link PublicError.Widgets.InvalidVariantKeyError} variantKey가 유효하지 않은 경우
752
+ * @throws {@link PublicError.Widgets.InvalidMethodTransactionError} 이미 다른 명령을 수행 중인 경우
753
+ * @throws {@link PublicError.Widgets.InvalidParametersError} 파라미터가 올바르지 않은 경우
754
+ * @throws {@link PublicError.Widgets.UnknownError} 알 수 없는 오류가 발생한 경우
755
+ */
756
+ type RenderPaymentWindow = (params?: {
757
+ /**
758
+ * 결제위젯 UI의 variantKey 정보입니다. [결제위젯 어드민](https://dashboard.tosspayments.com/payment-widget-service/)에서 확인할 수 있어요.
759
+ */
760
+ variantKey?: {
761
+ /**
762
+ * 결제수단 UI의 variantKey입니다.
763
+ */
764
+ paymentMethod?: string;
765
+ /**
766
+ * 약관 UI의 variantKey입니다.
767
+ */
768
+ agreement?: string;
769
+ };
770
+ }) => Promise<WidgetPaymentWindow>;
771
+
587
772
  interface TossPaymentsWidgets {
588
773
  /**
589
774
  * 주문의 결제 금액을 설정합니다. [자세히 >](#widgetssetamount)
@@ -597,10 +782,21 @@ interface TossPaymentsWidgets {
597
782
  * 결제를 요청합니다. 구매자가 결제 UI에서 선택한 결제수단의 결제창을 띄워요. [자세히 >](#widgetsrequestpayment)
598
783
  */
599
784
  requestPayment: RequestPayment$2;
785
+ /**
786
+ *
787
+ * 위젯 결제창으로 결제를 요청합니다. [자세히 >](#widgetsrequestpaymentwindow)
788
+ * @deprecated renderPaymentWindow API로 대체됩니다.
789
+ * @ignore
790
+ */
791
+ requestPaymentWindow: RequestPaymentWindow;
600
792
  /**
601
793
  * 약관 UI를 렌더링합니다. [자세히 >](#widgetsrenderagreement)
602
794
  */
603
795
  renderAgreement: RenderAgreement;
796
+ /**
797
+ * 결제창을 렌더링합니다. [자세히 >](#widgetsrenderpaymentwindow)
798
+ */
799
+ renderPaymentWindow: RenderPaymentWindow;
604
800
  }
605
801
 
606
802
  interface BrandpayAmount extends Amount {
@@ -1276,6 +1472,10 @@ interface TransferPaymentRequest extends PaymentRequest {
1276
1472
  * 문화비(도서, 공연 티켓, 박물관·미술관 입장권 등) 지출 여부입니다.
1277
1473
  */
1278
1474
  isCulturalExpenses?: boolean | null;
1475
+ /**
1476
+ * @ignore
1477
+ */
1478
+ encryptedCustomerCi?: string | null;
1279
1479
  } | null;
1280
1480
  }
1281
1481
 
@@ -1303,9 +1503,9 @@ interface ForeignEasyPayPaymentRequest extends PaymentRequest {
1303
1503
  */
1304
1504
  foreignEasyPay: {
1305
1505
  /**
1306
- * 해외간편결제 코드입니다. 현재는 `PAYPAL`만 지원하고 있어요.
1506
+ * 해외간편결제 코드입니다. 현재는 `PAYPAL`, `PAYPAY`만 지원하고 있어요.
1307
1507
  */
1308
- provider: 'PAYPAL' | 'GCASH' | 'TOUCHNGO' | 'BOOST' | 'BPI' | 'BILLEASE' | 'DANA' | 'ALIPAYHK' | 'TRUEMONEY' | 'RABBIT_LINE_PAY' | 'ALIPAY';
1508
+ provider: 'PAYPAL' | 'GCASH' | 'TOUCHNGO' | 'BOOST' | 'BPI' | 'BILLEASE' | 'DANA' | 'ALIPAYHK' | 'TRUEMONEY' | 'RABBIT_LINE_PAY' | 'ALIPAY' | 'PAYPAY';
1309
1509
  /**
1310
1510
  * 구매자가 위치한 국가입니다. ISO-3166의 두 자리 국가 코드를 입력하세요.
1311
1511
  */
@@ -1480,6 +1680,15 @@ interface TransferBillingAuthRequest extends BaseBillingAuthRequest {
1480
1680
  * 자동결제(빌링)에 등록할 결제수단입니다.
1481
1681
  */
1482
1682
  method: 'TRANSFER';
1683
+ /**
1684
+ * @ignore
1685
+ */
1686
+ transfer?: {
1687
+ /**
1688
+ * @ignore
1689
+ */
1690
+ encryptedCustomerCi?: string | null;
1691
+ } | null;
1483
1692
  }
1484
1693
  /**
1485
1694
  * 자동결제(빌링) 등록 요청 정보입니다. 토스페이먼츠 자동결제는 신용·체크카드, 계좌이체를 지원해요.