Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Integrate Paypal Payment System Using PHP And MySQL

Tuesday, Mar 7, 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="">
  <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">

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.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH