var stripePublishableKey = 'pk_test_P5VzMOKf8Mg3vVLlonXAFkEM';
var amount = 100;
var currency = 'eur';
Stripe.setPublishableKey(stripePublishableKey);
// Create Checkout's handler
var handler = StripeCheckout.configure({
key: stripePublishableKey,
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
allowRememberMe: false,
token: function(token) {
// use Checkout's card token to create a card source
Stripe.source.create({
type: 'card',
token: token.id
}, stripeCardResponseHandler);
displayProcessing();
}
});
$('#customButton').on('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Stripe.com',
description: '2 widgets',
amount: amount,
currency: currency
});
e.preventDefault();
});
// Close Checkout on page navigation:
$(window).on('popstate', function() {
handler.close();
});
function displayProcessing() {
document.getElementById("processing").style.display = 'block';
document.getElementById("charge-form").style.display = 'none';
document.getElementById("result").style.display = 'none';
}
function displayResult(resultText) {
document.getElementById("processing").style.display = 'none';
document.getElementById("charge-form").style.display = 'block';
document.getElementById("result").style.display = 'block';
document.getElementById("result").innerText = resultText;
}
function stripeCardResponseHandler(status, response) {
if (response.error) {
var message = response.error.message;
displayResult("Unexpected card source creation response status: " + status + ". Error: " + message);
return;
}
// check if the card supports 3DS
if (response.card.three_d_secure == 'not_supported') {
displayResult("This card does not support 3D Secure.");
return;
}
// since we're going to use an iframe in this example, the
// return URL will only be displayed briefly before the iframe
// is...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.