Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active November 19, 2022 05:59
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save ziadoz/5101836 to your computer and use it in GitHub Desktop.
Save ziadoz/5101836 to your computer and use it in GitHub Desktop.
Custom Stripe Checkout Button
<form action="." method="post">
<noscript>You must <a href="http://www.enable-javascript.com" target="_blank">enable JavaScript</a> in your web browser in order to pay via Stripe.</noscript>
<input
type="submit"
value="Pay with Card"
data-key="PUBLISHABLE STRIPE KEY"
data-amount="500"
data-currency="cad"
data-name="Example Company Inc"
data-description="Stripe payment for $5"
/>
<script src="https://checkout.stripe.com/v2/checkout.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
$(document).ready(function() {
$(':submit').on('click', function(event) {
event.preventDefault();
var $button = $(this),
$form = $button.parents('form');
var opts = $.extend({}, $button.data(), {
token: function(result) {
$form.append($('<input>').attr({ type: 'hidden', name: 'stripeToken', value: result.id })).submit();
}
});
StripeCheckout.open(opts);
});
});
</script>
</form>
@alaboudi
Copy link

alaboudi commented Jun 6, 2015

thanks a lot. this really did help

@azimidev
Copy link

This code is very helpful. I'm grateful.

@meghart
Copy link

meghart commented Jul 19, 2015

How do you redirect to a thank you after?

@sk29110
Copy link

sk29110 commented Oct 18, 2015

I tested this one but the charge is never show up in the dashboard. Why?

@campones
Copy link

because it s only one part of the process. after that stripe send you the token, you need to send the charge on the card to stripe.. but I can't find either how to process that part..

@sgrutman978
Copy link

I am trying to change the description attribute with Jquery's .attr(), and when I alert the new value it is correct, but the description on the Stripe popup is not changed!?

@mayur-raval
Copy link

This works great. Thank you!!!

@BusinessMan777
Copy link

@mayur-raval please give me help bud with php checkout will pay

@tdujmic
Copy link

tdujmic commented Jun 9, 2016

Great work. Thanks. Awsome Idea to put datas in input tag

@tdujmic
Copy link

tdujmic commented Jun 9, 2016

@BusinessMan777 just change extension of this html to .php and try with this it works for me:

'; if(count($_POST) > 0){ var_dump($_POST); if (isset($_POST['stripeToken'])) { # code... $token = $_POST['stripeToken']; \Stripe\Stripe::setApiKey("YOUR sk KEY"); $charge = \Stripe\Charge::create(array( "amount" => 999, // amount in cents, again "currency" => "usd", "source" => $token, "description" => "Subscription Payment" )); } } ?>

That must be before form

and include form in this php code:

/// Form code here
//// Set form action=""

Put this file on your local apache wamp or other server and enjoy

@dkrzysik
Copy link

Do you know how to receive the user's shipping info that they enter from the form?

screenshot_1
screenshot_2
screenshot_3
screenshot_4
screenshot_5

@avrumy
Copy link

avrumy commented Aug 9, 2016

can you make the payment amount custom

@dolson334
Copy link

Can you add a piece for the callback after the submit I want to parse on the result of the charge.

@jshwvr
Copy link

jshwvr commented Sep 15, 2016

Sorry for the ignorant question, but could someone help walk me through what I need to do to actually send the payment through to the stripe dashboard? The code works amazingly and I was finally able to use my existing button style to pull up the stripe checkout form... everything goes well until I submit the payment, then it doesn't end up in the stripe dashboard. I can see it in the logs in stripe, but that's the end of it.

@buckhornmktg
Copy link

@carlos94587
Copy link

carlos94587 commented Apr 20, 2017

any thoughts how can apply the script in a Webflow site? I added the basic piece of code but need to add a style to the button to match the site.

@minakshi-sharma
Copy link

I added stripe checkout button on my page but after entering the payment details it goes to a page that says not found. How can we set this or add thank you page after successful payment? below is my page url.
https://nathanaaron.lpages.co/the-act-of-forgiveness/

@chackett
Copy link

Is this solution PCI compliant?

Thanks

@yannsonnboys
Copy link

Thank a lot Ziadoz

@mehdico
Copy link

mehdico commented Apr 26, 2020

Is using checkout.js deprecated?

@riturmichatterjee
Copy link

how to redirect to thank you button after payment success?

Copy link

ghost commented Nov 19, 2022

Helpfull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment