Creating a Stripe Charge with JavaScript

Viewed 1632

I have a working piece of code below, I was wondering if it is possible to make a stripe charge within the "successful token" of the checkout process? All the code below is working, I was just wondering where I would insert the code that creates the acctuall charge.

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

    <button id="payment-button" type="button" class="btn btn-success">Pay With Card</button>

    <script>
    var handler = StripeCheckout.configure({
      key: 'mykeyhere',
      image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
      locale: 'auto',
      token: function(token) {
        // You can access the token ID with `token.id`.
        // Get the token ID to your server-side code for use.
        document.getElementById("book-appointment-submit").style.display="block";
        document.getElementById("payment-button").style.display="none";
      }
    });

    document.getElementById('payment-button').addEventListener('click', function(e) {
      // Open Checkout with further options:
      handler.open({
        name: 'DenchCodeLTD',
        description: '2 widgets',
        zipCode: true,
        currency: 'gbp',
        amount: 2000
      });
      e.preventDefault();
    });

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

<!-- End Of Stripe Payment -->

<button id="book-appointment-submit" type="button" class="btn btn-success" style="display:none">
    <span class="glyphicon glyphicon-ok"></span>
    <?php
        echo (!$manage_mode) ? $this->lang->line('confirm')
                : $this->lang->line('update');
    ?>
</button>
1 Answers
Related