2
我試圖讓用戶通過Stripe動態設置他們的捐贈值。我已經能夠使用StripeAmount變量爲'amount'賦值,但是當我嘗試在我的charge.php文件中調用該變量時,該變量返回null。我有搜索谷歌無盡的解決方案,但沒有工作。我是一個相對的新手。STRIPE - 在charge.php上調用時動態設置金額返回null
=表單代碼=
<form id="target_form" action="charge.php" method="POST">
<script src="https://checkout.stripe.com/checkout.js"></script>
<button class="stripe_button_style" id="myStripeButton">Give By Card</button>
<script>
var handler = StripeCheckout.configure({
key: "pk_test_xxxxxxxxxxxxxxxx",
image: "includes/images/stripe_logo.png",
token: function(token, args){
var form = $('#target_form');
form.append($('<input type="hidden" name="stripeToken" />').val(token.id));
form.get(0).submit();
}
});
document.getElementById('myStripeButton').addEventListener('click', function(e) {
var StripeAmount = $("#donation_amount").val() *100;
handler.open({
name: "company name",
description: "donation",
panelLabel: "Give:",
allowRememberMe: true,
amount: StripeAmount,
zipCode: true,
shippingAddress: true,
billingAddress: true
});
e.preventDefault();
});
$(window).on('popstate', function() {
handler.close();
});
</script>
</form>
= Charge.php代碼=
<?php require_once('includes/stripe/init.php');
$stripe = array(
"secret_key" => "sk_test_xxxxxxxxxxxxxxxxxxxxxxxx",
"publishable_key" => "pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
try {
$customer = \Stripe\Customer::create(array(
'email' => $_POST['stripeEmail'],
'source' => $token));
$charge = \Stripe\Charge::create(array(
'amount' => $amount,
'customer' => $customer->id,
'currency' => "usd",
'description' => $email));
echo 'Thank you for your donation. We will send you a receipt by email for your tax records within 48hours';
var_dump($charge);
}catch(\Stripe\Error\Card $e){
echo $e->getMessage();
}
我需要做出Ø ne小編輯,但否則這是完美的。非常感謝。 –