views:

236

answers:

1

Hello, Paypal returns me successfully to 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 happened on Paypal? And i also want to set some database values on the return url. But i am afraid if my user without paying to paypal goes to that url, then he too will become premium member. How do i secure this?

Please bear with me. Thanks in advance :)

+1  A: 

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&amp;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.

jamietelin
Hi jamietelin. Thanks for your valuable response. I already figured this out on my own. I would like to add that rather than storing temporary order in database, Paypal has already given once nice example where we retrieve all request parameter names and its values and send it back to Paypal(for validation) from our notify url and the Paypal then returns a string "VERIFIED" or "INVALID" based on which you can do some database operations.
Ankit Rathod
Well the temporary db is mostly if we need to connect it somehow to a user in our own user db. I do need this. But it depends on what service you are building I guess :)
jamietelin