0

私はPaypal IPNに取り組んでいます。私のアプリケーションは Paypal から最初の通知を受け取ることができましたが、ポストバックを送信した後、ポストバックが有効であるか無効であるかにかかわらず、paypal から応答がないようです。

コードの大部分は、paypal 開発者の Web サイトのサンプル コードから取得しました。

public function process(){

// Read the notification from PayPal and create the acknowledgement response
$req = 'cmd=_notify-validate';               // add 'cmd' to beginning of the acknowledgement you send back to PayPal

//$raw = file_get_contents("php://input");
foreach ($_POST as $key => $value) {         // Loop through the notification NV pairs
    $value = urlencode(stripslashes($value));  // Encode the values
    $req .= "&$key=$value";                    // Add the NV pairs to the acknowledgement
}

//Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";

//Open a socket for the acknowledgement request
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// Post request back to PayPal for validation
fputs ($fp, $header . $req);


while (!feof($fp)) {                     // While not EOF
    $res = fgets ($fp, 1024);              // Get the acknowledgement response
    //$res=stream_get_contents($fp, 1024);

    $this->emailtest(print_r($_POST,true) .'<br /><br />' . $header.$req);
    if (strcmp ($res, "VERIFIED") == 0) {  // Response is VERIFIED

        $this->emailtest('VERIFIED');
        // Send an email announcing the IPN message is VERIFIED
        //$mail_From = "IPN@example.com";
        //$mail_To = "Your-eMail-Address";
        //$mail_Subject = "VERIFIED IPN";
        //$mail_Body = $req;
        //mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

        // Notification protocol is complete, OK to process notification contents

        // Possible processing steps for a payment might include the following:

        // Check that 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

    }

    else if (strcmp ($res, "INVALID") == 0) { // Response is INVALID

        $this->emailtest('INVALID');
        // Notification protocol is NOT complete, begin error handling

        // Send an email announcing the IPN message is INVALID
        $mail_From = "IPN@example.com";
        $mail_To = "Your-eMail-Address";
        $mail_Subject = "INVALID IPN";
        $mail_Body = $req;
        mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
    }
}
fclose ($fp); 

}

私のヘッダーは次のようになります: [$header.$req の連結から]:

Content-Type: application/x-www-form-urlencoded 
Content-Length: 960 
Connection: close

cmd=_notify-validate&mc_gross=30.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=V6AHFXYY8YVFU&tax=0.00&address_street=1+Main+St&payment_date=09%3A20%3A02+Jul+06%2C+2013+PDT&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=LY&mc_fee=1.37&address_country_code=US&address_name=LY+Y&notify_version=3.7&custom=&payer_status=verified&business=test-facilitator%40hotmail.com&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=ALty0ZLnfvwh23G8AkAyx34uB78KAtFMUzdUnz11sJNJNFF4NI8JnFNu&payer_email=test%40hotmail.com&txn_id=2VB92036BK537324F&payment_type=instant&last_name=Y&address_state=CA&receiver_email=test-facilitator%40hotmail.com&payment_fee=&receiver_id=82EXQSKTSV6ZN&txn_type=web_accept&item_name=Chef&mc_currency=SGD&item_number=1&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=Chef&payment_gross=&shipping=0.00&ipn_track_id=1dc5a2e7b3934

前もって感謝します!

4

3 に答える 3

0

私にとってうまくいったのは、接続クローズヘッダーを削除し、PP からの応答にトリムを追加することでした。ヘッダーは次のとおりです。

$header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

fsockopen は次のとおりです。

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

PP から返された応答のトリムは次のとおりです。

if (!$fp) {
// HTTP ERROR
  error_mail("Could not open socket");
//
} else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = trim(fgets ($fp, 1024));
    }
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
  if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {

それは私のために働いた。

于 2013-08-26T07:26:48.847 に答える