Skip to content

Instantly share code, notes, and snippets.

@wioux
Created June 11, 2020 17:49
Show Gist options
  • Save wioux/a421854d401dd10afdcd42d535b4cab9 to your computer and use it in GitHub Desktop.
Save wioux/a421854d401dd10afdcd42d535b4cab9 to your computer and use it in GitHub Desktop.
$.getScript('https://js.stripe.com/v3/', function() {
var stripe = Stripe(STRIPE_TEST_KEY);
var paymentRequest = stripe.paymentRequest({
country: 'US',
currency: 'usd',
total: {
label: 'Demo total',
amount: 1099,
},
requestPayerName: true,
requestPayerEmail: true,
});
var elements = stripe.elements();
var prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
});
// Check the availability of the Payment Request API first.
paymentRequest.canMakePayment();
paymentRequest.canMakePayment().then(function(result) {
if (result) {
prButton.mount('#payment-request-button');
} else {
document.getElementById('payment-request-button').style.display = 'none';
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment