我第一次在其中一个项目中实现了 IPN 处理程序(从代码项目中粘贴它)。
问题在于用户可以使用一些电子邮件地址注册到我的网站,然后在付款时他可以使用一些不同的电子邮件地址
IPN 处理程序请求变量给出了用于支付的电子邮件地址。我应该如何找出哪个用户已经付款。
if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
string payerEmail = Request.Form["payer_email"];
string paymentStatus = Request.Form["payment_status"];
string receiverEmail = Request.Form["receiver_email"];
string amount = Request.Form["mc_gross"];
}
解决方案:
在支付处理页面中传递一些额外的可能是用户 ID,并假设它将在 IPN 处理程序中返回。
或者要求用户在付款前输入paypal邮箱地址。 (感觉不太好)
在这方面的任何帮助表示赞赏
最佳答案
我通常在购物车信息中发布一个自定义字段,用于标识我的本地交易或我的本地购物车。 IPN 会将自定义字段发回给您,以便您可以将交易与您的用户匹配。或者您可以只传递 USER_ID,然后不管交易如何取回它。
使用此字段在您的表单中向 paypal 发送您的自定义数据:
<input type="hidden" name="custom" value="YOUR_CUSTOM_INFO_HERE">
在回调中处理 IPN:
if (strcmp ($res, "VERIFIED") == 0) {
// This is the custom field i posted within the cart form.
$cid = $_POST['custom'];
$txn_id = $_POST['txn_id'];
$cart = load_cart_by_cid($cid);
if (!empty($cart)) {
// Fetch your user from cart and do things with it,
// along with your security checks.
$user = $cart->getUser();
// For example, store the transaction.
TransactionManager::saveTransaction($user, $txn_id);
}
}
源代码是 php,但我认为足够冗长,可以轻松翻译成 java、c# 或其他语言。
关于Paypal IPN 处理程序 - 如何知道谁的交易发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13082935/