/// <summary> /// This sends the message back to PayPal which will reply with the verification status. /// </summary> /// <param name="ipnContext">The IPN Context message that was built by Process</param> private void VerifyTask(ProcessedIPNMessage ipnContext) { try { var verificationRequest = WebRequest.Create(_IPNString); //Set values for the verification request verificationRequest.Method = "POST"; verificationRequest.ContentType = "application/x-www-form-urlencoded"; //Add cmd=_notify-validate to the payload string strRequest = "cmd=_notify-validate&" + ipnContext.PayPalRequest.rawBody; verificationRequest.ContentLength = strRequest.Length; //Attach payload to the verification request using (StreamWriter writer = new StreamWriter(verificationRequest.GetRequestStream(), Encoding.ASCII)) { writer.Write(strRequest); } //Send the request to PayPal and get the response using (StreamReader reader = new StreamReader(verificationRequest.GetResponse().GetResponseStream())) { ipnContext.VerificationString = reader.ReadToEnd(); } } catch (Exception exception) { throw new Exception(exception.ToString()); } }
private void processData(PayPalIPNRequest requestData) { PPIPNProcessor processor = new PPIPNProcessor(true); try { ProcessedIPNMessage result = processor.Process(requestData); if (result.Verification == VerificationStatuses.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 } else if (result.Verification == VerificationStatuses.Invalid) { //Log for manual investigation Note that you WILL get this value if you are testing from local data as PayPal didn't initiate the transaction! } else { //Log error based on result.VerificationString value Console.WriteLine(result.VerificationString); } } catch (Exception e) { // todo: log exception } }
/// <summary> /// Pass in the request from PayPal and it will do the required reply back to PayPal asynch. /// It then fires an event that your /// </summary> /// <param name="request"></param> /// <returns>A ProcessedIPNMessage that contains the request plus the verification status as obtained /// when we sent back the message to FaceBook</returns> public ProcessedIPNMessage Process(PayPalIPNRequest request) { ProcessedIPNMessage ipnContext = new ProcessedIPNMessage(); ipnContext.PayPalRequest = request; VerifyTask(ipnContext); //Reply back with true return(ipnContext); }