php에서 결제연동 테스트를 진행하려고 합니다.

가이드북 문서에 적혀있는 대로 아래와 같은 소스로 만들었는데 브라우저 콘솔상에 [caught Error: selector에 해당하는 element를 찾을 수 없습니다. selector 값을 다시 확인해주세요. (selector: #payment-method)] 이런 에러문구가 뜨는데 확인 바랍니다. <?php $clientKey = "testck"; $customerKey = "testsk"; ?> <head> <title>결제하기</title> <script src="https://js.tosspayments.com/v1/payment-widget"></script> </head> <body> <script> const clientKey = '<?php echo $clientKey?>'; const customerKey = '<?php echo $customerKey?>'; var paymentWidget = PaymentWidget(clientKey, customerKey); // 결제위젯 초기화 paymentWidget = PaymentWidget(clientKey, PaymentWidget.ANONYMOUS); // 비회원 결제 paymentWidget.renderPaymentMethods('#payment-method', 15000); paymentWidget.requestPayment({ orderId: 'AD8aZDpbzXs4EQa-UkIX6', orderName: '토스 티셔츠 외 2건', successUrl: 'http://localhost:8080/success', failUrl: 'http://localhost:8080/fail', customerEmail: 'customer123@gmail.com', customerName: '김토스' }); </script> <input type="text" name="payment-method" id="payment-method" /> <button type="button" onClick="requestPayment();">결제하기</button> </body> </html>
4 Replies
토스페이먼츠 BOT
3/12 이후에 결제 연동을 해보신 분들을 찾습니다!🔎
제품 발전을 위해 설문에 참여해주세요! 추첨을 통해 선물을 드립니다. (1분 소요)
이실장
이실장2y ago
스크립트를 아래에 넣어주세요. DOM이 생성되기전에 스크립트가 실행되서 Payment-method를 못찾는 겁니다. <input type="text" name="payment-method" id="payment-method" /> 이것보다 밑에 스크립트를 실행해주셔야해요. 아니면 DOM이 생성완료된 이벤트를 받아 랜더링 함수를 사용해주세요.
슬플땐우럭
슬플땐우럭OP2y ago
감사합니다. 잘되네요 ㅎㅎㅎ
토스페이먼츠 BOT
❤️ 기술문의 경험이 어떠셨나요?!
간단히 코멘트 남겨주세요! 제품 발전에 큰 힘이 됩니다.

Did you find this page helpful?