토스페이먼츠 정기결제 requestBillingAuth function에 관한 문의입니다
react에서 토스페이먼츠 정기결제를 연동하고 있습니다. 현재 PaymentCheckout.tsx라는 버튼 컴포넌트안에 useEffect로 토스페이먼츠 sdk를 불러온 후, requestBillingAuth를 콜백으로 불러오고 있습니다. requestBillingAuth안에 sdk를 로딩하게 구현하는거는 문제가 없을까요?
const requestBillingAuth = useCallback(async () => {
// 결제를 요청하기 전에 orderId, amount를 서버에 저장하세요.
// 결제 과정에서 악의적으로 결제 금액이 바뀌는 것을 확인하는 용도입니다.
if (!planId) return;
try {
const tossPayments = await loadTossPayments(clientKey);
const payment = tossPayments.payment({
customerKey,
});
await payment.requestBillingAuth({
method: 'CARD', // 자동결제(빌링)는 카드만 지원합니다
successUrl: window.location.origin + `/success/${orderId}`, // 요청이 성공하면 리다이렉트되는 URL
failUrl: window.location.origin + '/fail', // 요청이 실패하면 리다이렉트되는 URL
customerEmail: userData?.email,
customerName: userData?.nickname,
});
} catch (error) {
if (error.code === 'USER_CANCEL') {
return;
} else {
throw error;
}
}
}, [orderId, payment, userData]);
결제연동⏲️자동결제(빌링)