如何获得Paypal Checkout返回数据

I have been facing problems when i try to get the return data from paypal. I have set the Retrun Url on my Paypal Account and on the form as well. This is the form and this is only for testing purpose.

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" name="_xclick">
  <div align="center">   
     <input type="hidden" name="return" value="http://{host}/paypal/tnk.php" />

          <input type="hidden" name="cancel_return" value="http://{host}/paypal/tnk.php" />

          <input type="hidden" name="currency_code" value="USD" />            

            <input type="hidden" value="_xclick" name="cmd">

            <input type="hidden" name="business" value="test-facilitator@yahoo.com">

            <input type="hidden" name="item_name" value="Paypal 2015">

            <input type="hidden" name="item_number" value="123">

            <input type="hidden" name="amount" value="10">

            <input type="hidden" name="first_name" value="Test">

            <input type="hidden" name="last_name" value="Last Name">

            <input type="hidden" name="city" value="">

            <input type="hidden" name="state" value="">

            <input type="hidden" name="email" value="">

            <input type="hidden" name="image_url"">
           <input type="hidden" name="rm" value="2">
        <input type="hidden" name="notify_url"   value="http://{host}/paypal/tnk.php">

     <input type="submit" value="Proceed To Pay">

    </div>

   </form>

When i click "Proceed to pay", i am redirected to the Paypal and i can pay the price. On the return page, i have put a file to write all the return data from Paypal.

$post           = array( 'cmd' => '_notify-validate' );
foreach($_POST as $key=>$value){
        $post[$key] = $value;
        $file = fopen("test.txt","w+");  
        echo fwrite($file,print_r($_POST)); 

        fclose($file);    
}
$c  = curl_init();
curl_setopt_array($c, array(
    CURLOPT_FOLLOWLOCATION  => TRUE,
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_CONNECTTIMEOUT  => 15,
    CURLOPT_MAXREDIRS       => 15,
    CURLOPT_TIMEOUT         => 15,
    CURLOPT_URL             => 'https://www.paypal.com/cgi-bin/webscr',
    CURLOPT_POST            => TRUE,
    CURLOPT_POSTFIELDS      => $post,
));
$res = curl_exec($c);
curl_close($c);
$res    = trim($res);

if( $res != 'VERIFIED' ) {
    exit();
}

But it only writes value 1 on the text file. It means return url is owrking but paypal is not returning any data on $_REQUEST.

Anything that i am doing wrong?. Bit confused and tried several methods. Hope i have provide enough details on this.

Please help me on this. Thanks in Advance.

You must add parameter "notify_url" instead parameter "return". The parameter "return" is for successful purchase page. In your form you have the invalid fields like first_name and last_name! Use this example:

<form method="post" name="checkout-form" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="your@paypal_email.com">
<input type="hidden" name="item_name" value="Product Name>
<input type="hidden" name="amount" value="22" >
<input type="hidden" name="item_number" value="65">
<input type="hidden" name="custom" value="CUSTOM_CODE_@#!#!@#@!WDASD">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://zoomthe.me/paypalipn/paypal_ipn.php">
<input type="hidden" name="cancel_return" value="http://zoomthe.me/paypal_cancel">
<input type="hidden" name="cbt" value="Product Description">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="http://zoomthe.me/your_listener_ipn_file.php">
</form>

The most important thing in your ipn listener file is to validate paypal transaction ( This is just a recommendation ). Here is a (php) example:

        $post           = array( 'cmd' => '_notify-validate' );
    foreach($_POST as $key=>$value){
            $post[$key] = $value;
    }
    $c  = curl_init();
    curl_setopt_array($c, array(
        CURLOPT_FOLLOWLOCATION  => TRUE,
        CURLOPT_RETURNTRANSFER  => TRUE,
        CURLOPT_CONNECTTIMEOUT  => 15,
        CURLOPT_MAXREDIRS       => 15,
        CURLOPT_TIMEOUT         => 15,
        CURLOPT_URL             => 'https://www.paypal.com/cgi-bin/webscr',
        CURLOPT_POST            => TRUE,
        CURLOPT_POSTFIELDS      => $post,
    ));
    $res = curl_exec($c);
    curl_close($c);
    $res    = trim($res);

    if( $res != 'VERIFIED' ) {
        exit();
    }