Location: PHPKode > scripts > PHPBB Donation MOD with Paypal IPN > install_PayPal_IPN_Donation_MOD-v1.0.4.6/root/lwdonateresult.php
<?php
/***************************************************************************
*				lwdonateresult.php
*
*	begin				: 14/SEP/2004
*	copyright			: Zou Xiong - Loewen Exchange
*	email				: hide@address.com
*
*	version				: 1.0.3 - 30/DEC/2006
*
*  @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
***************************************************************************/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
//include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);


require_once($phpbb_root_path . 'includes/lw_donate_functions_V3.'.$phpEx);
require_once($phpbb_root_path . 'includes/lw_donate_paypal_functions.'.$phpEx);

//$unhtml_specialchars_match = array('#&gt;#', '#&lt;#', '#&quot;#', '#&amp;#');
//$unhtml_specialchars_replace = array('>', '<', '"', '&');

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

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

//while (list($key, $value) = each($HTTP_POST_VARS)) {
//$value = urlencode(stripslashes($value));
//$req .= "&$key=$value";
//}

// post back to PayPal system to validate
$header = '';
$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);

// assign posted variables to local variables
//$item_name = htmlspecialchars($HTTP_POST_VARS['item_name']);
//$item_number = htmlspecialchars($HTTP_POST_VARS['item_number']);
//$payment_status = htmlspecialchars($HTTP_POST_VARS['payment_status']);
//$payment_amount = htmlspecialchars($HTTP_POST_VARS['mc_gross']);
//$payment_currency = htmlspecialchars($HTTP_POST_VARS['mc_currency']);
//$txn_id = htmlspecialchars($HTTP_POST_VARS['txn_id']);
//$receiver_email = htmlspecialchars($HTTP_POST_VARS['receiver_email']);
//$payer_email = htmlspecialchars($HTTP_POST_VARS['payer_email']);
$item_name = request_var('item_name', '');
$item_number = request_var('item_number', '');
$payment_status = request_var('payment_status', '');
$payment_amount = request_var('mc_gross', '');
$payment_currency = request_var('mc_currency', '');
$txn_id = request_var('txn_id', '');
$receiver_email = request_var('receiver_email', '');
$payer_email = request_var('payer_email', '');


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
			// check that txn_id has not been previously processed
			// check that receiver_email is your Primary PayPal email
			// check that payment_amount/payment_currency are correct
			// process payment

			/* Input is passed as array so that later it can be easily extended.
			* Example of inut array
			* input_array = array(
			*     'ITEM_NUMBER' 	=> 'the_item_number',
			*     'SYSTEM_ACCOUNT_1'  => 'system_receiver_account 1',
			*     'SYSTEM_ACCOUNT_2'  => 'system_receiver_account 2',
			* 	  //PAYMENT_STATUS Supported: Reversed, Refunded, Completed, or unknown status
			*     'PAYMENT_STATUS' 	=> 'payment_status',
			*     'RECEIVER_ACCT'	=> 'receiver_paypal_account',
			*     'PAYER_ACCT'		=> 'payer_paypal_account',
			* 	  'MC_CURRENCY'		=> 'receive_cash_currency',
			*     'TXN_ID'			=> 'paypal_transaction_id',
			*     'MC_GROSS' 		=> 'amount_received',
			*     'GATEWAY_TYPE' 	=> 'gateway_type',
			* );
			*/
			$PayPal_Data = array(
			     'ITEM_NUMBER' 		=> trim($item_number),
			     'SYSTEM_ACCOUNT_1'    		=> trim($config['paypal_p_acct']),
			     'SYSTEM_ACCOUNT_2'    		=> trim($config['paypal_b_acct']),
				 'PAYMENT_STATUS' 	=> trim($payment_status),
			     'RECEIVER_ACCT'	=> trim($receiver_email),
			     'PAYER_ACCT'		=> trim($payer_email),
			 	 'MC_CURRENCY'		=> lw_DM_paypal_convert_currency_type_V3(trim($payment_currency)),
			     'TXN_ID'			=> trim($txn_id),
			     'MC_GROSS' 		=> ($payment_amount + 0.00),
			);

			lw_DM_process_payment_V3($PayPal_Data);			
		}
		else if (strcmp ($res, "INVALID") == 0) 
		{
			//do nothing
		}
	}
	fclose ($fp);
}

die("Process End");

?>
Return current item: PHPBB Donation MOD with Paypal IPN