| <?php | |
| require 'path-to-Stripe.php'; | |
| if ($_POST) { | |
| Stripe::setApiKey("YOUR-API-KEY"); | |
| $error = ''; | |
| $success = ''; | |
| try { | |
| if (!isset($_POST['stripeToken'])) | |
| throw new Exception("The Stripe Token was not generated correctly"); | |
| Stripe_Charge::create(array("amount" => 1000, | |
| "currency" => "usd", | |
| "card" => $_POST['stripeToken'])); | |
| $success = 'Your payment was successful.'; | |
| } | |
| catch (Exception $e) { | |
| $error = $e->getMessage(); | |
| } | |
| } | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
| <title>Stripe Getting Started Form</title> | |
| <script type="text/javascript" src="https://js.stripe.com/v1/"></script> | |
| <!-- jQuery is used only for this example; it isn't required to use Stripe --> | |
| <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
| <script type="text/javascript"> | |
| // this identifies your website in the createToken call below | |
| Stripe.setPublishableKey('YOUR-PUBLISHABLE-API-KEY'); | |
| function stripeResponseHandler(status, response) { | |
| if (response.error) { | |
| // re-enable the submit button | |
| $('.submit-button').removeAttr("disabled"); | |
| // show the errors on the form | |
| $(".payment-errors").html(response.error.message); | |
| } else { | |
| var form$ = $("#payment-form"); | |
| // token contains id, last4, and card type | |
| var token = response['id']; | |
| // insert the token into the form so it gets submitted to the server | |
| form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />"); | |
| // and submit | |
| form$.get(0).submit(); | |
| } | |
| } | |
| $(document).ready(function() { | |
| $("#payment-form").submit(function(event) { | |
| // disable the submit button to prevent repeated clicks | |
| $('.submit-button').attr("disabled", "disabled"); | |
| // createToken returns immediately - the supplied callback submits the form if there are no errors | |
| Stripe.createToken({ | |
| number: $('.card-number').val(), | |
| cvc: $('.card-cvc').val(), | |
| exp_month: $('.card-expiry-month').val(), | |
| exp_year: $('.card-expiry-year').val() | |
| }, stripeResponseHandler); | |
| return false; // submit from callback | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <h1>Charge $10 with Stripe</h1> | |
| <!-- to display errors returned by createToken --> | |
| <span class="payment-errors"><?= $error ?></span> | |
| <span class="payment-success"><?= $success ?></span> | |
| <form action="" method="POST" id="payment-form"> | |
| <div class="form-row"> | |
| <label>Card Number</label> | |
| <input type="text" size="20" autocomplete="off" class="card-number" /> | |
| </div> | |
| <div class="form-row"> | |
| <label>CVC</label> | |
| <input type="text" size="4" autocomplete="off" class="card-cvc" /> | |
| </div> | |
| <div class="form-row"> | |
| <label>Expiration (MM/YYYY)</label> | |
| <input type="text" size="2" class="card-expiry-month"/> | |
| <span> / </span> | |
| <input type="text" size="4" class="card-expiry-year"/> | |
| </div> | |
| <button type="submit" class="submit-button">Submit Payment</button> | |
| </form> | |
| </body> | |
| </html> |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joshholat
commented
Feb 9, 2012
|
The point of using Stripe.js is so that credit card information never really leaves the client side except in the form of a token, correct? If so, shouldn't you also remove the credit card fields from the form submission when you add the token field on line 46? Or am I missing something? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boucher
Feb 9, 2012
Because those fields do not contain a "name" attribute, they will not be included in the data the form POSTs to your server.
|
Because those fields do not contain a "name" attribute, they will not be included in the data the form POSTs to your server. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ianwalter
Mar 24, 2012
On line 5 of this example you call Stripe directly to set the API key:
Stripe::setApiKey("YOUR-API-KEY");
But when I downloaded the SDK Stripe is an abstract class.
ianwalter
commented
Mar 24, 2012
|
On line 5 of this example you call Stripe directly to set the API key: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ratfactor
Mar 26, 2012
Ian - it's okay to call a static method on an abstract class in PHP. I'm guessing that the Stripe class has been declared abstract only to keep it from being instantiated. Someone please correct me if I'm wrong.
ratfactor
commented
Mar 26, 2012
|
Ian - it's okay to call a static method on an abstract class in PHP. I'm guessing that the Stripe class has been declared abstract only to keep it from being instantiated. Someone please correct me if I'm wrong. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ianwalter
Mar 27, 2012
Right, sorry, the autoloader within my CodeIgniter installation was trying to instantiate it. Thank you.
ianwalter
commented
Mar 27, 2012
|
Right, sorry, the autoloader within my CodeIgniter installation was trying to instantiate it. Thank you. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
MoeedParacha
Sep 6, 2012
Is there any example that takes full credentials from the user i.e. address,amount e.t.c
MoeedParacha
commented
Sep 6, 2012
|
Is there any example that takes full credentials from the user i.e. address,amount e.t.c |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rakeshr
commented
Nov 30, 2012
|
How do I create customer with this code? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
shahzad1234
Aug 22, 2013
you will create customer and this customer can save in your database if you want and in stripe.com customer as well.
$customer = Stripe_Customer::create(array(
"card" => $token,
"description" => "description")
);
shahzad1234
commented
Aug 22, 2013
|
you will create customer and this customer can save in your database if you want and in stripe.com customer as well. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
shahzad1234
Aug 22, 2013
I believe token is just use one time, and each time we need credit card information to make payment and create token?
is there is any way , that we will not take credit card information every time from user and make payment through token?
shahzad1234
commented
Aug 22, 2013
|
I believe token is just use one time, and each time we need credit card information to make payment and create token? is there is any way , that we will not take credit card information every time from user and make payment through token? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rajkram
Aug 25, 2013
there is no need to take the credit card from user every time..the token is not one time and can be re-used. check this one. I'll do too as I'm planning to use it
rajkram
commented
Aug 25, 2013
|
there is no need to take the credit card from user every time..the token is not one time and can be re-used. check this one. I'll do too as I'm planning to use it |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
abnermagahud
Aug 31, 2013
Hi! When i put the require 'stripe/lib/Stripe.php'; the page is empty. What is the problem?
abnermagahud
commented
Aug 31, 2013
|
Hi! When i put the require 'stripe/lib/Stripe.php'; the page is empty. What is the problem? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
AnandPhadnis123
Sep 24, 2013
I want to use stripe with Canada country. Is their is any testing bank account we can create in stripe by accepting some details like account number and routing number. How can we can transfer money in Canadian bank through stripe. Please give me test details
AnandPhadnis123
commented
Sep 24, 2013
|
I want to use stripe with Canada country. Is their is any testing bank account we can create in stripe by accepting some details like account number and routing number. How can we can transfer money in Canadian bank through stripe. Please give me test details |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
EMCP
Nov 26, 2013
AnandPhadnis , I suggest you lookup the latest details at Stripe.com . http://lmgtfy.com/?q=using+stripe+in+canada
EMCP
commented
Nov 26, 2013
|
AnandPhadnis , I suggest you lookup the latest details at Stripe.com . http://lmgtfy.com/?q=using+stripe+in+canada |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Carlitta87
commented
Dec 10, 2013
|
I tried this but the dashboard didn't respond. Is there a next step? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vignesh2014
commented
Feb 5, 2014
|
What is "path-to-Stripe.php"? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
drdan18
Feb 11, 2014
@vignesh2014 the "path-to-Stripe.php" is referring to the Stripe.php file that is required. You can store it anywhere so just change the "path-to-" portion to the place you have it stored.
It will look something like this:
require_once('./lib/Stripe.php');
drdan18
commented
Feb 11, 2014
|
@vignesh2014 the "path-to-Stripe.php" is referring to the Stripe.php file that is required. You can store it anywhere so just change the "path-to-" portion to the place you have it stored. It will look something like this: require_once('./lib/Stripe.php'); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Cam
Feb 22, 2014
This is wonderful. Thanks! Any clues as to how to redirect the page to another upon success? Using form variables didn't work for me.
Cam
commented
Feb 22, 2014
|
This is wonderful. Thanks! Any clues as to how to redirect the page to another upon success? Using form variables didn't work for me. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
danngyw
Mar 8, 2014
I'm a newbie. Please help me how to check in case the transaction is false(no money,card is test demo).
Thanks so much!
danngyw
commented
Mar 8, 2014
|
I'm a newbie. Please help me how to check in case the transaction is false(no money,card is test demo). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
hussaintamboli
commented
Mar 12, 2014
|
I'm a newbie. Where do I get the 'path-to-Stripe.php' file from? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
hussaintamboli
commented
Mar 12, 2014
|
I just found it here https://github.com/stripe/stripe-php |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pogeybait4883
Apr 1, 2014
To redirect to a new page on success, firstly make sure you are processing the response in PHP at the top of the page just like in this example and when you get a success response just use this line of code
header("Location: http://www.google.com");
change the google.com above to the whatever you want. If you write any html to the page first, even a simple tag, it wont redirect. That's why you have to do it at the top of the page in php before you write any html tags.
pogeybait4883
commented
Apr 1, 2014
|
To redirect to a new page on success, firstly make sure you are processing the response in PHP at the top of the page just like in this example and when you get a success response just use this line of code header("Location: http://www.google.com"); change the google.com above to the whatever you want. If you write any html to the page first, even a simple tag, it wont redirect. That's why you have to do it at the top of the page in php before you write any html tags. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
fabiobasile
Jun 5, 2014
How do i specify submit buttons names into Stripe post? I tried and it just renders the form catatonic.
I am generating a stripe form from form A, which pre-fills the Stripe form B with data using POST. Because of this, form B complains that every index in form B is undefined and throws the token error before even submitting payment.
fabiobasile
commented
Jun 5, 2014
|
How do i specify submit buttons names into Stripe post? I tried and it just renders the form catatonic. I am generating a stripe form from form A, which pre-fills the Stripe form B with data using POST. Because of this, form B complains that every index in form B is undefined and throws the token error before even submitting payment. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marcis
commented
Jun 26, 2014
|
What about the form's language? Can't it be set? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ghost
commented
Dec 30, 2014
|
What do I need to change if I were to charge a customer rather than a card? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
otuatail
Jan 23, 2015
Strugling with this. 1st it has a default amount of £10 assuming it is in pence. There should be an input field for the amount.
2nd require 'path-to-Stripe.php'; is this a joke. or do we have to research the path.
What is needed I think is a separate php form and a php only to keep the code separate pref behind a .htaccess folder. That way we can put up a thank you form or an error form.
otuatail
commented
Jan 23, 2015
|
Strugling with this. 1st it has a default amount of £10 assuming it is in pence. There should be an input field for the amount. What is needed I think is a separate php form and a php only to keep the code separate pref behind a .htaccess folder. That way we can put up a thank you form or an error form. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ghost
Jan 26, 2015
otuatail you could put the amount into a hidden field no problem then replace it on the server-side using the POST variable. Remember to validate it before submission
Secondly, the script can't be published with the path to Stripe as it depends where you put it. If your document root is /var/www/html/ then you may want to put it in /var/www/html/Stripe/
To split up the form as you suggest (which is the better way of doing it), copy the first 20 lines of code, place them in a new file wherever you would like it and then submit the form to that file. At the end of the file add header('Location: index.php'); remembering to use your own path
This is fairly basic PHP coding, so general tutorials should help a lot. If you need any more help let me know
Dan
ghost
commented
Jan 26, 2015
|
otuatail you could put the amount into a hidden field no problem then replace it on the server-side using the POST variable. Remember to validate it before submission Secondly, the script can't be published with the path to Stripe as it depends where you put it. If your document root is /var/www/html/ then you may want to put it in /var/www/html/Stripe/ To split up the form as you suggest (which is the better way of doing it), copy the first 20 lines of code, place them in a new file wherever you would like it and then submit the form to that file. At the end of the file add header('Location: index.php'); remembering to use your own path This is fairly basic PHP coding, so general tutorials should help a lot. If you need any more help let me know Dan |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
LinuxPhreak
Apr 14, 2015
Would I just added "plan" => "myplanname" if I wanted to make it a subscription form?
if ($_POST) {
Stripe::setApiKey("YOUR-API-KEY");
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
Stripe_Charge::create(array("amount" => 1000,
"currency" => "usd",
"plan" => "myplanname",
"card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
}
catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
LinuxPhreak
commented
Apr 14, 2015
|
Would I just added "plan" => "myplanname" if I wanted to make it a subscription form?
if ($_POST) {
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bedio
commented
Apr 23, 2015
|
hi how can i integrate stipe to symfony project |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
MaanikSingh
Jun 10, 2015
I'm a very beginner to this and coding in general, but i dont understand how you can execute php and html in the same file, what am i missing?
MaanikSingh
commented
Jun 10, 2015
|
I'm a very beginner to this and coding in general, but i dont understand how you can execute php and html in the same file, what am i missing? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bateller
Jun 17, 2015
Just FYI if you are using Stripe's new Stripe-PHP found here:
https://github.com/stripe/stripe-php
Here is this updated Gist with the correct format for the new Stripe API:
https://gist.github.com/bateller/154c6e5d1f6e0e53e527
bateller
commented
Jun 17, 2015
|
Just FYI if you are using Stripe's new Stripe-PHP found here: Here is this updated Gist with the correct format for the new Stripe API: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
amitambekar
Sep 28, 2015
Class 'Stripe' not found in E:\xampp\htdocs\projects\Amit\try\stripe\stripe-php-2.1.4\gistfile1.php on line 4
error coming what should i do ??
amitambekar
commented
Sep 28, 2015
|
Class 'Stripe' not found in E:\xampp\htdocs\projects\Amit\try\stripe\stripe-php-2.1.4\gistfile1.php on line 4 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vishusharma1
Mar 17, 2016
is it possible to integrate stripe gateway with the .Net if it is then please let me know the code if anyone knows
vishusharma1
commented
Mar 17, 2016
|
is it possible to integrate stripe gateway with the .Net if it is then please let me know the code if anyone knows |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
deemi
Mar 23, 2016
Can any one tell me please, where is the input field of price .... and can i convert this into radio button
deemi
commented
Mar 23, 2016
|
Can any one tell me please, where is the input field of price .... and can i convert this into radio button |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
SamAsEnd
Mar 24, 2016
@deemi DON'T USE A PRICE FIELD ON YOUR FORM PLEASE!
Stripe_Charge::create(array("amount" => 1000,
"currency" => "usd",
"card" => $_POST['stripeToken']));the "amount" key is for the price and fetch that from the db of some where safe!
SamAsEnd
commented
Mar 24, 2016
|
@deemi DON'T USE A PRICE FIELD ON YOUR FORM PLEASE! Stripe_Charge::create(array("amount" => 1000,
"currency" => "usd",
"card" => $_POST['stripeToken']));the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
LuceroGera
May 31, 2016
Hello my friend,
I was looking your example and I want to look functional but I can't because I don't know what do you have in this file (path-to-Stripe.php)?
Can you help me please?
Thanks,
Lucero
LuceroGera
commented
May 31, 2016
|
Hello my friend, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
garimaagarwal111
commented
Nov 17, 2016
|
line number 72 73 says undefined index |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vikas2804
Dec 8, 2016
Hi,
Can anyone tell me how can i add more fields(name, city, address1 etc.) and save in stripe while creating new user?
Please
vikas2804
commented
Dec 8, 2016
|
Hi, Can anyone tell me how can i add more fields(name, city, address1 etc.) and save in stripe while creating new user? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
big89
Dec 28, 2016
If anyone wants integrate stripe payment gateway api, you can contact me. Thanks !!!
big89
commented
Dec 28, 2016
|
If anyone wants integrate stripe payment gateway api, you can contact me. Thanks !!! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdc-cunningham
Dec 10, 2017
Just a note for anyone regarding the stripe.php path
Apparently you just require the init.php from the main folder (extracted) for non-composer install
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR.'stripe-php-5.7.0/init.php');
Found from here:
https://stackoverflow.com/questions/28846062/stripe-php-fatal-error-class-stripe-charge-not-found
jdc-cunningham
commented
Dec 10, 2017
•
|
Just a note for anyone regarding the Apparently you just require the init.php from the main folder (extracted) for non-composer install
Found from here: https://stackoverflow.com/questions/28846062/stripe-php-fatal-error-class-stripe-charge-not-found |
The point of using Stripe.js is so that credit card information never really leaves the client side except in the form of a token, correct? If so, shouldn't you also remove the credit card fields from the form submission when you add the token field on line 46? Or am I missing something?