我想知道如何在没有隐藏输入类型的情况下将自定义金额发送到最终条带流程,换句话说我会从表单中获取数据量
这是我的表格:
$Total = 1000000;
<form action="stripe.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key= '.$stripe["publishable"].'
data-amount='.$Total.'
data-name="My Web Site"
data-description="Reservation"
data-email='.$_POST["email"].'
data-image="img/logo2.png"
data-locale="auto">
</script>
</form>
这将是我的过程
if(isset($_POST['stripeToken']))
{
$toke = $_POST['stripeToken'];
$Amount = $_POST["stripeAmount"]; // I don't know how to get this value
$email = $_POST["stripeEmail"]; // Email works good
try
{
Stripe_Charge::create(array(
"amount" => $Amount, // this doesn't work
"currency" => "usd",
"source" => $toke, // obtained with Stripe.js
"description" => $email
));
}
catch(Stripe_CardError $e)
{
alert("Error");
}
header('Location: index.php');
exit();
}
使用print_r($ _ POST)我得到了
Array ( [stripeToken] => tok_1Ax6UbIUY34Xblablablabla [stripeTokenType] => card [stripeEmail] => myemail@outlook.com )
所以,我知道$ _POST [&#34; stripeAmount&#34;]并不存在,但我相信存在一种方法可以做到这一点,而不会隐藏输入类型
答案 0 :(得分:0)
为什么不在会话中存储总数?
$_SESSION['grandtotal'] = $total;
然后在发布到的文件中,您可以在添加到Stripe_Charge对象之前提取该值并将其更改为美分(条带要求):
if(isset($_POST['stripeToken']))
{
$toke = $_POST['stripeToken'];
$amount = $_SESSION["grandtotal"];
$amount *= 100; //convert from dollars to cents.
$email = $_POST["stripeEmail"];
try
{
Stripe_Charge::create(array(
"amount" => $amount,
"currency" => "usd",
"source" => $toke, // obtained with Stripe.js
"description" => $email
));
}
catch(Stripe_CardError $e)
{
alert("Error");
}
header('Location: index.php');
exit();
}