【发布时间】:2019-03-01 12:03:30
【问题描述】:
我正在处理条纹并在收取金额时出现错误 我使用的代码是
<button id="customButton" class="submit_btn">Make Appointment</button>
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="hidden" id="stripeToken" name="stripeToken" />
<script>
var handler = StripeCheckout.configure({
key: 'TOKEN',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
jQuery(function ($) {
console.log("testing12");
var value = $('#stripeToken').val(token.id);
console.log(value);
});
}
});
jQuery(function ($) {
document.getElementById('customButton').addEventListener('click', function (e) {
var amount = 0;
$('input:checkbox:checked').each(function(){
amount += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
$('#total').text(amount);
});
handler.open({
name: 'Sports Solution',
description: '',
amount: amount
});
e.preventDefault();
});
<?php
\Stripe\Stripe::setApiKey("sk_test TOTEN");
$token = $_POST['stripeToken'];
var_dump($token);
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
]);
?>
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
</script>
出现的错误在条纹上可见,就像它显示的那样 { “错误”: { “代码”:“参数缺失”, "doc_url": "https://stripe.com/docs/error-codes/parameter-missing", "message": "必须提供来源或客户。", “类型”:“invalid_request_error” } }
【问题讨论】:
-
'source' => $token,传入的值应该是以tok_开头的字符串。您能否检查以确认您在那里获得了正确的$token值?
标签: stripe-payments