I have an Asp.Net WEB API 2 project and I would like to implement an Instant Payment Notification (IPN) listener controller.
I can\'t find any example and nuget package
Extending Michal Hosala's answer, there are two things needed to get a successful handshake with PayPal
First, setting the security protocol before making request to PayPal
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Second, avoiding the dictionary because for verification, PayPal requires the data to be posted back in the same order and preceded by the cmd variable. I ended up doing this
Request.InputStream.Seek(0, SeekOrigin.Begin);
string rawRequestBody = new StreamReader(Request.InputStream).ReadToEnd();
var ipnVarsWithCmd = rawRequestBody.Split('&').Select(x => new KeyValuePair(x.Split('=')[0], x.Split('=')[1])).ToList();
ipnVarsWithCmd.Insert(0, new KeyValuePair("cmd", "_notify-validate"));