Notify URL of PayPal

51,530

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.

Share:
51,530

Related videos on Youtube

TCM
Author by

TCM

Updated on November 12, 2020

Comments

  • TCM
    TCM over 3 years

    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?

  • TCM
    TCM about 14 years
    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.
  • jamietelin
    jamietelin about 14 years
    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 :)
  • PHP Ferrari
    PHP Ferrari over 12 years
    @ jamietelin I tried it but not succeeded please see stackoverflow.com/questions/8570539/…
  • quano
    quano about 12 years
    How can you verify the data posted is correct and really coming from paypal? Edit: found it: cms.paypal.com/uk/cgi-bin/…
  • Nick Green
    Nick Green almost 11 years
    I have been having similar issues. PayPal doesn't document that well how the IPN works and what information you can get back to process. The best way is to create an order before you send the user to PayPal and append the UID to "Item_Number". That way we have something to use at our end to update the order status. Great question and fantastic response from @jamietelin thanks guys
  • Drazen Bjelovuk
    Drazen Bjelovuk over 9 years
    Do the address related variables represent shipping or billing?
  • jamietelin
    jamietelin over 9 years
    Not 100% sure how it works now, it was a while ago i posted my awnser. But I think it's billing and shipping. User may get a chance to add external shipping adress via Paypals site later in the process, or you could controll that on your side before sending users to Paypal. I think you can control this via 'no_shipping' variable.
  • Dr. Piyush Dholariya
    Dr. Piyush Dholariya about 7 years
    I want pay_key in IPN response, not all these things, how can I do it?
  • Patanjali
    Patanjali over 6 years
    I thought that @TCM was using the return html variable to return to their site, in which case, the best first choice would be to use PDT, which returns the same values as IPN, but while in front of the customer, so the site can let them know it has been successfully fulfilled immediately. Of course, use IPN as a backup, as the customer may not return, but need to make sure it doesn't double supply.
  • PJ Brunet
    PJ Brunet over 6 years
    Please never link to Paypal documentation, they usually 404, and I'm finding several links on their own website that "have moved" and redirect to the homepage.
  • jamietelin
    jamietelin over 6 years
    @PJBrunet This answer is 8 years old.. Links are links. Of course I should link to more information. It is more Paypals problem that they are bad at handling their links than me linking to them. But all documents on internet are time sensitive, so links can be dead.
  • PJ Brunet
    PJ Brunet over 6 years
    @jamietelin I completely agree, it's Paypal's problem--that's what I meant, and I wasn't criticizing you, in fact just upvoted your answer. I specifically was looking for item_number and couldn't find much info from Paypal. For such a large company, as you maybe noticed, IMO they're not good at maintaining their website since they changed to their current "mobile" design. As far as item_number, what I found is if you have only one item, item_number isn't numbered like item_number1, item_number2... it's just item_number.