------------------------------------------------------------------------ 파일구성 JS wd_module/pay/module.js HTML wd_module/pay/index.html 성공시 /wd_module/pay/toss_ok.html tosspayments-sample-main/php-javascript/public/payment/success.html 복사
실패시 /wd_module/pay/toss_no.html tosspayments-sample-main/php-javascript/public/fail.html 복사
액션 결제버튼을 클릭하면 requestPayment 함수를 호출하고 결제 승인 결과에 따라 toss_ok.html, toss_no.html 로 받음
오류 결제를 실패했어요 에러메시지 Unexpected token '<', "<!DOCTYPE "... is not valid JSON 에러코드 undefined ------------------------------------------------------------------------
위 답변에서 index.php 에서 function confirmPayment 가 호출되는지 확인해 보세요. 라고 하는데 저는 index.php 를 아래와 같이 수정 case '/confirm/payment': echo json_encode(["ok" => "confirmPayment call"]); exit; if ($requestMethod === 'POST') { confirmPayment($encryptedApiSecretKey); } break;
그런후 테스트를 해보면 index.php 는 호출되고 있지 않는것 같습니다. 첫번째 질문입니다. 위 처리에서 어디가 문제인걸까요?
그리고 추가로 샘플의 index.php 는 실제 개발時에는 필요없는 부분이라고 보여집니다.
예를 들어 카드로 결제한다고 했을때 사용자가 결제버튼을 클릭하면 금액, 상품명, 이메일, 성명을 해당 결제건에 맞도록 requestPayment 함수에 반영하고 해당 함수는 toss 결제 API 를 호출하여 승인 처리를 하고 특별한 오류가 없다면 requestPayment.successUrl 로 실제 처리에 필요한 값들을 넘겨 requestPayment.successUrl 의 confirm 함수에서 처리된 승인 결과에 따라 아래의 then 과 catch 에서 사용자에 맞도록 처리하면 된다 confirm() .then(function (data) { // TODO: 결제 승인에 성공했을 경우 UI 처리 로직을 구현하세요. document.getElementById("response").innerHTML =
<pre>${JSON.stringify(data, null, 4)}</pre>
<pre>${JSON.stringify(data, null, 4)}</pre>
; }) .catch((err) => { // TODO: 결제 승인에 실패했을 경우 UI 처리 로직을 구현하세요. window.location.href =