PayPal integration in PHP
Just follow some step and PayPal integration is ready to use.
You need one test account for test this method. If you have
already test account so use it. Otherwise create new from www.developer.paypal.com and
signup. After complete your PayPal test account follow this code for your PayPal
integration.
1.
Create Form for send payment
Paypal.php
<?phpinclude "../wp-config.php";
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
$paypal_id='your paypal account'; // Business email ID
?>
<div class="product">
<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="FSBO-PRO">
<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="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://www.yoursite.com/cancel.php">
<input type="hidden" name="return" value="http://www.yoursite.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>
2.Success.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 = '10.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>";
}
3.Cancle.php
<?php
echo "<h1>Welcome, Guest</h1>";
echo "<h1>Payment Canceled</h1>";
?>
4.
Finally last step create database
CREATE TABLE `payments` (
`id` int(6) NOT NULL
AUTO_INCREMENT,
`txnid` varchar(20)
NOT NULL,
`payment_amount`
decimal(7,2) NOT NULL,
`payment_status`
varchar(25) NOT NULL,
`itemid` varchar(25)
NOT NULL,
`createdtime`
datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Hey your PayPal
integration is complete.
After successful tested some changes need for put it in your web site.
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr';
//to
$paypal_url='https://www.paypal.com/cgi-bin/webscr';
After successful tested some changes need for put it in your web site.
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr';
//to
$paypal_url='https://www.paypal.com/cgi-bin/webscr';
and you completely integrate paypal in your web site.
Enjoy it……………
Comments
Post a Comment