0

We have a small problem on our checkout where customers are sometimes shown the wrong price.

For example if the total should be £150.00 its showing as £15,000

Its really hard for us to debug as we cant replicate the problem ourselves and it doesn't seem to be browser dependent.

We are taking the amount in GBP £

Here is the code we use:

 <form action="/user/dashboard/releases/card/{$release->releaseFrontID}/" method="POST" class="stripe-container"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="REMOVED" data-amount="{math equation='x * 100' x=$release->releaseGrandTotal}"
  • I believe what you're seeing is 15,000 pence, which is £150 converted into the smallest units of that currency. More info: http://stackoverflow.com/a/35326901/1459653 – Mark Gavagan Feb 28 '17 at 12:19

1 Answers1

0

So I think you should do two things. First, make sure you're setting your currency correctly and not simply overriding the label. Because your code sample actually isn't complete, it's tough for me to say what's going wrong. My guess is that your little math script is going wonky though.

I'd recommend separating the math out and putting it into a separate section for calculation and using the Custom Checkout Integration [1] as opposed to the Basic Checkout Integration.

[1] https://stripe.com/docs/checkout#integration-custom

Original:

<form action="/user/dashboard/releases/card/{$release->releaseFrontID}/" method="POST" class="stripe-container"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="REMOVED" data-amount="{math equation='x * 100' x=$release->releaseGrandTotal}"

Recommended:

<script src="https://checkout.stripe.com/checkout.js"></script>

<button id="customButton">Purchase</button>

<script>

  var amount = 100 * {$release->releaseGrandTotal};
  console.log('Amount >> ' + amount);

  var handler = StripeCheckout.configure({
    key: 'pk_test_xxx',
    locale: 'auto',
    currency: 'gbp',
    amount: amount,
    token: function(token) {
      $.post(
        "/user/dashboard/releases/card/{$release->releaseFrontID}/",
        {
          stripeToken: token.id,
          stripeAmount: amount,
          stripeEmail: token.email
        }, function (data, status) {
          // request succeeded, do something
        }
      );
    }
  });

  $('#customButton').on('click', function(e) {

    // Open Checkout with further options:
    handler.open({
      name: 'Company Name',
      description: 'Charge Description'
    });
    e.preventDefault();
  });

  // Close Checkout on page navigation:
  $(window).on('popstate', function() {
    handler.close();
  });
</script>

Once you've done that, it should be obvious where the problem is happening. Is this a Smarty template? Have you considered passing the amount as part of the context, rather than doing some kind of math equation in the templating language?

korben
  • 1,146
  • 7
  • 7