【发布时间】:2014-04-28 01:41:03
【问题描述】:
我试图让 Stripe 的结帐自定义按钮向信用卡收费,但它所做的只是在我输入信用卡详细信息后最小化。我正在使用文档中的代码,但我无法让它工作。这个简单的按钮很容易使用,我认为它就像自定义那个按钮一样简单,但它非常不同。
代码如下:
付款页面
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="submit" value="Pay with card" id="customButton"/>
<?php require_once('./config.php'); ?>
<script>
var handler = StripeCheckout.configure({
key: '<?php echo $stripe['publishable_key']; ?>',
image: 'favicon.png',
token: function(token, args) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Imprintnation',
description: 'Decals',
amount: <?php echo $stripeTotal; ?>
});
e.preventDefault();
});
</script>
</form>
收费页面(charge.php)
<?php
require_once(dirname(__FILE__) . '/config.php');
$token = $_POST['stripeToken'];
$customer = Stripe_Customer::create(array(
'email' => 'customer@example.com',
'card' => $token
));
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $5!</h1>';
?>
配置页面(config.php)
<?php
require_once('./lib/Stripe.php');
$stripe = array(
secret_key => 'sk_test_************************',
publishable_key => 'pk_test_************************'
);
Stripe::setApiKey($stripe['secret_key']);
?>
我在这里缺少什么?我什至无法让它检索令牌。
如何取回令牌并从卡中扣款?
【问题讨论】:
-
大概你必须在 stripe.com 上设置一个回调页面,并将它们定向到你的
charge.php,这样你就可以得到令牌,我假设 stripe 的工作方式类似于 paypal,我没有检查跨度> -
这直接来自他们的文档,并没有提到任何关于设置回调页面的内容。
-
您可以尝试
var_dump($charge)看看是否有任何返回。还要检查你的服务器是否为 php 安装了 curl 扩展,它需要它来与他们的服务器交互 -
似乎他们回调到您发帖的同一页面,所以您可能是对的,无需配置 stripe.com/docs/tutorials/forms#create-a-single-use-token
标签: javascript php checkout stripe-payments