0
我一直在嘗試使用條紋來接受付款,我一直試圖從我發現的指南中爲它製作一個粗糙的原型,但我似乎無法得到它的工作。提交後,名爲「stripeToken」的新輸入從不插入。這導致我的PHP腳本永遠不會執行。我試圖理解爲什麼它永遠不會插入。這裏的腳本:Javascript未插入輸入
的Javascript:(在頁面頭部)
<script src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('mykeyishere');
</script>
<script>
// Event Listeners
$('#payment-form').on('submit', generateToken);
var generateToken = function (e) {
var form = $(this);
// No pressing the buy now button more than once
form.find('button').prop('disabled', true);
// Create the token, based on the form object
Stripe.create(form, stripeResponseHandler);
// Prevent the form from submitting
e.preventDefault();
};
</script>
HTML/JavaScript的:(嘗試JS都在頭部和形式)
<form action="index.php" method="POST" id="payment-form">
<script>
var stripeResponseHandler = function (status, response) {
var form = $('#payment-form');
// Any validation errors?
if (response.error) {
// Show the user what they did wrong
form.find('.payment-errors').text(response.error.message);
// Make the submit clickable again
form.find('button').prop('disabled', false);
} else {
// Otherwise, we're good to go! Submit the form.
// Insert the unique token into the form
$('<input>', {
'type': 'hidden',
'name': 'stripeToken',
'value': response.id
}).appendTo(form);
// Call the native submit method on the form
// to keep the submission from being canceled
form.get(0).submit();
}
};</script>
<span class="payment-errors"></span>
<div class="row">
<label>
<span>Card Number</span>
<input type="text" data-stripe="number">
</label>
</div>
<div class="row">
<label>
<span>CVC</span>
<input type="text" data-stripe="cvc">
</label>
</div>
<div class="row">
<label>
<span>Expiration (MM/YYYY)</span>
<input type="text" data-stripe="exp-month">
</label>
<input type="text" data-stripe="exp-year">
</div>
<button type="submit">Submit</button>
</form>
我把它放在另一個腳本的頭部。它仍然沒有工作。我也打開了開發者模式的網絡菜單,但我對JS並不是非常熟悉,所以我不確定我在找什麼。對於另一部分,是的。在提交Stripe.js處理信息,併發回一個令牌並將輸入放入窗體並執行該窗體。 – spencdev