async function requestTossPayment(site, keyword, payMethod) {
console.log("requestTossPayment 호출됨", site, keyword, payMethod);
let method = "CARD"; // 기본값
if (payMethod === "카드") method = "CARD";
else if (payMethod === "가상계좌") method = "VIRTUAL_ACCOUNT";
else if (payMethod === "계좌이체") method = "TRANSFER";
let baseUrl = window.location.origin; // 현재 도메인 자동 사용
let options = {
amount: {
currency: "KRW",
value: finalPrice // 최종 결제 금액 사용
},
orderId: generateRandomString(),
orderName: "고정 URL 구매",
successUrl: baseUrl + "/buy-success",
failUrl: baseUrl + "/buy-cancel",
method: method,
metadata: {
keyword: keyword,
site: site
}
};
// :white_check_mark: 결제 방식별 옵션 분리
if (payMethod === "카드") {
options.method = "CARD";
options.card = {
useEscrow: false,
flowMode: "DEFAULT",
useCardPoint: false,
useAppCardOnly: false
};
} else if (payMethod === "가상계좌") {
options.method = "VIRTUAL_ACCOUNT";
} else if (payMethod === "계좌이체") {
options.method = "TRANSFER";
} else if (payMethod === "카카오페이") {
options.method = "KAKAOPAY";
} else if (payMethod === "네이버페이") {
options.method = "NAVERPAY";
}
const optionsJson = JSON.stringify(options, null, 2);
// alert(optionsJson); // 결제 옵션을 JSON 문자열로 변환하여 alert로 표시
// console.log("결제 옵션(JSON):", optionsJson);
await payment.requestPayment(options);
}