<?php /* * An example script for testing pre-made IPN requests locally. * * Because we manually provide the data that is normally sent by PayPal, * we can run this script from command line or open it in a web browser * and see the output. */ include dirname(dirname(__FILE__)) . '/src/IpnListener.php'; use dezlov\PayPal\IpnListener; $listener = new IpnListener(); $listener->use_sandbox = true; // Example IPN request data, we expect PayPal to tell us that it is "INVALID". $example_request_data = 'mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00'; // Verify IPN request trhough PayPal $error = null; $verified = $listener->tryProcessIpn($example_request_data, $error); if ($verified) { echo 'IPN verified successfully.' . PHP_EOL; } else { echo 'IPN error: ' . $error . PHP_EOL; } // Print out debug information print_r($listener->getData()); echo $listener->getTextReport();
* * Dummy functions at the bottom of the script give examples of how to actually * handle various parts of the process. */ include dirname(dirname(__FILE__)) . '/src/IpnListener.php'; use dezlov\PayPal\IpnListener; $listener = new IpnListener(); $listener->use_sandbox = true; try { // Process IPN request $verified = $listener->processIpn(); if (!$verified) { throw new Exception('Invalid IPN request'); } // Skip all notifications except for completed payments $payment_status = $listener->getData('payment_status'); if ($payment_status != 'Completed') { exit; } // Check transaction ID $transaction_id = $listener->getData('txn_id'); if (!check_transaction($transaction_id)) { throw new Exception('Unable to process IPN for transaction ID: ' . $transaction_id); } // Check receiver email $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');