I have a paypal merchant account and some times people pay me on pay pal after subscribing.
Sometimes I have a problem of receiving IPN and updating my database and sometime my database don't get updated although payment is successfully made on PayPal for the same subscription.
I tried to use the IPN Message as suggested to see what went wrong locally, but it giving me forbidden errors.
The is sample of my code:
[HttpPost] public HttpStatusCodeResult Receive() { //Store the IPN received from PayPal LogRequest(Request);
//Fire and forget verification task Task.Run(() => VerifyTask(Request));
//Reply back a 200 code return new HttpStatusCodeResult(HttpStatusCode.OK); }
private void VerifyTask(HttpRequestBase ipnRequest) { var verificationResponse = string.Empty;
try {
using (var client = new WebClient()) {
ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
var param = Request.BinaryRead(ipnRequest.ContentLength); var strRequest = Encoding.ASCII.GetString(param);
strRequest = "cmd=_notify-validate&" + strRequest; verificationResponse = client.UploadString("https://www.paypal.com/cgi-bin/webscr", strRequest); }
} catch (Exception exception) { //Capture exception for manual investigation }
ProcessVerificationResponse(verificationResponse); }
private void ProcessVerificationResponse(string verificationResponse) { if (verificationResponse.Equals("VERIFIED")) { // check that Payment_status=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 if (Request.Form["txn_type"] == "subscr_signup") {
} else if (Request.Form["txn_type"] == "subscr_payment" && Request.Form["payment_status"] == "Completed") { //do something } else if (Request.Form["txn_type"] == "subscr_cancel") {
//do something 2
} } else if (verificationResponse.Equals("INVALID")) { //Log for manual investigation } else { //Log error } }
My Online IPN : https://vodapi.mtv.com.lb/IPN/Receive.
Please advice on how to debug what is going wrong.
... View more