0

The following data in the $res verbal is output from cURL and I am trying to use it to make the following script to work. But it does not processes the data at all. I have checked it an $lines[0] has SUCCESS in it as the first line. It should output the rest of the data but it doesn't.Any body have any ideas on how ti fix this. Or is it because I am not processing the data through cURL to test this. I what to make the script work perfect before I make it live. cURL pules the data from PayPal as pdt and PayPals sandbox is crap

$res = "SUCCESS 
transaction_subject=Subscribe+to+Notary+Accounting 
payment_date=16%3A29%3A09+May+24%2C+2014+PDT
txn_type=subscr_payment
subscr_id=S-01T86772CP0815034
last_name=Kurth
option_selection1=1+month
residence_country=US
item_name=Subscribe+to+Notary+Accounting
payment_gross=0.05
mc_currency=USD
business=rdkurth%40live.com
payment_type=instant
protection_eligibility=Ineligible
payer_status=unverified
payer_email=rich%40notaryaccounting.com
txn_id=94V17846W2603332N
receiver_email=rdkurth%40live.com
first_name=Richard
option_name1=Payment+options
payer_id=AAAE8FMAK2TH2
receiver_id=5GZ34FDY49A64
recur_times=4146841749
payment_status=Completed
payment_fee=0.05
mc_fee=0.05
btn_id=81809415
mc_gross=0.05
charset=windows-1252";

if(!$res){
    //HTTP ERROR
}else{

     // parse the data
    $lines = explode("\n", $res);
    $keyarray = array();
    if (strcmp ($lines[0], "SUCCESS") == 0) {
        for ($i=1; $i<count($lines);$i++){
        list($key,$val) = explode("=", $lines[$i]);
        $keyarray[urldecode($key)] = urldecode($val);

    }

    $firstname = $keyarray['first_name'];
    $lastname = $keyarray['last_name'];
    $itemname = $keyarray['item_name'];
    $amount = $keyarray['payment_gross'];

    echo ("<p><h3>Thank you for your purchase!</h3></p>");

    echo ("<b>Payment Details</b><br>\n");
    echo ("<li>Name: $firstname $lastname</li>\n");
    echo ("<li>Item: $itemname</li>\n");
    echo ("<li>Amount: $amount</li>\n");
    echo ("");
    }
    else if (strcmp ($lines[0], "FAIL") == 0) {
        echo(' log for manual investigation');
    }
}

1 Answer 1

1

its a known paypal issue you need to remove some white space from the first response line like so:

if (strcmp (trim($lines[0]), "SUCCESS") == 0) {
Sign up to request clarification or add additional context in comments.

3 Comments

I can't believe all it took was adding trim. You say its a known paypal issue. Does paypal know about this
well if they do, they haven't fixed it, since they introduced it ;(
afaik, this is a quirk of using the http 1.1 chuncked transfers - not directly being related to PP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.