Payment Gateways / PHP · February 15, 2017 1

Integrating stripe using stripe.js and stripe-php library

Stripe is getting popular as a payment processor because of its simplicity and PCI compliance.

To meet with PCI standards your website shouldn’t send or store any credit card information to any where other than stripe, so to send credit card information directly to stripe we use stripejs.

How it works

Stripe.js collects credit card and customer information from our form and sends it to stripe, if all information is correct then strip will issue back a token.
We can send that token to our webserver for charging actual amount using stripe-php library.
So in above case instead of sending credit card information to our server we are sending a token.

Stripe token
Stripe.js sending credit card information to stripe and getting token back

Token is generate so now we are going to send that token to our webserver instead of sending credit card info.

 

Charge request
Sending token to your webserver and calling stripe-php api to make a charge

In our charge.php it receives token from from and calls stripe charge api using stripe-php libaray. After charge is created stripe will send response back to charge.php.
If charge was successful we can save transaction information to our database otherwise show an error to customer.

Here is a working code on github