dtd14883 2015-05-12 12:18
浏览 91

条纹结账 - 收费金额

I'm following the basic example from https://stripe.com/docs/checkout/guides/php and having problems seeing how the amount can be determine and use in the creation of the charge.

I would have thought/hoped that using the token I created I would be able to retrieve the amount associated with it and pass this amount into \Stripe\Charge::create()?

For example I have some PHP/template code that generates a form for a range of products

# index.php
<?php require_once('./config.php'); ?>

<form action="charge.php" method="post">
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<?php echo $stripe['publishable_key']; ?>"
          data-amount="{$MY_AMOUNT}" data-description="One year's subscription"></script>
</form>

$MY_AMOUNT will change according to the product that is being displayed

Now charge.php receives the post and creates a charge but what is the correct way to specify the value (currently 5000) of the 'amount' index of the array?

<?php
  require_once('./config.php');

  $token  = $_POST['stripeToken'];

  $customer = \Stripe\Customer::create(array(
      'email' => 'customer@example.com',
      'card'  => $token
  ));

  $charge = \Stripe\Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 5000,
      'currency' => 'usd'
  ));

  echo '<h1>Successfully charged $50.00!</h1>';
?>

So, there are 2 approaches I can think of here

  1. A PHP page per product with hardcoded amounts - No thanks
  2. Passing the key and amount as hidden variables, these doesn't seem "right" as it can easily be changed, e.g. below

    <form action="charge.php" method="POST">
        <script
            src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="{$key}"
            data-amount="{$amount}"
            data-currency="GBP"
            data-address="true"
            data-name="{$name}"
            data-description="{$description}"
            data-image="logo.png">
        </script>
        <input name="myHiddenKey" type="hidden" value="{$amount}" />
        <input name="myHiddenName" type="hidden" value="{$name}" />
    </form>
    
  • 写回答

1条回答 默认 最新

  • dphj737575 2015-05-13 14:46
    关注

    No the token is just a precheck to allow you to make a charge, the amount being passed through to Stripe in the Javascript is only used by Stripe for display purposes. Stripe_Charge::create is where you actually pass through the amount.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程