What should I do if I cannot receive IPN when integrating paypal?

Source: Internet
Author: User
When integrating paypal, you cannot receive IPN1. the standard integration method is adopted, and the button is paid (successful). 2. return can be received. 3. IPN cannot receive... However, in the seller's account settings, we can see that ipn has been sent out. 4. sandbox environment & lt; formaction = & quot; https: // ww cannot receive IPN when integrating with paypal
1. use the standard integration method and the button for payment (successful)
2. return can be received.
3. IPN cannot receive... However, in the seller's account settings, we can see that ipn has been sent out.
4. sandbox environment




// Add a variable when reading POST information from PayPal? Cmd?
$ Req = 'cmd = _ policy-validate ';
Foreach ($ _ POST as $ key => $ value ){
$ Value = urlencode (stripslashes ($ value ));
$ Req. = "& $ key = $ value ";
}
// We recommend that you record the received information here to the log file to confirm whether the IPN information is received.
// POST the information back to PayPal for verification
$ 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 ";
// In the case of Sandbox, set:
$ Fp = fsockopen ('www .sandbox.paypal.com ', 80, $ errno, $ errstr, 30 );
// $ Fp = fsockopen ('www .paypal.com ', 80, $ errno, $ errstr, 30 );
// Record the POST variable in the local variable
// For the payment details, see:
// Https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.htm
$ 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 '];
//...
// Determine whether the reply POST is created successfully
If (! $ Fp ){
// HTTP error
} Else {
// Write the reply POST information to the SOCKET Port
Fputs ($ fp, $ header. $ req );
// Start accepting the authentication information sent by PayPal to Reply to POST
While (! Feof ($ fp )){
$ Res = fgets ($ fp, 1024 );
// Has passed the authentication
If (strcmp ($ res, "VERIFIED") = 0 ){

@ $ Fp = fopen ("aaa.txt", "w ");
If (! $ Fp ){
Echo "system error ";
Exit ();
} Else {
Fwrite ($ fp, "finished ");
Fclose ($ fp );
}

// Check the payment status
// Check whether txn_id has been processed
// Check whether receiver_email is the EMAIL address in your PayPal account
// Check whether the payment amount and currency unit are correct
// Process the payment, including writing the database
} Else if (strcmp ($ res, "INVALID") = 0 ){
// An error code or an invalid POST may be returned if the authentication fails.
@ $ Fp = fopen ("bbb.txt", "w ");
If (! $ Fp ){
Echo "system error ";
Exit ();
} Else {
Fwrite ($ fp, "error ");
Fclose ($ fp );
}


}
}
Fclose ($ fp );
}
?>

------ Solution --------------------
PHP code
//session_start();$req = 'cmd=_notify-validate';foreach ($_POST as $key => $value) {$value = urlencode(stripslashes($value));$req .= "&$key=$value";}$url='https://www.paypal.com/cgi-bin/webscr';    $curl_result=$curl_err='';    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL,$url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));    curl_setopt($ch, CURLOPT_HEADER , 0);       curl_setopt($ch, CURLOPT_VERBOSE, 1);    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    curl_setopt($ch, CURLOPT_TIMEOUT, 3000);    $curl_result = @curl_exec($ch);    $curl_err = curl_error($ch);    curl_close($ch);$mc_gross = $_POST['mc_gross'];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.