【发布时间】:2017-07-30 20:51:59
【问题描述】:
我需要允许用户使用 Stripe 输入自定义金额。他们在输入中输入他们想要支付的费用。然后我有一个脚本来收集默认条纹结帐按钮下方的金额。但是我应该如何处理charge.php 上的收费服务器端?
donation.php
//user enter custom amount
<input type="number" class='form-control'
id="custom-donation-amount"
placeholder="$50.00" min="0" step="10.00 " />
//default stripe checkout button
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_XXXXXXXXXXXXXXX"
data-amount="0"
data-name="ORGANIZATION"
data-description="Saving Penguins"
data-image="logo.png"
data-locale="auto"
data-zip-code="true"
data-billing-address="true"
data-label="DONATE"
data-currency="usd">
</script>
//script to collect variable amount
<script type="text/javascript">
$(function() {
$('.donate-button').click(function(event) {
var amount = $('#custom-donation-amount').val();
$('.stripe-button').attr('data-amount', amount)
});
});
</script>
charge.php
<?php require_once('./config.php');
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$customer = \Stripe\Customer::create(array(
'source' => $token,
'email' => $email)
);
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'usd'
));
header("Location: confirmation.php");
die();
?>
【问题讨论】:
标签: php stripe-payments