I am trying to setup stripe checkout and i can get the payment form up and running just fine, however i need to redirect the user to another page only after payment has been successfull. This is the javascript I am using to display the form and to process it but I need to know how and where can i add the code of redirect?
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton" style="border: none" ><img src="/orange_pay_now.png" style="width: 265px;height: 66px;"></button>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_..............',
image: '/orange_pay_now.png',
token: function(token) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Name of Product',
description: 'description goes here',
amount: 800,
currency: 'GBP'
});
e.preventDefault();
});
// Close Checkout on page navigation
window.addEventListener('popstate', function() {
handler.close();
});
</script>
I will really appreciate any assistance.
Checkout should be created within the context of another form on that page (see the simple integration):
https://stripe.com/docs/checkout
When Checkout completes its thing, it'll automatically submit that other form to whatever
action
attribute you use. Then you can use your server-side code to process an actual charge request.If you're using a custom integration, you'll instead want to add code to the token function to submit your form or redirect the browser or whatever.
Hope that helps, Larry
PS I work on Support at Stripe.