我正在尝试将Stripe付款实施到我的网站中,以便客户可以自行收取金额 . 条带文档并不简单,因为集成有困难 .
<form action="charge.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_xxxxxxxxxxxxxxxxxxxx"
data-amount="CHARGE AMOUNT"
data-name="Maid In Raleigh"
data-description="Service Charge"
data-image="/128x128.png">
</script>
</form>
我希望我的客户更改“数据量”,以便他们可以更改付款的 Value . 我确信下面给出的charge.php是一团糟 . 虽然仪表板在其日志文件中注册了令牌,但我无法使其工作 .
<?php
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxx");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => CHARGEAMOUNT, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "Service Charge")
);
echo "<h2>Thank you!</h2>"
echo $_POST['stripeEmail'];
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
echo "<h2>Thank you!</h2>"
?>
有没有办法避免从客户端javascript充电,而是使用PHP来处理?
谢谢,如果有人可以帮忙!
1 回答
几天前我不得不使用条带api处理动态金额的付款 . 我使用了以下代码,我没有使用名称空间 . 但我相信你能够工作 .
需要此数组才能生成令牌 .
现在是时候处理付款了 . 但首先检查令牌是否有效
我使用此代码来设置定期付款系统 . 它工作了!我希望这对你也有帮助 . :)