Fork me on GitHub

Paypal IPN return messsages  Bottom

  • I am not sure this is a migration issue but it is something that worked in 764 but now that I have upgraded to Zikula 1.1.2 I am getting a repeated message returned from PayPals IPN function. The cash is accepted but it continues to send IPN messages even though the payment has been accepted.

    The code processes the _POST variable and since Zikula has changed how the variables are processed I am not sure this is why the problem has appeared. The IPN function is the following http://agilityjot.com/index.php?module=UpgradeUser&func=paypalIPN and the function in the following:

    Code

    function UpgradeUser_user_paypalIPN()
    {
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        // This is for checking PDT (payment data transfer)
        // 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 ('www.paypal.com', 80, $errno, $errstr, 30);
        // If possible, securely post back to paypal using HTTPS
        // Your PHP server will need to be SSL enabled
        $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
        //$fp = fsockopen ('ssl://www.sandbox.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'];
        $payer_name = $_POST['first_name'] . ' ' . $_POST['last_name'];

        switch ($item_number) {
          case 1:
          case 2:
            $uid = $_POST['custom'];
            $gname = "Standard";
            break;
          case 3:
            $uid = $_POST['custom'];
            $gname = "Premium";
            break;
          case 4:
            list($giftname, $giftemail) = explode(':', $_POST['custom']);
            $gname = "Standard";
            break;
        }

        if (!$fp) {
            // HTTP ERROR
            $stop = _HTTPERRORIPN;
        } else {
            fputs ($fp, $header . $req);
            while (!feof($fp)) {
                $res = fgets ($fp, 1024);
                if (strcmp ($res, "VERIFIED") == 0) {
                    // check the payment_status is Completed
                    if ($_POST['payment_status'] != 'Completed') {
                      $stop = _PENDINGFUNDS;
                    }

                    // 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
                    foreach ($_POST as $key => $value){
                      $emailtext .= $key . " = " .$value ."\n\n";
                    }

                }
                else if (strcmp ($res, "INVALID") == 0) {
                    // log for manual investigation
                    $stop = _INVALIDIPN;
                }
            }
            fclose ($fp);
        }
        if (!$stop) {

          $diskAllow = explode('|', pnModGetVar('UpgradeUser', 'diskAllow'));
          list($ds, $amt) = explode(':', current($diskAllow));

          $adminmail = pnConfigGetVar('adminmail');
          $sitename = pnConfigGetVar('sitename');
          $siteurl = pnGetBaseURL();

          switch ($item_number) {
            case 4:
              $subject = _UPGRADEUSERPURCHASESUB;
              $message = _UPGRADEUSERHEADER . _UPGRADEUSERPURCHASE1 . " $giftname ($giftemail) " . _UPGRADEUSERPURCHASE2;
              pnModAPIFunc('Mailer', 'user', 'sendmessage', array('toaddress' => $payer_email, 'subject' => $subject, 'body' => $message, 'html' => 1));

              pnModAPIFunc('UpgradeUser', 'user', 'addGift', array('email' => $giftemail, 'fromemail' => $payer_email));

              $message = _UPGRADEUSERHEADER . _UPGRADEUSERCONGRATS1 . " $sitename. " . _UPGRADEUSERCONGRATS2 . " ${payer_name}" . _UPGRADEUSERCONGRATS3 . "<br /><br />";
              if (pnUserGetIDFromEmail($giftemail) === false) {

                $accturl = $siteurl . '/index.php?module=Users&func=register';
                $message .= _UPGRADEUSERHASNOACCT1 . $accturl . _UPGRADEUSERHASNOACCT2;
              } else {

                $message .= _UPGRADEUSERHASACCT;
              }
              $email = $giftemail;
              $subject = "$sitename " . _ASREG . " " . _ASREGCONFIRM;
              break;

            default:
              pnModAPIFunc('UpgradeUser', 'user', 'updateReg', array('uid' => $uid, 'regtype' => $gname, 'diskspace' => $ds));
              $uname = pnUserGetVar('uname', $uid);
              $email = pnUserGetVar('email', $uid);

              $item = pnModAPIFunc('UpgradeUser',
                                   'user',
                                   'get',
                                   array('uid' => $uid));
              $message = _UPGRADEUSERHEADER . _WELCOMETO . " $sitename ($siteurl)!<br /><br />" . _THANKYOU . " ${sitename}!<br /><br />" . _YOUEXPIREDATE . strftime('%d %B %Y', strtotime($item['expire'])) . ".<br /><br />";
              $subject = "$sitename " . _ASREG . " " . _ASREGCONFIRM;
              break;
          }

          // send the e-mail
          pnModAPIFunc('Mailer', 'user', 'sendmessage', array('toaddress' => $email, 'subject' => $subject, 'body' => $message, 'html' => 1));
          if (pnConfigGetVar('reg_notifyemail') != "") {
              $email2 = pnConfigGetVar('reg_notifyemail');
              $subject2 = _NOTIFYEMAILSUB;
              $message2 = _NOTIFYEMAILCONT1 . "$uname" . _NOTIFYEMAILCONT2;
              // send the e-mail
              pnModAPIFunc('Mailer', 'user', 'sendmessage', array('toaddress' => $email2, 'subject' => $subject2, 'body' => $message2));
          }

        } else {
            $email2 = $adminmail;
            $subject2 = _PROBLEMIPN;
            $message2 = pnVarPrepForDisplay($stop) . " the uid= $uid \nreq= $req" ;
            // send the e-mail
            pnModAPIFunc('Mailer', 'user', 'sendmessage', array('toaddress' => $email2, 'subject' => $subject2, 'body' => $message2));
        }
    }



    Because I am reading the _POST from within this function I am not sure this is what is causing the problem or if it is something from Paypal but since this problem has only occurred since I have upgraded it does seem suspect. The payment is accepted but it continues to send the function and send the confirmation email but it does not continue to take payment (unfortunately icon_wink ) -- So I am not sure if I need to change this function ... any help is much appreciated!!
  • I have programmed a work around for this. Thanks to anyone that took a look.

    It appears that Zikula is somehow returning a 404 back and therefore it does not clear. Alas.
  • Does anyone know why a 404 error code is being returned by Zikula and not a 200 success?

    Got it! I was not returning a real page!! Doh!



    edited by: mjturn, datetimebrief
  • I clicked your IPN URL and it leads me to the login page. PayPal IPN must be open for anyone to access: security is performed in the callback from the called script.

    Drak

    --
    Zikula Lead Developer
    Board Member of the Zikula Foundation
    Follow me on twitter.com/zikuladrak
  • By the way, I would strongly suggest using the new Zikula APIs and DBUtil here because some of your code will break in future versions. There is no ADODB object for example from 1.3.0 nor support for language defines.

    http://community.zik…ag=ConvertToGettext

    Drak

    --
    Zikula Lead Developer
    Board Member of the Zikula Foundation
    Follow me on twitter.com/zikuladrak
  • I am painfully aware of that... I have been working through all my websites and this site has a really BIG module I am working through before I get to this particular module.

    Thanks for the heads up!
    I finally did figure out what the problem was... this function was not returning a real page... so now it does and I believe that has solved the problem.
  • With the removal of ADODB will DBUtils::executeSQL still be available? Or will I have to some up with another solution?
  • DBUtil remains completely in tact, but DBUtil internals moves to using PDO and Doctrine.

    Drak

    --
    Zikula Lead Developer
    Board Member of the Zikula Foundation
    Follow me on twitter.com/zikuladrak

This list is based on users active over the last 60 minutes.