【发布时间】:2015-04-02 18:25:55
【问题描述】:
我正在尝试在我的网站中实施 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>
我希望我的客户更改“数据金额”,以便他们可以更改付款的价值。我确信下面给出的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来处理?
如果有人可以提供帮助,谢谢!
【问题讨论】:
标签: javascript php stripe-payments