An e-commerce website is not considered to be complete without the payment gateway linked to it. There are various payment gateways and you can select from, but most famous and renowned online payment gateway is known to be PayPal. This is an American Platform which has been also around for about two decades. As an initial level, it was also known as Confinity, though after the year 2001 it was known as PayPal.
PHP is known to be the common platforms for the e-commerce websites. PHP is known to be secure, fast as well as much trusted language when it is about the industry of banking and financial. Now various websites of e-commerce also run on PHP platform.
Mentioned Below are some of the functions that we can perform in process of demonstration for integrating PayPal in PHP.
- The button of PayPal buy pulls the products from database and from webpage.
- When a buyer will click on the button of PayPal, the buyer will redirects to page of PayPal, where the payment gets processed.
- Here, buyer will be redirected to webpage subsequent to payment done at the PayPal; the details of payment will be accessible on webpage.
Moreover, PayPal has the sandbox atmosphere for testing the functionalities prior to that it gets live by the developer. In such a way a software developer will be able to iron out any of the issues even before the business begins accepting the payments from other customer. The developer may also simply get access to sandbox through signing up for the sandbox account at PayPal.
Mentioned below is a step-by-step guide, now let us learn about tips of integrating the PayPal payment gateway in the PHP.
Step 1: Create Sandbox Accounts
Below mentioned are some the steps through which you can open a PayPal sandbox account
- The initial most thing that you need it having the PayPal account. In case you don’t have a PayPal account, you need to sign up for free. In case you already have an account on PayPal, you need to head to PayPal developer page and then simply sign in.
- After this, you need to click on Dashboard; that is quite much visible on top side of the navigation.
- Then click on accounts which are available under sandbox label.
- You will also see that there is buyer account that is created by default; it is created through the email-buyer.
- You also need to make a merchant account by choosing the account type and the country name and after that click on the button create account.
Step 2: Create Tables for Database
You require two tables that can store the product along with the payment information in database. The mentioned SQL quires make the product along with the payment tables in database of MySQL.
Step 3: Setting of PayPal and configuration of Data (config.php)
Consent variables related to gateway of PayPal are mainly defined in file of config.php.
Step 4: Connect the Database through dbConnect.php
Step 5: List the Products in the Index file (index.php)
- The products get pulled from database and they are listed on webpage
- The PayPal buy the button that gets placed at side of every product
- For accessing the payment gateway at PayPal, you should submit a form of HTML with the predefined variables of PayPal.
Step 6: Make the payment Successful (success.php)
When you make the payment and it gets successful, you need to take the below mentioned steps.
- Subsequent to the payment being successful at PayPal, buyer gets redirected to the page
- With the help of PHP$_Get method, you can retrieve the transaction data from URL
- The complete information and details about payment get saved in database and it is mainly based on transaction id
- You can find the payment details on webpage
Step 7: Cancelation of Payment (cancel.php)
If the buyer wants to cancel the payment done at PayPal, they need to get redirected at the payment cancelation page.
Step 8: Setup of the Payment Transfer and PayPal Auto-Return
It is mainly required to get complete details of the transaction back through PayPal; in case this is not available, you will be able to get the requisite details at just few clicks.
All you need to do is follow the below mentioned steps
- Log in to the Business PayPal account
- Click on profile that is available on the TAB” my account”
- Click on hosted payment services and choose the link of website payments preferences
- Choose the radio button and click on “Auto Return,” and then enter and redirect the URL in given field
- Now, click on button that says “Payment data transfer.”
- Finally Click on Save
Step 9: Setup of the IPN
Suck kind of setup is needed to make payment more secure. The initial most thing that you need to do is adding below code to HTML with variables of PayPal.
You need to now log into the Paypal Business account and follow below mentioned steps:
- Click on button gear icon to reach the settings
- Move to selling tools and then click on the notification of instant payment.
- After this click on IPIN settings page
- After this, enter notification URL and allow getting the IPN messages
- Now click on save button
Step 10: Set up the trxn and Validate Transaction
Once your IPN gets enabled, PayPal will help to send some instant notifications of transaction. Add below mentioned code to ipn.php that helps to validate transaction and save details of payment in the database.
It is really simple to integrate the Payment Gateway in PayPal By following such steps, you must be able to simply integrate the payment gateway of PayPal with PHP successfully. In case you face any of the issues, you may feel free to visit PayPal and check if you have a solution available there. Or if required you may also hire the PHP developer who also has an experience to integrate the PayPal with PHP.
- Top PHP interview questions and answers 2020 - July 7, 2020
- How to create a Whatsapp account using the Australian number? - June 28, 2020
- Top C++ interview questions And answers 2020 - June 19, 2020