.

.

Integrate Paypal Payment System in PHP & MySQL

Step 1
Create a Paypal Sandbox account at https://developer.paypal.com/
Step 2
Now create test accounts for payment system. Take a look at Sandbox menu left-side topSandbox->Test Accounts
create a file where we use 
index.php
<?php
// Test Paypal API URL
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr';
 // Business email ID
$paypal_id='your_seller_id';
?><h4>Welcome, Guest</h4> 
<div class="product"> <div class="name"> Test Payment </div>
 <div class="price"> Price:$15 </div>  
 <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="Test 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="15"> 
 <input type="hidden" name="cpp_header_image" value="your logo path or any image">
 <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="cancel.php"> 
 <input type="hidden" name="return" value="success.php">
 <input type="image" src="paypalimage urlor button image" border="0" name="submit" 
alt="PayPal"> </form> 
 </div></div>

success.php
Paypal payment success return file. Getting Paypal argument like item_number. Paypaldatasuccess.php?tx=83437E384950D&st=Completed&amt=10.00&cc=USD&cm=&item_number=1
<?php
$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 = '15.00';
$currency='USD';
//Rechecking the product price and currency details
if($item_price==$price && $item_currency==$currency)
{
    echo "<h1>Welcome, Guest</h1>";
    echo "<h1>Payment Successful</h1>";
}
else
{
    echo "<h1>Payment Failed</h1>";
}
?>

cancel.php

Paypal API cancel_return file.
<?php
echo "<h1>Welcome, Guest</h1>";
echo "<h1>Payment Canceled</h1>";
?>


 Step 3

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_id seller email id.
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr';
//to
$paypal_url='https://www.paypal.com/cgi-bin/webscr';


EmoticonEmoticon