PayPal payment gateway integration in PHP

PayPal is an American international e-commerce business allowing payments and money transfers to be made through the Internet. PayPal is very popular payment gateway for every web project. This tutorial will explain about PayPal payment gateway integration in PHP. With this tutorial you can easily integrate the payment option in your web project. At first we will receive payment from the buyers and then store the transaction information at the database.

PayPal has two environments such as Sandbox and Real Time. Sandbox environment help developers to do their test transaction before the project go live. Real Time environment is used after project live.

PayPal payment gateway integration
PayPal payment gateway integration

Step 1 ( Creating a new Sandbox test account )

At first we need to create a new Sandbox test account. Following steps would be help to create Sandbox account.

  • Step 1 – Go to the Log in with your PayPal account. If you don’t have any PayPal account, first sign up at PayPal. Once the sign up is completed, login with this account.
  • Step 2 – After logged in you would be redirected to the developer home page. Now click on the “Dashboard” link from the top navigation menu.
  • Step 3 – Click on the “Accounts” link under the “Sandbox” label from the left menu section.
  • Step 4 – Create buyer account and merchant account from the “Create Account” link. For buyer account you need to select “Personal” radio button under the “Account type” section or select Business radio button for merchant account.

Step 2 ( Database Tables Creation )

We have created two tables named products and payments. products data is stored into the products table and payments table is used for storing the transaction information provided by PayPal.

Step 3 ( db_config.php File )

Step 4 ( products.php File )

Step 5 ( success.php File )

Once the PayPal payment is successful, buyer would be redirected to this page. We have received the transaction information with $_GET variable and insert transaction data into the database. If the payment is successful, then buyer would be see the success message otherwise failed message.

Step 6 ( cancel.php File )

If the buyers wish to cancel payment at the PayPal payment page, then buyer would be redirected to this page.

That is all you need to setup the paypal standard into your php website.