Wednesday, 29 August 2018

Stripe checkout. Checking client amount

Is it possible to check through the stripe if amount witch a client can see in stripe modal window (iframe) on client side equals to amount on server side where stripe charging process is going?

I set amount on client size.

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

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

<script>
  var handler = StripeCheckout.configure({
    key: 'pk_test_1002UFB11gJ1sXBHcdDM8HPi',
    image: '/square-image.png',
    token: function(token) {
      // Use the token to create the charge with a server-side script.
      // You can access the token ID with `token.id`
    }
  });

  document.getElementById('customButton').addEventListener('click', function(e) {
    // Open Checkout with further options
    handler.open({
      name: 'Demo Site',
      description: '2 widgets ($20.00)',
      amount: 2000
    });
    e.preventDefault();
  });

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

I am sending the token from client-side stripe callback to server:

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

$token  = $_POST['stripeToken'];

$charge = Stripe_Charge::create(array(
  'customer' => $customer->id,

  'amount'   => 1000000000000,
  'currency' => 'usd'
  'email' => 'customer@example.com',
  'card'  => $token
));

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

Server side amount is higher than client side one in several times. But this number will be charged by stripe.



from Stripe checkout. Checking client amount

No comments:

Post a Comment