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]);
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]);