How to Integrate Paypal Payment System in PHP & MySQL
Php 16-Jul-2019

How to Integrate Paypal Payment System in PHP & MySQL

In this tutorial I want to explain how to work with Paypal Sandbox test accounts for payment system development and sending arguments while click buy now button. It’s simple and very easy to integrate in your web projects.

Step 1

Create a Paypal Sandbox account at

Step 2

Now create test accounts for payment system. Take a look at Sandbox menu left-side top Sandbox->Test Accounts


Step 3

Here I have created two accounts Buyer (personal) and Seller (merchant/business)



Contains PHP code. Displaying productsproduct imageproduct name and product price. Here you have to give your business(seller) $paypal_id id. Modify paypal button form return and cancel_return URLs.

$paypal_url=''; // Test Paypal API URL
$paypal_id='your_seller_id'; // Business email ID
<h4>Welcome, Guest</h4>

<div class="product">            
    <div class="image">
        <img src="" />
    <div class="name">
        PHPGang Payment
    <div class="price">
    <div class="btn">
    <form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
    <input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="item_name" value="PHPGang Payment">
    <input type="hidden" name="item_number" value="1">
    <input type="hidden" name="credits" value="510">
    <input type="hidden" name="userid" value="1">
    <input type="hidden" name="amount" value="10">
    <input type="hidden" name="cpp_header_image" value="">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="handling" value="0">
    <input type="hidden" name="cancel_return" value="">
    <input type="hidden" name="return" value="">
    <input type="image" src="" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="" width="1" height="1">


Paypal payment success return file. Getting Paypal argument like item_number. Paypal data success.php?tx=83437E384950D&st=Completed&amt=10.00&cc=USD&cm=&item_number=1

$item_no            = $_REQUEST['item_number'];
$item_transaction   = $_REQUEST['tx']; // Paypal transaction ID
$item_price         = $_REQUEST['amt']; // Paypal received amount
$item_currency      = $_REQUEST['cc']; // Paypal received currency type

$price = '10.00';

//Rechecking the product price and currency details
if($item_price==$price && $item_currency==$currency)
    echo "<h1>Welcome, Guest</h1>";
    echo "<h1>Payment Successful</h1>";
    echo "<h1>Payment Failed</h1>";



Paypal API cancel_return file.

echo "<h1>Welcome, Guest</h1>";
echo "<h1>Payment Canceled</h1>";


Step 4

When your web application test payment system workflow is completed. Change the form action development API URLs to original API URLs and give valid $paypal_idseller email id.