Stripe PRAPI
by Atty Eleti
HTML
<script src="https://js.stripe.com/v3/"></script>
<button id="my-button">
Pay now
</button>
Babel + JSX
const stripe = Stripe('pk_test_ozjVjOVezSxwrwsoF4BnqtII');
const paymentRequest = stripe.paymentRequest({
country: 'US',
currency: 'usd',
total: {
label: 'Demo total',
amount: 1000,
},
});
paymentRequest.canMakePayment().then((result) => {
const myButton = document.getElementById('my-button');
if (result) {
myButton.addEventListener('click', () => {
paymentRequest.show();
});
} else {
// Not supported, don't show the button.
myButton.style.display = 'none';
}
});
paymentRequest.on('token', (ev) => {
console.log(ev);
ev.complete('success');
});