function process_orders() { global $db; $slt_trade_order_a = "SELECT * FROM trade_order WHERE active = 'yes' AND finished = 'no' ORDER BY filing_time DESC"; $rlt_trade_order_a = mysql_query($slt_trade_order_a); while ($row_trade_order_a = mysql_fetch_assoc($rlt_trade_order_a)) { process_order($row_trade_order_a["id"]); } }
$receiver_email = $listener->getData('receiver_email'); if (!check_receiver_email($receiver_email)) { throw new Exception('Unable to process IPN for receiver email: ' . $receiver_email); } // Check price and currency $payment_total = $listener->getData('mc_gross'); $payment_currency = $listener->getData('mc_currency'); if (!check_price($payment_total, $payment_currency)) { throw new Exception('Unable to process IPN due to issues with price/currency'); } // If we got this far, then its ok to fulfil the order $item_name = $listener->getData('item_name'); $item_number = $listener->getData('item_number'); $payer_name = trim($listener->getData('first_name') . ' ' . $listener->getData('last_name')); $payer_email = $listener->getData('payer_email'); process_order($transaction_id, $item_name, $item_number, $payer_name, $payer_email); // Tell PayPal that we have successfully processing IPN. header('HTTP/1.1 200 OK'); } catch (Exception $e) { // Tell PayPal that we had problems processing IPN. header('HTTP/1.1 500 Internal Server Error'); // Report error message. $message = 'IPN error: ' . (string) $e; $message .= PHP_EOL . PHP_EOL . $listener->getTextReport(); report_problem($message); } function process_order($transaction_id, $item_name, $item_number, $payer_name, $payer_email) { // For example: Fulfil the order, save details in the database. } function check_price($total, $currency)
<?php $fh = fopen('orders.txt', 'r') or die($php_errormsg); while (!feof($fh)) { $s = fgets($fh, 256); process_order($s); } fclose($fh) or die($php_errormsg);
if (strcmp($res, "VERIFIED") == 0) { // check whether the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your PayPal email // check that payment_amount/payment_currency are correct // process payment and mark item as paid. // assign posted variables to local variables //$item_name = $_POST['item_name']; //$item_number = $_POST['item_number']; //$payment_status = $_POST['payment_status']; //$payment_amount = $_POST['mc_gross']; //$payment_currency = $_POST['mc_currency']; //$txn_id = $_POST['txn_id']; //$receiver_email = $_POST['receiver_email']; //$payer_email = $_POST['payer_email']; process_order($_POST); if (DEBUG == true) { error_log(date('[Y-m-d H:i e] ') . "Verified IPN: {$req} " . PHP_EOL, 3, LOG_FILE); } } else { if (strcmp($res, "INVALID") == 0) { // log for manual investigation // Add business logic here which deals with invalid IPN messages if (DEBUG == true) { error_log(date('[Y-m-d H:i e] ') . "Invalid IPN: {$req}" . PHP_EOL, 3, LOG_FILE); } } } function process_order($data) { // Do stuff like log to database, email admin.