0
votes

I'm trying out Subscription functionality using Paypal sandbox and the payment is successfully processed. However, when trying to verify the response, Paypal returns INVALID response.

Here's the data I'm trying to send -

Array
(
    [cmd] => _notify-validate
    [txn_type] => subscr_signup
    [subscr_id] => I-3R009NJ6JYS9
    [last_name] => buyer
    [residence_country] => GB
    [mc_currency] => USD
    [item_name] => Sellacious_Git
    [business] => [email protected]
    [amount3] => 52.50
    [recurring] => 1
    [payer_status] => verified
    [payer_email] => [email protected]
    [first_name] => test
    [receiver_email] => [email protected]
    [payer_id] => LCLETGLHU5H7A
    [reattempt] => 1
    [item_number] => 123
    [subscr_date] => 06:35:57 Sep 15, 2018 PDT
    [charset] => windows-1252
    [period3] => 1 D
    [mc_amount3] => 52.50
    [auth] => AyB1VOVssxLlLE177ha.etTVC3E8ZWDZOAEu.e9Wezio0ciVvog4UXvI6ODZq-ZxS2tearHH1MAiO.U7E0k.IBg
    [form_charset] => UTF-8
)

This is the response I get -

(
    [code] => 200
    [headers] => Array
        (
            [Date] => Sat, 15 Sep 2018 14:05:29 GMT
            [Server] => Apache
            [X-Frame-Options] => SAMEORIGIN
            [Set-Cookie] => Apache=10.72.108.11.1537020329139856; path=/; expires=Mon, 07-Sep-48 14:05:29 GMT
            [Vary] => Accept-Encoding,User-Agent
            [Connection] => close
            [Transfer-Encoding] => chunked
            [Content-Type] => text/html; charset=UTF-8
        )

    [body] => INVALID
)

The url that I'm trying to cURL through is -

https://ipnpb.sandbox.paypal.com/cgi-bin/webscr

I've also setup the character encoding to be UTF-8 in the Paypal Seller's settings in Profile > PayPal button language encoding.

Please help.

1
Could you please share your full code whatever you have implemented and sending CURL?Raghbendra Nayak

1 Answers

0
votes

I have implemented like below and that is working fine:

Just change Email address in below code and try, it should work.

function paymentIpnlistener(){
     // 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";
    // If testing on Sandbox use: 
    $header .= "Host: www.sandbox.paypal.com:443\r\n";
    //$header .= "Host: ipnpb.paypal.com:443\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    if (strpos('ssl://www.sandbox.paypal.com', 'sandbox') !== FALSE && function_exists('openssl_open')) {
    $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
  }
    else{
    // The old "normal" way of validating an IPN.
     $fp = fsockopen('ssl://www.sandbox.paypal.com', 80, $errno, $errstr, 30);
    }
    // If testing on Sandbox use:
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
    //$fp = fsockopen ('ssl://ipnpb.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) {
                // check the payment_status is Completed
                // 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

                $mail_From = "// add here your working email address";
                $mail_To = "// add here your working email address";
                $mail_Subject = "VERIFIED IPN";
                $mail_Body = $req;
                foreach ($_POST as $key => $value){
                    $emailtext .= $key . " = " .$value ."\n\n";
                }

                mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

            }
            else if (strcmp ($res, "INVALID") == 0) {
                // log for manual investigation

                $mail_From = "From: // add here your working email address";
                $mail_To = "// add here your working email address";
                $mail_Subject = "INVALID IPN";
                $mail_Body = $req;

                foreach ($_POST as $key => $value){
                    $emailtext .= $key . " = " .$value ."\n\n";
                }

                mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

            }
        }   // while end
     fclose ($fp);
    }   
}

Please use above function I hope it will solve your problem, I have implemented in PHP same. Let me know if required any help.