0

I am trying to use paypal IPN but it only returns a blank field instead of "Verified" or not verified? Is it suposed to return a blank field?

function VerifyPayment() {

          // parse the Paypal URL
          $url_parsed=parse_url($this->GatewayUrl);        

          // generate the post string from the _POST vars aswell as load the
          // _POST vars into an array so we can play with them from the calling
          // script.
          //print_r($_POST);

          $this->InvoiceNo = $_POST['invoice'];

          $post_string = '';    
          foreach ($_POST as $field=>$value) { 
             $this->ipn_data["$field"] = $value;
             $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; 
          }
          $post_string.="cmd=_notify-validate"; // append ipn command

          // open the connection to Paypal
          $fp = fsockopen($url_parsed[host],"80",$err_num,$err_str,30); 
          if(!$fp) {

             // could not open the connection.  If loggin is on, the error message
             // will be in the log.
             $this->last_error = "fsockopen error no. $errnum: $errstr";
             $this->log_ipn_results(false);       
             return false;

          } else { 

             // Post the data back to Paypal
             fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); 
             fputs($fp, "Host: $url_parsed[host]\r\n"); 
             fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
             fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); 
             fputs($fp, "Connection: close\r\n\r\n"); 
             fputs($fp, $post_string . "\r\n\r\n"); 

             // loop through the response from the server and append to variable
             while(!feof($fp)) { 
                $this->ipn_response .= fgets($fp, 1024); 
             } 

             fclose($fp); // close connection

          }

          if (eregi("VERIFIED",$this->ipn_response)) {

                // Valid IPN transaction. 
                $to = "my-emailo@gmail.com";
                $subject = "VerifyPayment TRUE";
                $message = "text";
                $from = "zezecamarinha@gajas.come";
                $headers = "From:" . $from;
                mail($to,$subject,$message,$headers);
                echo "Mail Sent.";

                return true;       

          } else {
            $to = "my-email@gmail.com";
                $subject = "VerifyPayment FALSE";
                $message = "||response:".$this->ipn_response."||errornum:".$err_num."||errorstr:".$err_str."||url_parsed[path]:".$url_parsed[path]."||url_parsed[host]:".$url_parsed[host]."||post_string:".$post_string;
                $from = "zezecamarinha@gajas.come";
                $headers = "From:" . $from;
                mail($to,$subject,$message,$headers);
                echo "Mail Sent.";

             // Invalid IPN transaction.  Check the log for details.
             return false;

      }

   }

and the response I get (in may e-mail) is:

´||response:HTTP/1.0 302 Found Location: https://www.sandbox.paypal.com Server: BigIP Connection: close Content-Length: 0

||errornum:0||errorstr:||url_parsed[path]:/cgi-bin||url_parsed[host]:www.sandbox.Paypal.com||post_string:mc_gross=0.04&invoice=5138d0b85e6b5&protection_eligibility=Eligible&address_status=confirmed&payer_id=DM32R376STZLY&tax=0.00&address_street=1+Main+St&payment_date=09%3A40%3A14+Mar+07%2C+2013+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=ze&mc_fee=0.04&address_country_code=US&address_name=ze+malh%E3o&notify_version=3.7&custom=5138d0b85e6b5&payer_status=verified&business=admin_1362650103_biz%40gmail.com&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AALyDIKsAioIkAct58DvtIPZSSJJAoGuIYe.LXHArin2.kTsH2Y.VvW6&payer_email=zepipo_1362649981_per%40gmail.com&txn_id=3064854848985250B&payment_type=instant&last_name=malh%E3o&address_state=CA&receiver_email=admin_1362650103_biz%40gmail.com&payment_fee=0.04&receiver_id=4S4KP74V2695Q&txn_type=web_accept&item_name=WPMP+Order%23+5138d0b85e6b5&mc_currency=USD&item_number=5138d0b85e6b5&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=5138d0b85e6b5&payment_gross=0.04&shipping=0.00&ipn_track_id=35c2de10de615&cmd=_notify-validate

4

0 回答 0