Notify URL of PayPal

TCM picture TCM · May 19, 2010 · Viewed 50.8k times · Source

PayPal successfully returns me the return URL that I specify while creating "buy now" button. But now I am confused. How do I retrieve details about the transaction that took place on PayPal? I also want to set some database values on the return URL. But I am afraid if my user navigates to that URL without paying, he will become a premium member nonetheless. How do I avoid this?

Answer

jamietelin picture jamietelin · May 25, 2010

PayPal returns data back to your site via what they call IPN. Its really just a callback to a URL you specify. You can set this URL via the variable notify_url you can send to PayPal.

Example:

<input name="notify_url" value="http://yourdomain.com/notify_url.php" type="hidden">

The notify_url.php in the example above receives some POST variables from PayPal when the payment is completed, even if the customer never returns to your website.

Some of the important variables returned by PayPal is:

  • mc_gross
  • invoice
  • settle_amount
  • protection_eligibility
  • address_status
  • payer_id
  • tax
  • address_street
  • payment_date
  • payment_status
  • charset
  • address_zip
  • mc_shipping
  • mc_handling
  • first_name
  • mc_fee
  • address_country_code
  • exchange_rate
  • address_name
  • notify_version
  • settle_currency
  • custom
  • payer_status
  • business
  • address_country
  • address_city
  • verify_sign
  • payer_email
  • txn_id
  • payment_type

invoice is returned if you set it. It can be used as your own order-id/transaction-id.

txn_id is generated by PayPal and it is their own id for the transaction.

If you add items yourself you will PayPal also returns num_cart_items, item_name1 (item_name2, item_name3), quantity1 (quantity2, quantity3) and such.

More reading at https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

Of course then you still have the problem to solve, how to check all this data and connect it to a customer in your own database, which you probably have.

What I do is to save a temporary "order" before I send the customer to PayPal with a invoice id, same id i send to PayPal as invoice. This way my notify_url.php page can check my database for a invoice id and compare the order/payment.