WebAPI PayPal C# example issue with notify_url (localhost / 127.0.0.1)

Hi everyone,

I am trying to configure the PayPal implementation in the WebAPI project c#. The payments are working fine, I am successfully creating payments, as my test facilitator and test buyer accounts are being debited and credited fine.

However, the paychecker.aspx page which is the notify_url does not ever seem to be reached, as my VS debugger never steps into the code. After I make a purchase on PayPals page, I press the "Return to merchant" button and am immediately taken back to the return Thank you page. There is some Paypal validation code in the notify_url which doesn't seem to execute.

I haven't changed the input tag in the payment.aspx page, and I've configured the CheckScript variable to a valid url.

<input type="hidden" name="notify_url" value="<%= PaymentSettings.CheckScript + "?paypal=1" %>"/>

public const string CheckScript = "http://localhost:2103/paychecker.aspx";

Is there something more that needs to be done?

>> "http://localhost:2103/paychecker.aspx"

Yeah, that won't work. As described in the tutorial:

>> "Set the "CheckScript", "BuyPage", and "ThankYouPage" variables to the publicly-accessible locations of the included pages."

"localhost" is not publicly accessible. Nor is 127.0.0.1. Also, you *must* use HTTPS for PayPal to contact the script.

It makes it harder to test, but that's what's required.

Ok thank you for letting me know.

So I've deployed the project to publicly accessible location. I've also installed an SSL certificate, yet the notify_url code does not execute still.

Is there anything else I need to check for? Now I can't really debug so this is going to be troublesome.

Well, not only does it need to be publicly accessible, but the URL needs to be public accessible, and use a non-self-signed certificate.

In short: you need to debug it. Start by getting on a separate computer viewing the source of the web page, getting the callback url from the source. Go to that URL in the browser window.

Does it work? I.e. do you get a blank page? Is the code executed on your server? Can you tell? Did you attach a debugger or add logging? If not, do that.

Standard debugging steps apply from there. That's just the first step -- can this URL even be properly retrieved from a separate network.

Hi Wyatt,

I really appreciate your quick and detailed replies.

So yes, the url is publicly accessible (I can access it from any network) as it is a standard "https://www.mydomain.net" url. The certificate was installed by my host (MyASP.net). So it is not self-signed (i.e. I did not sign it).

I got the callback url from the page source and opened that url in a browser. It provides just a blank page. I have not added any logging. I'm not sure how to go about it if I'm being very honest.

I've managed to set up logging. So apparently the callback URL is being reached, and my code is being run. I've found out that the PayPal order is not being validated because the Request.Form["payment_status"] is returning Pending and not Completed. So it returns false and ignores the rest of the code.

Is it expected for the order to be Completed at this point?

Ah, OK this is a PayPal configuration problem (a problem you can fix in your account): https://stackoverflow.com/questions/4298117/paypal-ipn-always-return-payment-status-pending-on-sandbox

Thanks Wyatt, that's done the trick! It looks like everything is working fine except for one issue I've noticed since adding logging. After making a successful payment, IPN send multiple notifications which triggers the product key creation code multiple times. Is this normal behaviour even after a successful payment?

>> "After making a successful payment, IPN send multiple notifications which triggers the product key creation code multiple times."

It's likely because the call back to PayPal saying that "received & processed the message" was never received by them. Make sure the post back is "VERIFIED" (see the end of the ValidatePP() function). And make sure you're sending to the correct server (sandbox for tests, real server for real payments).

Also, if you had a bunch of tests that were never validated, those get resent by PayPal (so you might be working through a backlog of your tests)