결제연동 결제 요청 변수 추가 (PHP)
PHP index.html에서 결제 성공시 orderName, amount 값을 success로 보내고 success에서 GET으로 받고 있는데
orderName과 amount 이외의 변수 값을 넣어서 success에 보내고 그 값을 DB에 저장하고 싶은데 success에서 변수값을 다 못받네요 구현할 방법이 있을까요?
ex) amount 경우에는
store.php -> index.html(기존 토스 페이먼츠 페이지) -> success.php 에서
store.php에서 amount 값을 입력하고 index.html에서 amount값을 GET으로 받고 이 값을 requestPayment를 통해 success.php로 전송중인데 이렇게 할 수 있는 게 amount 이외에 가능한게 있는지
store.php
header("Location: /url/index.html?amount=" . urlencode($pay_amount) . "&text=".urlencode($pay_text));
index.html
<script>
const urlParams = new URLSearchParams(window.location.search);
const amount = urlParams.get('amount');
const orderName = urlParams.get('text');
</script>
paymentWidget.renderPaymentMethods("#payment-method", { value: amount });
const paymentRequestButton = document.getElementById(
"payment-request-button"
);
paymentRequestButton.addEventListener("click", () => {
/** 결제 요청
* @docs https://docs.tosspayments.com/reference/widget-sdk#requestpayment%EA%B2%B0%EC%A0%9C-%EC%A0%95%EB%B3%B4
*/
paymentWidget.requestPayment({
orderId: generateRandomString(),
orderName: orderName, amount: amount, success.php $orderId = $_GET['orderId']; $amount = $_GET['amount'];
orderName: orderName, amount: amount, success.php $orderId = $_GET['orderId']; $amount = $_GET['amount'];
결제위젯 JavaScript SDK | 토스페이먼츠 개발자센터
결제위젯 JavaScript SDK를 추가하고 메서드를 사용하는 방법을 알아봅니다.
5 Replies
⏳ 잠시만 기다려주세요! 곧 답변드리겠습니다
오류 문의일 경우 아래 정보를 미리 전달해주시면, 빠른 답변에 도움이 됩니다.
- 주문번호(orderId) :
- 문의 내용 :
(img를 함께 첨부해주시면 도움이됩니다)
* 계약관련 내용은 1544-7772로 문의주세요.
* 주말/공휴일에는 답변이 늦을 수 있어요.
successurl 설정하실 때 뒤에 getParam으로 더 붙여서 보내시면 될것같아요
ex: localhost:8080/success.php?product=사과
mid는 어떻게 되실까요?
그런데 원래 amount 는 저희가 보내드립니다.
successurl에 붙여서 해보겠습니다 감사합니다.
확인해보니 제가 echo 나타낼때 totalamount로 나타냈었네요 이해했습니다. 감사합니다.
❤️ 기술문의 경험이 어떠셨나요?!
간단히 코멘트 남겨주세요! 제품 발전에 큰 힘이 됩니다.