Search code examples
c#asp.netpaypalsandbox

PayPal Instant Payment Notification


I am working on a donations page where users can enter a donation amount and then be redirected to the PayPal page to make the payment.

I would like to get a verification from PayPal informing me whether the user actually made the transaction on the PayPal payment page so that I can then record the transaction in the database. I read that I have to use PayPal Instant Payment Notification however I couldn't find a good tutorial about how to do this.

This is the code I have used so far:

string temp_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&item_name=Sponsor a Child Society&amount=";
string PayPal = temp_url + Convert.ToString(donation);
Response.Redirect(PayPal);

I am using a sandbox account with PayPal. I have set up a business account and am able to make a payment. The only problem is that I don't know how to use the PayPal Instant Payment Notification.

Could someone please provide a suggestion?


Solution

  • The IPN service will call back to a nominated URL on your website, and echo back your payment reference, and the result. You'll have a page on your site, IPN.aspx, once your payment is confirmed, paypal will then send back to you a list of elements in your HTTP POST, which you can access, eg status, amount, currency, etc. I believe it's the same set of fields that are returned in the query string once the user is returned to your site.

    When you send the user off to paypal, you can define your IPN url there, or configure it in paypal itself. I find it's easier to do it as you send them off because it allows your to configure different ones depending on your environment.

    Remember, PayPal will need to be able to see your URL, so if you're behind a firewall, you'll need to put a rule into allow it.

    The PayPal SDK docs provide some great samples, I don't recall the form names specifically, so just talking about the principle in general.