JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<div id="last4"></div>
JavaScript
var handler = StripeCheckout.configure({
key: 'pk_test_6SzygDGYEwZBeuUSebyMV4J1',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
console.log(token);
document.getElementById('last4').innerHTML = token.card.last4;
// you'd then want to do something with token.id and submit your form
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Demo Site',
description: '2 widgets',
zipCode: true,
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});