Paypal Payment using PHP

0

In this tutorial I want to explain how to work with Paypal Sandbox test accounts for payment system development and sending arguments while click buy now button. It’s simple and very easy to integrate in your web projects.

Create a Paypal Sandbox test account at https://developer.paypal.com/

payment.php

<?PHP
    $paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
    
//	$paypalUrl='https://www.paypal.com/cgi-bin/webscr'; Live Paypal API URL

    $paypal_id='Business email ID';  // Business email ID
?>

<div class="product">            
    <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="Script gurus 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="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://localhost/paypal/cancel.php">
            <input type="hidden" name="return" value="http://localhost/paypal/success.php">  
            <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit">
            <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
        </form> 
    </div>
</div>

success.php

$no            = $_REQUEST['item_number'];
$transaction   = $_REQUEST['tx']; // Paypal transaction ID

$price         = $_REQUEST['amt']; // Paypal received amount

$currency      = $_REQUEST['cc']; // Paypal received currency type

cancel.php

<?php
    echo "Payment Failed";
?>