发送金额到 Stripe

Send amount to Stripe

我想知道如何在不隐藏输入类型的情况下将自定义数量发送到最终条带化进程,换句话说,我将从表单中获取数据量

这是我的表格:

$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["stripeAmount"] 不存在,但我相信存在一种无需隐藏 输入类型的方法

为什么不在会话中存储总数?

$_SESSION['grandtotal'] = $total;

然后在发布到的文件中,您可以提取该值并将其更改为美分(Stripe 要求),然后再添加到 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();
}