Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

payment gateway - Notify URL of PayPal

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...