我正在使用Stripe(高级结帐)和PHP。我在输入测试卡详细信息时收到的错误500表示不知所措。
我可以确认PHP版本是7 +
我的代码是:
<script>
var handler = StripeCheckout.configure({
key: 'XXXXXXXXXXXXXXXXXXXXXXX',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
token: function(token) {
var $theToken = $('<input type=hidden name=stripeToken />').val(token.id);
$('form').append($theToken);
$("#stripeAmount").val(Math.floor($("#stripePence").val() * 100));
var path = "<?php bloginfo('template_url');?>/charge.php";
$.post(path, $("form").serialize(), function (data) {
if (data == "success") {
alert("Success");
}
else {
alert(data);
}
});
}
});
$('#submit').on('click', function(e) {
var stripeAmount = Math.floor($("#stripePence").val() * 100);
var displayAmount = parseFloat(Math.floor($("#stripePence").val() * 100) / 100).toFixed(2);
var stripeEmail = $('#email').val();
handler.open({
name: 'Demo Site',
description: 'Custom amount ($' + displayAmount + ')',
currency: 'gbp',
email: stripeEmail,
amount: stripeAmount,
});
e.preventDefault();
});
$(window).on('popstate', function() {
handler.close();
});
</script>
Charge.php
<?php
try {
require_once('config.php');
$email = $_POST['stripeEmail'];
$token = $_POST['stripeToken'];
$total = $_POST['stripeAmount'],
$err = array();
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token,
));
$charge = \Stripe\Charge::create(array(
"customer" => $customer->id,
"amount" => 1000,
"currency" => "gbp",
"description" => "Payment for Flowers"
));
} catch (\Stripe\Error\ApiConnection $e) {
$err[] = $e->getMessage();
} catch (\Stripe\Error\InvalidRequest $e) {
$err[] = $e->getMessage();
} catch (\Stripe\Error\Api $e) {
$err[] = $e->getMessage();
} catch (\Stripe\Error\Card $e) {
$err[] = $e->getMessage();
}
/*Count errors (if any)*/
if(count($err)) {
foreach($err as $one_er){
echo $one_er . "<br/>";
}
exit();
}
if (empty($err) === true) {
echo "success";
}
?>
查看console.log,stripeName,stripeEmail,stripeToken和stripeAmount都被发送到charge.php了。
我试图让用户选择各种可以改变价格的选项(因此可以作为变量)。
是否有其他人看到我遗失或做错的事情?
非常感谢