Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter vs IPN
#1

[eluser]benjamin[/eluser]
Hi All,

I'm using PayPal's IPN, and whilst I'm aware that there is a CI library for it, I'm trying to understand something, and was hoping whether somebody could help me shed some light into this. If I use the CI library, requests are being sent and received (all OK). Now if I'm being playful, and simply create a controller (let's call it "paypal_ipn"), and re-direct my IPN to xyz/index.php/paypal_ipn/listener, then suddenyl paypal can no longer send any messages...However if I call the same URL from my browser, everything works fine (i.e. no syntax errors etc)...I guess there is a fundamental CI principle that I don't understand / missed? Thanks in advance.

Controller:

Code:
<?php

class PayPal_IPN extends CI_Controller {


    /**
     * Constructor.
     *
     * @since 1.0
     */
    function __construct() {
        parent::__construct();
    }

    /**
     * The IPN listener. Processes IPN events.
     *
     * @since 1.0
     */
    function listener() {
        // 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('ssl://www.paypal.com', 443, $errno, $errstr, 30);

        // 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'];

        if (!$fp) {
            // HTTP ERROR

        } else {
            fputs($fp, $header . $req);
            while (!feof($fp)) {
                $res = fgets($fp, 1024);
                if (strcmp($res, "VERIFIED") == 0) {
                    // confirm and process order...foo bar
                } else if (strcmp($res, "INVALID") == 0) {
                    // log for manual investigation
        
                }
            }
            fclose($fp);
        }
    }

    

}

?>


Messages In This Thread
CodeIgniter vs IPN - by El Forum - 07-18-2011, 09:47 AM
CodeIgniter vs IPN - by El Forum - 07-18-2011, 09:59 AM
CodeIgniter vs IPN - by El Forum - 07-18-2011, 11:01 AM
CodeIgniter vs IPN - by El Forum - 07-18-2011, 12:05 PM
CodeIgniter vs IPN - by El Forum - 07-19-2011, 01:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB