Paypal返回“ INVALID”,尽管已成功订阅

时间:2018-09-15 14:16:35

标签: paypal paypal-sandbox sandbox paypal-subscriptions

我正在尝试使用Paypal沙盒进行订阅功能,并且付款已成功处理。但是,当尝试验证响应时,贝宝会返回无效响应。

这是我要发送的数据-

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] => aditya-facilitator@codeacious.tech
    [amount3] => 52.50
    [recurring] => 1
    [payer_status] => verified
    [payer_email] => aditya-buyer@codeacious.tech
    [first_name] => test
    [receiver_email] => aditya-facilitator@codeacious.tech
    [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
)

这是我得到的答复-

(
    [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
)

我要尝试通过的网址是-

  

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

我还在个人资料> PayPal按钮语言编码中的Paypal Seller设置中将字符编码设置为UTF-8。

请帮助。

1 个答案:

答案 0 :(得分:0)

我已经实现了如下所示,并且运行良好:

只需在下面的代码中更改电子邮件地址,然后尝试,它就可以工作。

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

请使用上面的函数,希望它能解决您的问题,我已经在PHP中实现了同样的功能。让我知道是否需要任何帮助。