How to Integrate Paypal as Payment System in Website using PHP

As we all know that PayPal is the biggest Online Payment Solution available these days. Many websites need to accept payments from their customers/users for providing services or selling products. This can be done very easily by integrating PayPal as a payment gateway in a website. Today we are going to see how to integrate PayPal as payment gateway in any web page using PHP.

Integrate Paypal as Payment System in Website using PHP & MYSQL


Now we are going to setup PayPal for receiving payments on our website using a simple Buy Now Button. We are going to it with demo accounts available for developers by PayPal. After everything will be successfully completed and working we will replace demo account with real PayPal account.

Step 1:

Create PayPal sandbox account using this link:

Sign up for a Developer account on PayPal

Step 2:

Go to Applications Tab and go to Sandbox accounts. Create one business and one personal account.

Here you can see, I have created one Personal (Buyer) & Business (Merchant/Seller) account.

PayPal Developer account

Step 3:

Check below example for creating personal account.

PayPal personal sandbox account creation

PHP Code:


This file contains PHP code which displays product name, product image, product price & payment button. Clicking the Payment button will send user to PayPal website for payment. You can modify product information. You can modify the URLs where user will be redirected if payment is successful or cancelled. Check input field <input name=”cancel_return” & <input name=”return”.



This File contains PayPal Payment API URL. Currently for testing purpose we are using PayPal Sandbox API URL. Please enter merchant/seller account email at $merchant_email.


It payment is successful, user will be redirected to this page along with product payment data. The data received from PayPal can be stored in database and records can be maintained.


User will be redirected to cancelled.php if payment is not processed. You can change this URL in example.php.

 last step:

If you have successfully integrated everything using PayPal Sandbox Account. Its time to change the Sandbox API  to real PayPal API.

Just comment the above $payment_url line and uncomment below $payment_url line and insert your real PayPal Merchant ID.

Hope you like it.

3 Replies to “How to Integrate Paypal as Payment System in Website using PHP”

  1. Anonymous says:


  2. Alyda says:

    Actually, it isn’t working at all. Several errors.

  3. Thabo says:

    Hi Umar,

    I would like to know how I could make a payment list: e.g like ticketing systems. If a person wants to buy two products of the same price.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top