[Stripe] Checkout Custom

Example of a Checkout custom integration.

by Cam Gould

HTML

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

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

JavaScript

var handler = StripeCheckout.configure({
    key: 'pk_test_6pRNASCoBOKtIshFeQd4XMUh',
    locale: 'auto',
    email: '[email protected]',
    token: function (token) {
        // Use the token to create the charge with a server-side script.
        // You can access the token ID with `token.id`
    }
});

$('#customButton').on('click', function (e) {
    var stripeAmount = 1000; // integer, in the smallest currency unit
    var displayAmount = (stripeAmount / 100).toFixed(2);
    var panelLabel = "Buy for Kr " + displayAmount;
    // Open Checkout with further options
    handler.open({
        name: 'Stripe.com',
        description: '2 widgets',
        panelLabel: panelLabel
    });
    e.preventDefault();
});

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