Created
December 3, 2013 23:24
-
-
Save andrewpthorp/7779564 to your computer and use it in GitHub Desktop.
checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script src="https://checkout.stripe.com/checkout.js"></script> | |
<input type="text" id="amount" /> | |
<button id="customButton">Purchase</button> | |
<script> | |
var handler = StripeCheckout.configure({ | |
key: 'your_public_key_here', | |
token: function(token, args) { | |
// Use the token to create the charge with a server-side script. | |
} | |
}); | |
document.getElementById('customButton').addEventListener('click', function(e) { | |
amount = document.getElementById('amount').value; | |
// Strip all non-numeric characters from the amount. | |
// You might want to do some more scrubbing here to ensure that the user | |
// has submitted a valid amount. For instance, if they submit $50, without | |
// a decimal, this would convert to 50 (50 cents), rather than 5000 (50 dollars). | |
formatted_amount = amount.replace(/\D/, ''); | |
handler.open({ | |
name: 'Your Site Name', | |
description: 'Product Description', | |
amount: formatted_amount | |
}); | |
e.preventDefault(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment