Paypal Payment Gateway Reviewed by Momizat on . Get business email from https://www.paypal.com HTML Form Page [php] <form method="post" action="https://www.paypal.com/cgi-bin/webscr" Get business email from https://www.paypal.com HTML Form Page [php] <form method="post" action="https://www.paypal.com/cgi-bin/webscr" Rating: 0

Paypal Payment Gateway

Get business email from https://www.paypal.com

HTML Form Page

<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="invoice" value="<?php echo mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); ?>" />
<input type="hidden" name="bn" value="sitename.com" />
<input type="hidden" name="business" value="XXXXXXXXX" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="return" value="sitename.com/success.php" />
<input type="hidden" name="cancel_return" value="sitename.com/cancel.php" />
<input type="hidden" name="item_name" value="Name" />
<input type="hidden" name="item_number" value="2342" />
<input name="amount" type="hidden" id="amount" value="1" />
<input type="hidden" name="notify_url" value="sitename.com/notify.php" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="currency_code" value="USD" />
<input name="submit" type="submit" value="Pay Now"/>
</form>

After form submition
paypal

notify.php Page

<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

$cart_id = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$invoice = $_POST['invoice'];
if (!$fp) {
// HTTP ERROR
} else {
	fputs ($fp, $header . $req);
	while (!feof($fp)) {
	$res = fgets ($fp, 1024);
	if (strcmp ($res, "VERIFIED") == 0) {
		// check the payment_status is Completed

		if (strtolower($_POST['payment_status']) == "completed")
		{
			// Coding Satement or database query operations
			// for duplicate transaction check $txn_id from tbl
		
		}
		
	}
	else if (strcmp ($res, "INVALID") == 0) {
	// log for manual investigation
			echo "Invalid";
		}
	}
fclose ($fp);
}

?>

Leave a Comment

© 2014 Powered By