コード例 #1
0
<?php

/*
 * A basic script which will verify IPN via the sandbox server.
 * If an error occurs inside of processIpn() we will catch it
 * and output full text report.
 *
 * Note that 'echo' commands are just for demonstration purposes.
 * In reality, your script is going to be called by PayPal server and you
 * will not actually see the output unless you log it somewhere on your server.
 */
include dirname(dirname(__FILE__)) . '/src/IpnListener.php';
use dezlov\PayPal\IpnListener;
$listener = new IpnListener();
$listener->use_sandbox = true;
try {
    $verified = $listener->processIpn();
    if ($verified) {
        echo 'IPN request was "VERIFIED".' . PHP_EOL;
    } else {
        echo 'IPN request was "INVALID".' . PHP_EOL;
    }
} catch (Exception $e) {
    echo 'IPN error: ' . $e->getMessage() . PHP_EOL;
    echo $listener->getTextReport();
}
コード例 #2
0
<?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&notify_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();
コード例 #3
0
<?php

/*
 * Advanced example which demonstrates the complete processing chain of IPN,
 * including validation of IPN, verification of transaction details,
 * order fulfilment and error logging.
 *
 * This example follows the recommended practices of IPN integration from PayPal:
 * https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/
 *
 * 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)) {
コード例 #4
0
ファイル: ipn_log.php プロジェクト: dezlov/PHP-PayPal-IPN
<?php

/*
 * This script verifies and logs to a file all received IPN requests.
 * You can use it with PayPal IPN Simulator, just upload it to your server
 * and specify its path as IPN handler URL:
 * https://developer.paypal.com/developer/ipnSimulator/
 *
 * Make sure that your web server has write access to the folder with this script,
 * otherwise you won't see any logs being created.
 */
include dirname(dirname(__FILE__)) . '/src/IpnListener.php';
use dezlov\PayPal\IpnListener;
$listener = new IpnListener();
$listener->use_sandbox = true;
$error = null;
$verified = $listener->tryProcessIpn(null, $error);
$report = $listener->getTextReport();
ipn_log($verified, $report, $error);
function ipn_log($verified, $report, $error)
{
    if ($verified) {
        $filename = 'ipn_verified.log';
        $content = $report;
    } else {
        $filename = 'ipn_errors.log';
        $content = 'ERROR: ' . $error . PHP_EOL . $report;
    }
    file_put_contents($filename, $content, FILE_APPEND | LOCK_EX);
}
コード例 #5
0
ファイル: ipn_basic.php プロジェクト: dezlov/PHP-PayPal-IPN
<?php

/*
 * A basic script which will verify IPN via the sandbox server.
 * Uses an alternative tryProcessIpn() method which will not throw exceptions
 * but instead will return an error in the $error variable if an error occurs.
 * 
 * Note that 'echo' commands are just for demonstration purposes.
 * In reality, your script is going to be called by PayPal server and you
 * will not actually see the output unless you log it somewhere on your server.
 */
include dirname(dirname(__FILE__)) . '/src/IpnListener.php';
use dezlov\PayPal\IpnListener;
$listener = new IpnListener();
$listener->use_sandbox = true;
$error = null;
$verified = $listener->tryProcessIpn(null, $error);
if ($verified) {
    echo 'IPN verified successfully.' . PHP_EOL;
} else {
    echo 'IPN error: ' . $error . PHP_EOL;
}