스트라이프 결제를 사용하는 간단한 예를 만들려고합니다. 이이 내가 바탕으로 자바 스크립트 콘솔스트라이프 결제 예가 표시되지 않습니다.
Uncaught Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().
at new t (js.stripe.com/:1)
at t.value (js.stripe.com/:1)
에서받은 오류가 나는 Stripe
의 예를 따라
// Create a Stripe client
var stripe = Stripe('pk_test_XSHE4IYLLy9qCPe7lW7pK4ZE');
// Create an instance of Elements
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base: {
color: '#32325d',
lineHeight: '24px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
// Create an instance of the card Element
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the user if there was an error
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server
stripeTokenHandler(result.token);
}
});
});
.StripeElement {
background-color: white;
padding: 8px 12px;
border-radius: 4px;
border: 1px solid transparent;
box-shadow: 0 1px 3px 0 #e6ebf1;
-webkit-transition: box-shadow 150ms ease;
transition: box-shadow 150ms ease;
}
.StripeElement--focus {
box-shadow: 0 1px 3px 0 #cfd7df;
}
.StripeElement--invalid {
border-color: #fa755a;
}
.StripeElement--webkit-autofill {
background-color: #fefde5 !important;
}
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://js.stripe.com/v3/"></script>
<title>test</title>
</head>
<body>
<form action="/charge" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
<!-- a Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors -->
<div id="card-errors"></div>
</div>
<button>Submit Payment</button>
</form>
</body>
</html>
내 PHP 파일입니다 오류, 스트라이프 js # card 요소를 찾을 수 없습니다 생각합니다. 그러나 그것은 거기에있다.
이것은 덤프 질문 일 수 있습니다 : D하지만 이것은 처음으로 스트라이프를 사용하기 때문에 누군가가 나를 도울 수 있다면 좋을 것입니다. 정말 고마워.
으로,에서 HTML 후 스크립트를 있나요 넣어? 여러분의 코드를 보면서'stripeTokenHandler (result.token);에 의해 참조 된'stripeTokenHandler'를 정의 할 필요가있는 것처럼 보입니다 --- 여기 샘플이 있습니다 https://stripe.com/docs/elements#submit-token – duck
@duck 방금 예제를 정확히 따라갔습니다. 나는 실수를 볼 수있는 나의 포스트 쇼를 편집했다. 고마워요 – trinhdh
흠, 'DOM 요소 없음'오류가 발생하면 페이지에'# card-element'가 있기 전에 JS를로드하는 것처럼 보입니다. 여기에 예제를보십시오 http://jsbin.com/dukecivela/edit?html,output – duck