Results 1 to 3 of 3

Thread: paypal IPN
      
   

  1. #1
    Freedom35 is offline Staff Sergeant
    Join Date
    Dec 2006
    Posts
    43

    Default paypal IPN

    I'm receiving the following error message when my website (paypal_subscr.php) communicate with paypal using IPN.

    Error message:
    "PayPal callback: returned INVALID. Transaction: 50726235BC3658216, payer email: tf.freedom******.com"
    File: paypal_subscr.php (see below)
    Line: 140

    From Paypal online FAQ, the problem is:
    "If your script is receiving the final post from PayPal but it is always 'INVALID' or you are receiving an error message, then you are posting back to us, but there is a problem with the information we are receiving. You must post all of the form variables exactly as you received them, and maintaining the same order."

    My questions:
    How to I "...post all of the form variables exactly as you received them, and maintaining the same order."?

    How to I know what variables are being post and in what order from IPN?

    or How to I solve this error?



    paypal_subscr.php:
    <?php
    //================================================== ==========================
    // Copyright (c) Maros Fric, webradev.com 2004
    // All rights reserved
    //
    // For support contact info@webradev.com
    //
    // script for handling PayPal subscriptions payments
    //================================================== ==========================

    // include files
    require_once('global.php');

    DebugMsg("PayPal callback: started", __FILE__, __LINE__);

    // 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);

    DebugMsg("PayPal callback: post back to PayPal", __FILE__, __LINE__);

    if (!$fp)
    {
    // HTTP ERROR
    LogError("PayPal callback: HTTP error, cannot post back. Error number: $errno, Error msg: $errstr", __FILE__, __LINE__);
    }
    else
    {
    fputs ($fp, $header.$req);
    while (!feof($fp))
    {
    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $custom = $_POST['custom'];
    $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'];
    $txn_type = $_POST['txn_type'];
    $subscr_id = $_POST['subscr_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];

    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0)
    {
    DebugMsg("PayPal callback: returned VERIFIED", __FILE__, __LINE__);

    $postvars = '';
    foreach($_POST as $k=>$v)
    $postvars .= "$k=$v;";
    DebugMsg("PayPal callback: POST variables: $postvars", __FILE__, __LINE__);

    if($custom == '')
    {
    DebugMsg("PayPal callback: custom field is empty", __FILE__, __LINE__);
    }

    if($payment_status != "Completed")
    {
    DebugMsg("PayPal callback: payment status is not COMPLETED. Transaction: $txn_id, payer email: $payer_email", __FILE__, __LINE__);
    }
    else
    {
    if(strpos($txn_type, 'subscr') === false)
    {
    // it is normal payment
    DebugMsg("PayPal callback: Start registering payment, custom field: $custom", __FILE__, __LINE__);

    $saleReg = QUnit_Global::newObj('Affiliate_Scripts_Bl_SaleReg istrator');;

    // register sale
    if($saleReg->decodeData($custom))
    {
    DebugMsg("PayPal callback: Start registering sale, params TotalCost='".$payment_amount."', OrderID='".$txn_id."', ProductID='".$item_number."'", __FILE__, __LINE__);

    $saleReg->registerSale($payment_amount, $txn_id, $item_number);

    DebugMsg("PayPal callback: End registering sale", __FILE__, __LINE__);
    }
    else
    {
    DebugMsg("PayPal callback: SaleRegistrator->decodeData returned false", __FILE__, __LINE__);
    }

    DebugMsg("PayPal callback: End registering payment", __FILE__, __LINE__);
    }
    else if($txn_type == 'subscr_payment')
    {
    // it is subscription (recurring) payment
    DebugMsg("PayPal callback: Start registering subscription (recurring) payment, custom field: $custom", __FILE__, __LINE__);

    $saleReg = QUnit_Global::newObj('Affiliate_Scripts_Bl_SaleReg istrator');;

    // register sale
    if($saleReg->findPaymentBySubscriptionID($subscr_id))
    {
    // we got affiliate id and campaign id filled by findPaymentBySubscriptionID() function

    // it is recurring call
    $saleReg->setSaleTypeAndKind(TRANSTYPE_RECURRING, TRANSKIND_RECURRING);
    $saleReg->registerSale($payment_amount, $subscr_id, $item_number);
    }
    else
    {
    // it is first subscription call
    if($saleReg->decodeData($custom))
    {
    DebugMsg("PayPal callback: Start registering sale, params TotalCost='".$payment_amount."', OrderID='".$txn_id."', ProductID='".$item_number."'", __FILE__, __LINE__);

    $saleReg->registerSale($payment_amount, $subscr_id, $item_number);

    DebugMsg("PayPal callback: End registering sale", __FILE__, __LINE__);
    }
    else
    {
    DebugMsg("PayPal callback: SaleRegistrator->decodeData returned false", __FILE__, __LINE__);
    }
    }

    DebugMsg("PayPal callback: End registering subscription (recurring) payment", __FILE__, __LINE__);
    }
    }
    }
    else if (strcmp ($res, "INVALID") == 0)
    {
    // log for manual investigation
    LogError("PayPal callback: returned INVALID. Transaction: $txn_id, payer email: $payer_email", __FILE__, __LINE__);
    }
    }

    fclose ($fp);
    }
    ?>

  2. #2
    VodaHost's Avatar
    VodaHost is offline General & Forum Administrator
    Join Date
    Mar 2005
    Location
    Wilmington, Delaware USA
    Posts
    11,428

    Default Re: invalid error with paypal IPN

    1) How many variables are you trying to passback?
    2) What are the varaibles?
    3) What are you selling?
    4) What type of commission structures are you trying to trigger?

    VodaHost

    Your Website People!
    1-302-283-3777 North America / International
    07031847328 / United Kingdom

    ------------------------

    Top 3 Best Sellers

    Web Hosting - Unlimited disk space & bandwidth.

    Reseller Hosting - Start your own web hosting business.

    Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)



  3. #3
    Freedom35 is offline Staff Sergeant
    Join Date
    Dec 2006
    Posts
    43

    Default Re: paypal IPN

    honestly, I don't know what variables I'm passing back! I'm not technically literate. I'm simply using the "template" given by PAP. Err... maybe you can help out.

    But my limited interpretation from the paypal_subscr.php (as per my previous post), I believe the variables passing back are the following:

    $item_name = $_POST['item_name'];
    $custom = $_POST['custom'];
    $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'];
    $txn_type = $_POST['txn_type'];
    $subscr_id = $_POST['subscr_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];


    I'm selling a subscription-based service.

    I have 3 tiers commission structure (www.horsedummies.com/affiliates.html)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49