简体   繁体   中英

Paypal IPN: Update the value of a column after payment?

I have 2 documents:

  1. index.php
  2. thankyou.php

In index.php the user submits his email (I save it into my database table column called 'email') and then goes to PayPal and he does the payment. Then with thankyou.php I want to update my database where the email column is, the column is called premium, the default is 0 now after the payment it should be 1...

The easy way could be saying WHERE the email (submitted in index.php) comparing it to the 'payer_email' submitted in Paypal payment. How can I do this? Sessions? Cookies? They seem not to be working for me, how can I do this? Thanks in advance.

You don't need any session nor cookie, just use a regular UPDATE ... SET premium = 1 WHERE email = :1 with :1 being $_POST['payer_email'] .

I understand that you're not sure whether the email you have in your records is the email the buyer is using to login to paypal, therefore you have to use the custom field paypal leaves at your disposal. Do as following:

  1. Record the client id in your database
  2. Create the paypal button adding the following field:

<input type="hidden" name="custom" value="yourclientid">

  1. When receiving the ipn, retrieve the custom field using $_POST['custom'] and update your database using this unique correspondency, so you don't have to wonder which email has been used.

Please note that is valid for paypal common "buy" buttons. For subscriptions things could be slightly different since after the first ipn the custom field is not passed anymore.

Hope it helped. S.

The sequence of events is covered in PayPal's API documentation. I would suggest that you read it to understand how the process works.

To get you started, you need to register the return URL (thankyou.php) with PayPal, and then the Instant Payment Notification (IPN) will be submitted to the registered URL as a POST object, you should verify the POST object with PayPal to ensure it is valid, after which you can parse the fields, and extract whatever data you need to complete your own process as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM