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
To Create Paypal Payment System It Takes Only two Steps:-
- Make a PHP file and define markup and scripting
- 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
<?php $paypal_url='https://www.paypal.com/cgi-bin/webscr'; $paypal_id='your_seller_id'; // Business email ID ?> <html> <body> <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"> </form> </div> </div> </body> </html>
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` ( `id` int(11) NOT NULL AUTO_INCREMENT, `transaction_id` text NOT NULL, `amount` int(11) NOT NULL, `currency_type` text NOT NULL, `item_number` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 <?php $host="localhost"; $username="root"; $password=""; $databasename="sample"; $connect=mysql_connect($host,$username,$password); $db=mysql_select_db($databasename); if($_GET['st']=="Completed") { $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.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery