
Stripe payment gateway integration
Just only $50. lifetime licence. No extra charges. No hidden cost.
Stripe payment gateway integration
Just only $50. lifetime licence. No extra charges. No hidden cost.
whmcs-stripe-php
Stripe checkout is the easiest payment flow on web and mobile.
Click “Remember me” to securely store your credit card info for faster checkout on this and other sites that use Stripe.
On this computer, when you come back to any participating site, your credit card info will already be filled in: just click Payto confirm your purchase.
You can edit the card number if you need to. Stripe will store the one you used most recently.
Your credit card is linked to your email address and your mobile phone number.
To pay with Stripe on a different computer, or after you log out, just enter your email address during checkout and Stripe will instantly send you a text message to verify your identity.
Message and data rates may apply. Frequency of messages depends on user. For help, reply back with HELP. To stop, reply back with STOP.
Stripe checkout plugin is very easy to install with your existing WHMCS plugin.
Price : € 10 only
Drop a comment below, if you are interested for demo.
whmcs-stripe-php
Do you want to accept credit cards on your website and save users confusion and time? This credit card gateway extension for WHMCS lets you accept credit card payments directly on your website via Stripe payment gateway.
With this extension your customer can use their credit cards during the checkout process and Stripe.com handles the rest. This means a smoother experience for your users as they never have to leave your website for making payments.
This is a free and open source Stripe Payment Gateway for WHMCS that supports one time and recurring payments without ever having a credit card number hit your WHMCS server.
Stripe pay payment gateway allows the WHMCS billing system to use Stripe’s one time and reoccurring payment gateway capabilities. Stripe provides the unique ability to take a client’s credit card information without ever having the client leave your site, but it also allows for credit card data to never get stored in or even pass through your own server, eliminating costly concerns over PCI compliance. This gateway for WHMCS is being released free for anyone, although it should still be considered in beta as there are likely still bugs to work out of it.
You can sign up for a Stripe account at https://stripe.com.
stripe.php
and place it into the /modules/gateways/
folder of your WHMCS installation.callback
folder of the repository, copy the other stripe.php
file and place it into the /modules/gateways/callback
folder of your WHMCS installation.ccpay.php
file from the repository into the root directory of your WHMCS installation.clientareacreditcard-stripe.tpl
file into the root level of the theme folder you are currently using for WHMCS. For example, if you’re using the default
theme, then copy this file to /templates/default/
.https://yourwhmcsinstall.com/modules/gateways/callback/stripe.php
.In the end, your folder structure should look roughly like the diagram below, with a ccpay.php file in the root of your install, a stripe.php in /modules/gateways/callback
, a stripe.php in /modules/gateways/
, a clientareacreditcard-stripe.tpl
in the root of your WHMCS active template folder, and the lib
folder of the Stripe API in the newly-created /modules/gateways/stripe/
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
whmcs |-- ccpay.php |-- modules |-- gateways |-- callbacks |-- stripe.php |-- stripe (contains the lib folder of the Stripe PHP API) |-- Stripe |-- ... (files from Stripe API) |-- data |-- ... (files from Stripe API) |-- Stripe.php (Stripe API core file) |-- stripe.php |-- templates |-- yourtemplatename (i.e. default) |-- clientareacreditcard-stripe.tpl |
You may now activate this new payment gateway from within WHMCS through the Setup > Payments > Payment Gateways screen. This module should be listed as Stripe. You can then fill in the appropriate API key information as well as a required email address where the gateway can send you any serious errors that come up while billing clients or communicating with Stripe.
To download source code Click here !!!
Fork on Github
I’m always looking to improve this code, so if you see something that can be changed or if you have an idea for a new feature or any other feedback, send me an email to sagasdeshmukh91@gmail.com
, or send me a message on Twitter (@starsagar91
), and I’ll get right back to you. If you decide to use this module in your WHMCS install, send me a message to say hello (and let me know what you think too) and it’ll make my day. Thanks!
Stripe error handling
Stripe API libraries raise exceptions for many reasons, such as a failed charge, invalid parameters, authentication errors, and network unavailability. The Stripe recommends for writing code that gracefully handles all possible API exceptions.
Below Error Handling code is compatible with latest stripe API version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php ... try { // Use Stripe's library to make requests... } catch(\Stripe\Error\Card $e) { // Since it's a decline, \Stripe\Error\Card will be caught $body = $e->getJsonBody(); $err = $body['error']; print('Status is:' . $e->getHttpStatus() . "\n"); print('Type is:' . $err['type'] . "\n"); print('Code is:' . $err['code'] . "\n"); // param is '' in this case print('Param is:' . $err['param'] . "\n"); print('Message is:' . $err['message'] . "\n"); } catch (\Stripe\Error\RateLimit $e) { // Too many requests made to the API too quickly } catch (\Stripe\Error\InvalidRequest $e) { // Invalid parameters were supplied to Stripe's API } catch (\Stripe\Error\Authentication $e) { // Authentication with Stripe's API failed // (maybe you changed API keys recently) } catch (\Stripe\Error\ApiConnection $e) { // Network communication with Stripe failed } catch (\Stripe\Error\Base $e) { // Display a very generic error to the user, and maybe send // yourself an email } catch (Exception $e) { // Something else happened, completely unrelated to Stripe } ... ?> |
For old stripe versions i.e Stripe API v1.18.0 use below Error Handling code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php ... try { // Use Stripe's library to make requests... } catch(Stripe_CardError $e) { // Since it's a decline, \Stripe\Error\Card will be caught print('Message is:' . $e->getMessage() . "\n"); } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API } catch (Stripe_AuthenticationError $e) { // Authentication with Stripe's API failed // (maybe you changed API keys recently) } catch (Stripe_ApiConnectionError $e) { // Network communication with Stripe failed } catch (Stripe_Error $e) { // Display a very generic error to the user, and maybe send // yourself an email } catch (Exception $e) { // Something else happened, completely unrelated to Stripe } ... ?> |
For more details please check .
Stripe payment gateway integration
Stripe payment gateway offers 2 ways of integration in PHP –
Strip checkout integration:
The easiest way to integrate Stripe is via Checkout, an embedded tool that takes care of building an HTML form, validating user input, and securing your customers’ card data. Using Checkout, sensitive credit card information is sent directly to Stripe, and does not touch your server. Stripe returns to your site a token representation of the card, and this token can then be used in a charge request.
Embedding Checkout in your site
To get started, add the following code to your payment page:
1 2 3 4 5 6 7 8 9 10 11 12 |
<form action="/your-charge-code" method="POST"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh" data-amount="999" data-name="ILovePHP.net" data-description="Donation" data-image="http://www.ilovephp.net/wp-content/uploads/2016/03/small-3.jpg" data-locale="auto" data-zip-code="true"> </script> </form> |
Reference link : https://stripe.com/docs/checkout/tutorial
Stripe custom integration (Stripe.js):
For a more custom approach, you can instead use Stripe with your own payment form via Stripe.js.
Processing payments with Custom Stripe integration has two components:
Below code example show you demonstrate you the custom stripe integration with stripe.js.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
<?php // Stripe library require 'stripe/Stripe.php'; $params = array( "testmode" => "on", "private_live_key" => "sk_live_xxxxxxxxxxxxxxxxxxxxx", "public_live_key" => "pk_live_xxxxxxxxxxxxxxxxxxxxx", "private_test_key" => "sk_test_xxxxxxxxxxxxxxxxxxxxx", "public_test_key" => "pk_test_xxxxxxxxxxxxxxxxxxxxx" ); if ($params['testmode'] == "on") { Stripe::setApiKey($params['private_test_key']); $pubkey = $params['public_test_key']; } else { Stripe::setApiKey($params['private_live_key']); $pubkey = $params['public_live_key']; } if(isset($_POST['stripeToken'])) { $amount_cents = str_replace(".","","10.52"); // Chargeble amount $invoiceid = "14526321"; // Invoice ID $description = "Invoice #" . $invoiceid . " - " . $invoiceid; try { $charge = Stripe_Charge::create(array( "amount" => $amount_cents, "currency" => "usd", "source" => $_POST['stripeToken'], "description" => $description) ); if ($charge->card->address_zip_check == "fail") { throw new Exception("zip_check_invalid"); } else if ($charge->card->address_line1_check == "fail") { throw new Exception("address_check_invalid"); } else if ($charge->card->cvc_check == "fail") { throw new Exception("cvc_check_invalid"); } // Payment has succeeded, no exceptions were thrown or otherwise caught $result = "success"; } catch(Stripe_CardError $e) { $error = $e->getMessage(); $result = "declined"; } catch (Stripe_InvalidRequestError $e) { $result = "declined"; } catch (Stripe_AuthenticationError $e) { $result = "declined"; } catch (Stripe_ApiConnectionError $e) { $result = "declined"; } catch (Stripe_Error $e) { $result = "declined"; } catch (Exception $e) { if ($e->getMessage() == "zip_check_invalid") { $result = "declined"; } else if ($e->getMessage() == "address_check_invalid") { $result = "declined"; } else if ($e->getMessage() == "cvc_check_invalid") { $result = "declined"; } else { $result = "declined"; } } echo "<BR>Stripe Payment Status : ".$result; echo "<BR>Stripe Response : "; print_r($charge); exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Stripe Pay Custom Integration Demo</title> </head> <body> <link href="style.css" type="text/css" rel="stylesheet" /> <h1 class="bt_title">Stripe Pay Demo</h1> <div class="dropin-page"> <form action="" method="POST" id="payment-form"> <span class="payment-errors"></span> <div class="form-row"> <label> <span>Card Number</span> <input type="text" size="20" data-stripe="number"> </label> </div> <div class="form-row"> <label> <span>Expiration (MM/YY)</span> <input type="text" size="2" data-stripe="exp_month"> </label> <span> / </span> <input type="text" size="2" data-stripe="exp_year"> </div> <div class="form-row"> <label> <span>CVC</span> <input type="text" size="4" data-stripe="cvc"> </label> </div> <input type="submit" class="submit" value="Submit Payment"> </form> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript" src="https://js.stripe.com/v2/"></script> <!-- TO DO : Place below JS code in js file and include that JS file --> <script type="text/javascript"> Stripe.setPublishableKey('<?php echo $params['public_test_key']; ?>'); $(function() { var $form = $('#payment-form'); $form.submit(function(event) { // Disable the submit button to prevent repeated clicks: $form.find('.submit').prop('disabled', true); // Request a token from Stripe: Stripe.card.createToken($form, stripeResponseHandler); // Prevent the form from being submitted: return false; }); }); function stripeResponseHandler(status, response) { // Grab the form: var $form = $('#payment-form'); if (response.error) { // Problem! // Show the errors on the form: $form.find('.payment-errors').text(response.error.message); $form.find('.submit').prop('disabled', false); // Re-enable submission } else { // Token was created! // Get the token ID: var token = response.id; // Insert the token ID into the form so it gets submitted to the server: $form.append($('<input type="hidden" name="stripeToken">').val(token)); // Submit the form: $form.get(0).submit(); } }; </script> </body> </html> |
You can download all above demos from below link :
Download Source Code
Or
Browse source code in github : https://github.com/sagarsdeshmukh/Stripe_gateway_integration_demo_with_PHP
If you have any additional questions Or queries, don’t hesitate to let me know!, Just put comment below or contact @ my mail id sagarsdeshmukh@gmail.com
Hope you enjoy my post 🙂