2
私はユーザーがStripeを通じて寄付の価値を動的に設定できるようにしようとしています。私はStripeAmount変数を使って 'amount'の値を割り当てることができましたが、私のcharge.phpファイルでこの変数を呼び出そうとすると、変数はnullを返します。私は解決のために無限にGoogleを検索しているが、何もしていない。私は相対的な初心者です。サーバー側のコードで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();
}
私はOを行うために必要なne small edit、それ以外は完璧でした。大変感謝します。 –