결제 위젯

결제 위젯이란?

결제 위젯은 카드, 계좌이체 등 다양한 결제수단을 하나의 UI에서 처리할 수 있는 통합 결제창입니다. widgets 객체를 통해 렌더링하고 결제를 요청할 수 있습니다.

위젯 렌더링

결제 금액과 통화를 설정하고, renderPaymentMethods 메서드를 호출하여 위젯을 특정 DOM 요소에 렌더링합니다.

const widgets = tossPayments.widgets({ customerKey: 'YOUR_UNIQUE_CUSTOMER_KEY' });

widgets.setAmount({ currency: 'KRW', value: 15000 });

widgets.renderPaymentMethods('#payment-methods'); // CSS Selector
widgets.renderAgreement('#agreement'); // 약관 동의

결제 요청

사용자가 결제수단을 선택하고 정보를 입력하면, requestPayment 메서드를 호출하여 결제를 요청합니다. 성공 또는 실패 시 지정된 URL로 리디렉션됩니다.

widgets.requestPayment({
    orderId: "YOUR_ORDER_ID",
    orderName: "프리미엄 구독 서비스",
    successUrl: window.location.origin + "/success",
    failUrl: window.location.origin + "/fail",
    customerEmail: "customer@example.com",
    customerName: "김온누리"
});