Stripe Payment GateWay is payment suite provided by stripe. An Irish company founded by John and Patrick Collison in 2010. It provides businesse to accept electronic payments. Integration process in Checkout method is quite easy and secure.

In Checkout method, sensitive credit card information does not sent to stripe via your server. So, You do not need to take care about PCI compliance.

Stripe Payment Gateway Integration

Stripe payment gateway offers 2 methods of integration in PHP:

1) Stripe checkout integration
2) Stripe custom integration (Stripe.js)



Stripe Checkout Integration Using PHP and JavaScript

Stripe checkout supports modern browser including Google Chrome, Firefox, Safari, Internet Explorer 9 and above versions. It also increase your server’s security by sending credit card data directly to stripe server.

In this tutorial we will learn to integrate the custom stripe integration with stripe.js. Below code example demonstrate the stripe integration with stripe.js

 Demo Download

Directory Structure

index.php

The first step is to build a HTML form for your product and embed stripe script using JavaScript <script> tag.

 

Insert above code where you want to add Payment Button in the web page. Now, Open page in browser you will see Payment button where you embedded the stripe script. The stripe checkout script will automatically creates the HTML form for the payment. It also validates the user input and generates unique token for the payment.

Stripe Payment Button Sgeek

 

Configuration Options

Parameter Description
data-description: It holds the description of product
data-name: Holds product name
data-key: The key provided by stripe for transaction
data-amount: Amount of payment. By Default The amount will be in cents.
data-locale: Holds Language code in which checkout will display. Set auto to show in the user’s preffered language. English will be used by default.
data-zip-code (true or false): Specify whether payment should validate the billing ZIP code.
data-billing-address (true or false): Set true to collect user’s billing address.
data-image: Image or Logo show in payment popup. It supports gif, jpeg and png files only.
Set a URL in form’s action, where you want to redirect the page having transaction details once transaction completes.



 

Optional Config

Parameter Description
data-currency: The currency of the amount. Three digit currency ISP code, Eg USD. See List of currencies which stripe supports
data-panel-label: Label of payment button in Checkout Form.
data-shipping-address(true or false): Set true to collect user’s shipping address.
data-email: You can prefill email of user if you have already user’s email address.
data-label: Label of payment button.
data-allow-remember-me(true or false): Specify whether to include the option to “Remember Me” or not. The default is true.
Output

Stripe Checkout Form Sgeek

In By clicking on the button, Payment Popup will show having Payment inputs such as Email Address, Card Number, Expiry Date, CVV and Remember me option. By clicking on Payment button Checkout sends all details to stripe server directly. After validating checkout details stripe submits form and returns token or error message if the checkout fails to the URL you have mentioned in form action.

 

Success Response

stripeToken will be used to charge the card in later part.

 

Response Parameters

Parameter Description
stripeToken: Token Id of the payment details
stripeEmail: Email Address Of user entered during checkout
stripeBillingName: Billing address details if enabled
stripeShippingName: Shipping address details if enabled
Charge User’s Card

Once Checkout process completes and collects checkout details, Last step is to charge the card. It will use Stripe Library to charge user’s card.



First of All, install Stripe Library if you have not installed yet. To install library, Add stripe/stripe-php in composer.json and update the composer by running composer update command. Read more about Composer

payment.php

Now add create stripe object and charge user’s card by using Create method.

The $charge immediately receive the response of the request in JSON format. If the charge attempt succeed, The card have been charged successfully and amount will be sent as per stripe’s policy. In case of error, stripe returns specific error code with error message. Here is list of error codes along with error message.

That’s it. Stripe Payments has been integrated into a web page.

 

We will discuss how to Save credit card details for later in next Tutorial. Comment or Tweet if you have any queries related to stripe integration.

Read More:
Payumoney Payment Gateway Integration In PHP
How To Setup PayPal Account
Introduction To PayPal Adaptive Payments
Introduction To Adyen Payment Platform
sfiletypechecker-JQuery Plugin Validate Input File

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">