Want To Be A Blogger  →  Start A Blog  →  Increase Traffic  →  Make Money Online  →  Recommended Things

Integrate Paypal Payment System Using PHP And MySQL

Friday, Dec 15, 2017

Tags:- PHP MySQL

Payment system is must have for those website who have something to sell on their website and integrate payment system in your website makes the whole process so easy.So, in this tutorial we will show you how to integrate paypal payment system using PHP and MySQL.You have to create account on Paypal Developer

Integrate Payment Payment System Using PHP And MySQL

To Create Paypal Payment System It Takes Only two Steps:-

  1. Make a PHP file and define markup and scripting
  2. Make a PHP file to store transaction

Step 1.Make a PHP file and define markup and scripting

We make a PHP file and save it with a name payment.php

$paypal_id='your_seller_id'; // Business email ID


<div class="product_div">
 <p class="image"><img src="product1.jpg"/></p>
 <p class="name">Sample Product 1</p>
 <p class="price">Price:$10</p>
 <div class="paypal_button">
  <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="Sample Product 1">
  <input type="hidden" name="item_number" value="1">
  <input type="hidden" name="credits" value="300">
  <input type="hidden" name="userid" value="1">
  <input type="hidden" name="amount" value="10">
  <input type="hidden" name="cpp_header_image" value="http://sample_site.com/images/product1.jpg">
  <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="http://sample_site.com/cancel.php">
  <input type="hidden" name="return" value="http://sample_site.com/success.php">
  <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

In this step we create a sample product for selling and insert paypal button then insert all the required fields in paypal payment form.In this form there are two main fields one is 'return' and another is 'cancel_return'.'return' is the url where paypal send data like transaction id after payment done successfully then in 'cancel_return' we give cancel payment url to cancel payment.

Step 2.Make a PHP file to store transaction

We make a PHP file and save it with a name success.php

// Database Structure 
CREATE TABLE `payment_transaction` (
 `transaction_id` text NOT NULL,
 `amount` int(11) NOT NULL,
 `currency_type` text NOT NULL,
 `item_number` int(11) NOT NULL,



 $item_transaction = $_GET['tx'];
 $item_price = $_GET['amt']; 
 $item_currency = $_GET['cc'];
 $item_no = $_GET['item_number'];
 mysql_query("insert into payment_transaction values('','$item_transaction','$item_price','$item_currency','$item_no')");
 echo "Payment Done Successfully";

In this step we first create a sample table to store transaction detail after every successful payment done.This kind of url 'success.php?tx=734HJ28JKDF32&st=Completed&amt=10.00&cc=USD&cm=&item_number=1' is return after completion of payment successfully.Then we get all the values and store them in our database.

Thats all, this is how to integrate paypal payment system using PHP and MySQL.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Subscribe Our Newsletter And Get Tutorials And Offers Via Email

About Me

Hello, My Name is Mudit Jain. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of TalkersCode. I started this blog in february 2015 to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers.