Created
October 24, 2015 15:25
-
-
Save srmklive/aa377b9995acebc0e16f to your computer and use it in GitHub Desktop.
Automatically trigger stripe checkout form
This file contains 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
<form name="checkoutform" action="/payment" method="POST"> | |
<input type="hidden" name="stripeToken" id="stripe_token" /> | |
</form> | |
<script src="https://checkout.stripe.com/checkout.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
<button id="customButton" style="display:none;">Purchase</button> | |
<script> | |
var handler = StripeCheckout.configure({ | |
key: "YOUR_STRIPE_PUBLISHABLE_KEY", | |
token: function(token, args) { | |
document.getElementById("stripe_token").value = token.id; | |
document.checkoutform.submit(); | |
}}); | |
var click_event = document.getElementById('customButton').addEventListener('click', function(e) { | |
// Open Checkout with further options | |
handler.open({ | |
name: "YOUR_SITE_NAME", | |
description: "YOUR_ORDER_DESCRIPTION", | |
amount: "ORDER_COST", // If cost is 2 USD, then value here should be 2*100=200 | |
currency: "USD", | |
email: "USER_EMAIL", | |
image: "YOUR_LOGO_PATH" | |
}); | |
e.preventDefault(); | |
}); | |
$(window).load(function(){ | |
$("button#customButton").trigger('click'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment