所以我正在尝试在我的服务器上设置条纹,但我遇到了问题。我在我的页面上使用结帐 v2,表单运行良好,但是令牌永远不会传递到我的 php 文件。该卡已收费,但信息未显示在仪表板上,但它在日志中。
这是我所拥有的:
<form action="assets/php/slingshot.php" method="POST">
<button id="customButton">Purchase</button>
<script>
$('#customButton').click(function(){
var token = function(res){
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('form').append($input).submit();
};
StripeCheckout.open({
key: 'pk_live_*************************',
address: true,
amount: 2500,
currency: 'usd',
name: 'test',
description: 'A bag of test',
panelLabel: 'Checkout',
token: token
});
return false;
});
</script>
</form>
然后是弹弓.php:
<?php
require_once(dirname(__FILE__) . '/config.php');
$token = $POST['stripeToken']; //get the creditcard details from the form
try {
$charge = Stripe_Charge::create(array(
'card' => $token,
'amount' => 2500, //amount in cents
'currency' => 'usd',
'description' => 'Get Bacon Direct, LLC'
));
} catch(Stripe_CardError $e) {
// The card has been declined
}
echo '<h1>Successfully charged $25.00 </h1>';
}
?>
和我的配置.php文件:
<?php
require_once('stripe-php/lib/Stripe.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://manage.stripe.com/account
$stripe = array(
"secret_key" => "sk_live_************************************",
"publishable_key" => "pk_live_************************************"
);
Stripe::setApiKey($stripe['secret_key'] );
?>
你能帮帮我吗?
我不完全确定收费是如何进行的,但我相当有信心你没有得到令牌的原因是因为这条线
$token = $POST['stripeToken']; //get the creditcard details from the form
在 PHP 中访问 POST 数据时,全局变量以下划线为前缀,因此您需要这样做
$token = $_POST['stripeToken']; //get the creditcard details from the form
这应该可以解决它。
--更新---
只是为了可读性,在您的 javascript 中,我会指定输入字段如下
var $input = $('<input type="hidden" name="stripeToken" />').val(res.id);
我还再次查看了条纹文档,看起来卡属性是可选的,客户也是如此,但它确实指出必须提供一个。很有可能,它不会因为他们的代码问题而引发错误,而这些问题没有抓住两者都不提供的可能性。