/ Published in: PHP
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
// for live
// $url = "https://www.paypal.com/cgi-bin/webscr";
// for sandbox
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
?>
<form name="paypal_ipn" action="<?php echo $url ?>" method="POST">
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="cmd" value="_cart" />
<!-- The business email address, where you want to receive the payment -->
<input type="hidden" name="business" value="[email protected]" />
<!-- The customer email address -->
<input type="hidden" name="receiver_email" value="[email protected]" />
<input type="hidden" name="item_name_1" value="test product" />
<input type="hidden" name="quantity_1" value="1" />
<input type="hidden" name="amount_1" value="25.58" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="invoice" value="12345" />
<input type="hidden" name="amount" value="25.58" />
<!-- Where you want to return after PayPal Payment -->
<input type="hidden" name="return" value="http://www.yoursite.com/finished.php" />
<!-- A back-end notification send to the specific page after successful payment -->
<input type="hidden" name="notify_url" value="https://www.yoursite.com/finished_secure.php" />
<!-- Where you want to return after cancel the PayPal Payment -->
<input type="hidden" name="cancel_return" value="http://www.yoursite.com" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" border=0 />
</form>
============================ Start finished_secure.php file ===============================
<?php
$req = 'cmd=_notify-validate';
foreach($_POST as $key => $value) {
$req .= "&$key=$value";
}
$header .= "POST /cgi-bin/webscr HTTP/1.0
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
";
//$url = "ssl://www.paypal.com"; // for live
$url = "ssl://www.sandbox.paypal.com"; // for sandbox
$paypal_payment_amount = $_POST['mc_gross'];
//print_r($_POST); To print all the variables get form PayPal
if(!$fp){
echo "PayPal socket not opened.";
}
else{
// write any code to here
}
// error
}
} // end while
}
?>
============================== End finished_secure.php file =================================
URL: http://www.phpmoot.com/php-paypal-ipn-payment-gateway/
Comments
 Subscribe to comments
                    Subscribe to comments
                
                