I have a problem regarding my Paypal IPN Listener
. I use example code found here on Stack Overflow which seems to work for some people, but not for me.
No matter which example code I use, I always get the same error message while I try to send a message back to my paypal sandbox account (https://sandbox.paypal.com)
"Bad Request 400".
Is there any sample for PayPal IPN
Using this example code: https://stackoverflow.com/a/40079922/1804084 I can see that I get an IPN message from Paypal and it is copied to my model correctly, but then while sending it back to my Sandbox it fails with "Bad Request 400".
An additional problem is, that I can not debug that code because it is hosted in the Microsoft Azure cloud as an App Service and my breakpoints never get hit in the PayPalValidator
class while Remote Debugging and so I can not see what the example code is sending back. I also tried each solution found on the net to get my breakpoints hit but still no success. I think using Azure Cloud was a really bad choice as it makes my life so much harder.
response = client.PostAsync("cgi-bin/webscr", content).Result;
Maybe there is something wrong with the encoding?!
I tried it with using https (ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
) and without it and I configured my sandbox account to use UTF-8 encoding
. Still no success.
I also tried to add a host header client.DefaultRequestHeaders.Host(paypalUrl)
as this
seemed to be the solution for some people, but also without success.
Can someone can tell me what is wrong with the example code I use? Or even better If someone could provide me a up-to-date working C#
IPN Listener Code .
Maybe my console output can help:
w3wp.exe Information: 0 : Request, Method=POST, Url=://myservice.azurewebsites.net/api/paypal/ipn, Message='://myservice.azurewebsites.net/api/paypal/ipn' w3wp.exe Information: 0 : Message='PayPal', Operation=DefaultHttpControllerSelector.SelectController w3wp.exe Information: 0 : Message='myserviceService.Controllers.PayPalController', Operation=DefaultHttpControllerActivator.Create w3wp.exe Information: 0 : Message='myserviceService.Controllers.PayPalController', Operation=HttpControllerDescriptor.CreateController w3wp.exe Information: 0 : Message='Selected action 'ReceiveIPN(IPNBindingModel model)'', Operation=ApiControllerActionSelector.SelectAction w3wp.exe Information: 0 : Message='Parameter 'model' bound to the value 'myserviceService.DataObjects.IPNBindingModel'', Operation=ModelBinderParameterBinding.ExecuteBindingAsync w3wp.exe Information: 0 : Message='Model state is valid. Values: model=myserviceService.DataObjects.IPNBindingModel', Operation=HttpActionBinding.ExecuteBindingAsync w3wp.exe Information: 0 : Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance w3wp.exe Information: 0 : Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate w3wp.exe Information: 0 : Operation=MobileAppControllerAttribute.OnActionExecutingAsync, Status=400 (BadRequest) w3wp.exe Information: 0 : Operation=PayPalController.ExecuteAsync, Status=400 (BadRequest) w3wp.exe Information: 0 : Response, Status=400 (BadRequest), Method=POST, Url=http://myservice.azurewebsites.net/api/paypal/ipn, Message='Content-type='application/json; charset=utf-8', content-length=unknown' w3wp.exe Information: 0 : Operation=JsonMediaTypeFormatter.WriteToStreamAsync w3wp.exe Information: 0 : Operation=PayPalController.Dispose
Is there really nobody with an working IPN Listener example. Would even pay for that...