简体   繁体   English

Paypal IPN:付款后更新列的值?

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

I have 2 documents: 我有2个文件:

  1. index.php index.php
  2. thankyou.php 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. 用户在index.php中提交他的电子邮件(我将其保存到名为“ email”的数据库表列中),然后转到PayPal进行付款。 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... 然后使用thankyou.php我要更新我的数据库,其中电子邮件列是该列,该列称为premium,默认值为0,现在付款后应为1 ...

The easy way could be saying WHERE the email (submitted in index.php) comparing it to the 'payer_email' submitted in Paypal payment. 最简单的方法可能是,将电子邮件(在index.php中提交)与Paypal付款中提交的“ payer_email”进行比较。 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'] . 您不需要任何会话或cookie,只需使用常规的UPDATE ... SET premium = 1 WHERE email = :1其中:1是$_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. 我们了解您不确定自己记录中的电子邮件是否是买方用于登录Paypal的电子邮件,因此您必须使用自定义字段Paypal叶子供您使用。 Do as following: 执行以下操作:

  1. Record the client id in your database 在数据库中记录客户端ID
  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. 接收ipn时,请使用$_POST['custom']检索自定义字段,并使用此唯一的对应关系更新数据库,因此您不必怀疑已使用了哪个电子邮件。

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. 对于订阅,情况可能略有不同,因为在第一个ipn之后,不再传递custom字段。

Hope it helped. 希望能有所帮助。 S. S.

The sequence of events is covered in PayPal's API documentation. PayPal的API文档中介绍了事件的顺序。 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. 首先,您需要在PayPal中注册返回URL(thankyou.php),然后即时付款通知(IPN)将作为POST对象提交到注册的URL,您应该使用PayPal验证POST对象以确保它是有效的,然后您可以解析字段,并提取所需的任何数据以根据需要完成自己的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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