Paypal SandBox IPN always returns INVALID

前端 未结 9 1390
予麋鹿
予麋鹿 2020-12-03 08:33

As mentioned in one of the comments in an answer below, I tried following this tutorial. So now I have the following:


The ipn.php file:

相关标签:
9条回答
  • 2020-12-03 09:24

    These links may resolve your problem,

    Paypal: Invalid IPN problem

    http://www.webmasterworld.com/ecommerce/4292847.htm

    Paypal sandbox IPN return INVALID

    0 讨论(0)
  • 2020-12-03 09:24

    I finally found an updated (August 5, 2016) working answer to this query. You can use this code as your final IPN for Sandbox or Live. With the following consideration:

    1. Be sure to place your IPN listener to ->My selling tools -> instant payment notifications Section.
    2. Do not use IPN Simulator in sandbox, it will always return INVALID.
    3. Create and Use an actual Sandbox Button, but DO NOT put your IPN listener to RETURN PAGE that says "Take customers to this URL when they finish checkout".

    That's all of it. I hope this will help.

    And here is the working code:

    <?php
    $post_data = file_get_contents('php://input');
    $post_array = explode('&', $post_data);
    $dataFromPayPal = array();
    foreach ($post_array as $keyval) {
        $keyval = explode ('=', $keyval);
        if (count($keyval) == 2)
            $dataFromPayPal[$keyval[0]] = urldecode($keyval[1]);
    }
    
    $req = 'cmd=_notify-validate';
    if(function_exists('get_magic_quotes_gpc')) {
        $get_magic_quotes_exists = true;
    }
    foreach ($dataFromPayPal as $key => $value) {
        if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
            $value = urlencode(stripslashes($value));
        } else {
            $value = urlencode($value);
        }
        $req .= "&$key=$value";
    }
    
    $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
    //use https://www.sandbox.paypal.com/cgi-bin/webscr in case you are testing this on a PayPal Sanbox environment
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
    
    if( !($res = curl_exec($ch)) ) {
        curl_close($ch);
        exit;
    }
    curl_close($ch);
    
    
    
    if (strcmp ($res, "INVALID") == 0) {
            echo "INVALID";
    }
    else if (strcmp ($res, "VERIFIED") == 0) {
            echo "VALID";
    }
    
    ?>
    
    0 讨论(0)
  • 2020-12-03 09:27

    Hours of hair pulling until I saw Izudin's answer. He's right..The + in the date wasn't being transferred. Just to test, I removed it from the pre-populated field in the simulator and got a Verified at last.

    0 讨论(0)
提交回复
热议问题