제가 잘 못하는 것도 있지만… 아직 배우는 단계라서요…
자바스크립트로 json 데이터 보내고 받는 샘플 소스좀 주세요…
단건결제? 그거로 주시면 될 거 같아요.
여기에서 제공하는 설명만으로는 못하겠어요.ㅠㅠㅠㅠㅠㅠㅠㅠ
하… 아니 솔직히 이거 제대로 된 거 맞나 싶기도 하고…
근데 post man으로 해보면 잘 되는 건 확인을 했어요
const url = "https://open-api.kakaopay.com/online/v1/payment/ready";
const data = { "cid" : "TC0ONETIME", "partner_order_id" : "testorder123", "partner_user_id" : "testid123", "item_name" : "testitm", "quantity" : 1, "total_amount" : 1000, "tax_free_amount" : 0
, "approval_url" : "/BeeNb/emp/empLoginForm.jsp", "cancel_url" : "/BeeNb/emp/empLoginForm.jsp", "fail_url" : "/BeeNb/emp/empLoginForm.jsp" };
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "SECRET_KEY DEVF98DB8B895AB9183B7E1B013FD64B990F2BF4"
},
body: JSON.stringify(data),
mode: "no-cors"
})
.then(response => response.json())
.then(data => {
// 결제 승인 URL 처리
window.location.href = data.next_redirect_pc_url;
})
.catch(error => {
console.error("Error:", error);
});
첨에 cors 에러 때문에
mode: "no-cors"를 더 붙어줬어요.
근데도 400에러 뜨네요.