Want to integrate Paypal Payment Gateway in PHP in a very simple manner? First of all, In order to receive PayPal payments, you must have a PayPal account and registered with a valid email id. If you don't have PayPal account, you should register in it. This is the first step of it.
First Step :-
https://developer.paypal.com/ Create a PayPal Sandbox account.
Second Step :-
Further, you need to create test ccounts for payment system. Here, take a look at Sandbox menu left-side top Sandbox > Test Accounts
Third Step :-
Check out below, There are two accounts, one for Buyer and another for Seller.
index.php :-
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
$paypal_id='your_seller_id'; // Business email ID
?>
<h4>Welcome, Guest</h4>
<div class="product">
<div class="image">
<img src="http://freewebmentor.com/wp-content/uploads/2014/01/logo.png" />
</div>
<div class="name">
Paypal Payment System
</div>
<div class="price">
Price:$10
</div>
<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="freewebmentor 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="10">
<input type="hidden" name="cpp_header_image" value="http://freewebmentor.com/wp-content/uploads/2014/01/logo.png">
<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://freewebmentor.com/paypal-payment/cancel.php">
<input type="hidden" name="return" value="http://freewebmentor.com/paypal-payment/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>
Payment-success.php :-
You will be redirected to the payment-success.php page after completing the Payment process succesfully. You will get a success message here.
<?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>";
}
?>
cancel.php :-
<?php
echo "<h1>Welcome, Guest</h1>";
echo "<h1>Payment Canceled</h1>";
?>
First Step :-
https://developer.paypal.com/ Create a PayPal Sandbox account.
Second Step :-
Further, you need to create test ccounts for payment system. Here, take a look at Sandbox menu left-side top Sandbox > Test Accounts
Third Step :-
Check out below, There are two accounts, one for Buyer and another for Seller.
index.php :-
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
$paypal_id='your_seller_id'; // Business email ID
?>
<h4>Welcome, Guest</h4>
<div class="product">
<div class="image">
<img src="http://freewebmentor.com/wp-content/uploads/2014/01/logo.png" />
</div>
<div class="name">
Paypal Payment System
</div>
<div class="price">
Price:$10
</div>
<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="freewebmentor 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="10">
<input type="hidden" name="cpp_header_image" value="http://freewebmentor.com/wp-content/uploads/2014/01/logo.png">
<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://freewebmentor.com/paypal-payment/cancel.php">
<input type="hidden" name="return" value="http://freewebmentor.com/paypal-payment/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>
Payment-success.php :-
You will be redirected to the payment-success.php page after completing the Payment process succesfully. You will get a success message here.
<?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>";
}
?>
cancel.php :-
<?php
echo "<h1>Welcome, Guest</h1>";
echo "<h1>Payment Canceled</h1>";
?>
0 comments:
Post a Comment