Warning to developers: I just received a “Dispute” via stripe for a $1.23 payment and the dispute came with a $25 fee (that appears to be non refundable). If you setup stripe to make payments don’t do it for small payments as dispute/ refunds will send you in the red big time.
Just about every business wants to add ultra secure credit card payments to their website. http://www.stripe.com allows you to do that with a bit of coding.
The live processing has been removed (due to automated bulk credit card checking by someone).
Simple Payment Button
The live processing has been removed (due to automated bulk credit card checking by someone).
Here is the code for the page above, you would need to do a bit more to make save the purchase and handle errors but this demo is showing the minimum code required.
// make_payment.php
<h1>Donate $5.00 to Fearby.com (Real Transaction)</h1> <form action="process_payment.php" method="POST"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="PRIVATE_KEY_REMOVED_PUT_YOURS_HERE" data-amount="500" data-name="Fearby.com" data-description="Thank You for your Donation ($1.23)" data-image="128x128.png"> </script> </form>
// process_payment.php
<?php require_once('init.php'); \Stripe\Stripe::setApiKey("SECRET_KEY_REMOVED_ADD_YOURS_HERE"); $token = $_POST['stripeToken']; try { $charge = \Stripe\Charge::create(array( "amount" => 500, // amount in cents, again "currency" => "aud", "source" => $token, "description" => "Simon Test Web Donation..") ); echo "Payment Processed, Thank You<br />"; } catch(\Stripe\Error\Card $e) { // The card has been declined echo "The card has been declined"; } echo "Done<br />"; ?>
Simple Theme-less form.
Here is a basic form that can be styled into any webpage with other details (e.g “renew membership”, “pay for a course”, “buy item” etc).
Make A Dummy Credit Card Payment ($1.23 AUD)
https://link.removed.due.to.bulk.cc.checking/test/stripe/give_payment_test.php
– Test Credit Card Number: 4242 4242 4242 4242
– Exp: 01/17
– CVN 123
Make a real Credit Card Payment ($1.23 AUD)
The live processing has been removed (due to automated bulk credit card checking by someone).
Use a real credit card details.
https://link.removed.due.to.bulk.cc.checking/test/stripe/give_payment_test.php
Here is the single page source code for the page above.
// give_payment_real.php <?php require(dirname(__FILE__) . '/init.php'); $error = ""; $success = ""; if ($_POST) { \Stripe\Stripe::setApiKey("SECERT_KEY_REMOVED_ADD_YOURS_HERE"); $error = ''; $success = ''; try { if (!isset($_POST['stripeToken'])) throw new Exception("The Stripe Token was not generated correctly"); echo "ready to charge.<br />"; $charge = \Stripe\Charge::create(array( "amount" => 123, // amount in cents, again "currency" => "aud", "source" => $_POST['stripeToken'], "description" => "Simon test web charge") ); echo "charge done<br />"; if ($charge->status == 'succeeded') { $success = 'Your payment was sucessful.'; echo "$success"; } else { $success = 'Your payment failed.'; echo "$success"; } } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; echo 'Status is:' . $e->getHttpStatus() . "\n"; echo 'Type is:' . $err['type'] . "\n"; echo 'Code is:' . $err['code'] . "\n"; echo 'Param is:' . $err['param'] . "\n"; echo 'Message is:' . $err['message'] . "\n"; } catch (Exception $e) { echo $e->getMessage(); } catch (ErrorException $e) { echo $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/v2/"></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('PRIVATE_KEY_REMOVED_ADD_YOURS_HERE'); 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"); 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>Donate $1.23 to Fearby.com</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>
Bank Account Statements
You can stamp your transactions with payment/product descriptions.
Now to make your forms look nice.
Luckily wmhilton on http://www.bootsnipp.com has kindly created a Credit Card Payment with Stripe code pack that is compatible with the awesome bootstrap code.
More Information
Check out http://www.stripe.com for more information.
Stripe allows you to setup schedules, save or not save customer details, retry declined payments and fully integrate the payment process into other systems.
fyi: I use a dedicated Ubuntu server on Digital Ocean. You can easily deploy an SSD cloud server in 55 seconds for $5 a month. Sign up using my link and receive $10 in credit: https://www.digitalocean.com/?refcode=99a5082b6de5
If you need a secure domain with SSL check out these recent articles
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]