Table of Contents
Today we are going to integrate paypal payment gateway with core PHP,Mysql . Payment gateway are third party that handle payment transaction between customer and merchants .They have lots of parameter like customer name, email ,product name, model no, total cost, country code etc .
We will integrate in our previous tutorial of core PHP shopping cart project .So if you have not setup it ,do visit this tutorial and follow all steps or if you have your own project ,it's ok .
After successful integration ,Remove query string '?sandbox=1' from form action on order_review.php file and put actual merchant email id in paypal.php file . if you have any query feel free to write below ,I will try to reply soon . Do check our advance PHP training syllabus
Step 1 : Payment gateway information in hidden form field
We have our final page in e-commerce project i.e order_review.php .So , open this file in your favourite PHP editor and put below code to the bottom of the page
There above we are passing some parameters ,We should have an array i.e $checkout that contains value in key like name,email etc . Check below how our complete order_review.php page looks like
Step 2 : create paypal.php handler
in above we have a form action i.e paypal.php . Find below this file
In above file 1st line it's calling database config file , then on 2 lines we have declared paypal merchant'e email id and notification email id. The first email should be registered with paypal as a merchant account to accept payment from website . Currently we are in testing mode (sandbox account) ,so we can put anything here .
After it handle Paypal payment process .While on this step it insert the form data in database table 'purchases' and process to the paypal . Step 3 : create database table to store purchase records
in step 2 we discussed regarding a database table i.e 'purchases' .So , let's create it , execute below code to sql on your phpmyadmin for your database .
Step 4 : create paypal_class.php to validate the paid result with Paypal IPN
Now create a file 'paypal_class.php' and put below code in it .This file provides clean and simple method to validate the paid result with Paypal IPN
Now open order_review.php on your browser ex: https://localhost/my_php/order_review.php .Click button 'Pay now using Paypal' .It redirect to next page .Check there if all required parameter value are passing correctly . After 5 sec it redirect to paypal.com .Do check if all product name ,model and total cost are correct . well, this is paypal sandbox ,means paypal provide for developer for test integration on this mode. After successful integration ,Remove query string '?sandbox=1' from form action on order_review.php file and put actual merchant email id in paypal.php file . if you have any query feel free to write below ,I will try to reply soon . Do check our advance PHP training syllabus