Paypal IPN 处理程序 - 如何知道谁的交易发生

标签 paypal paypal-ipn

我第一次在其中一个项目中实现了 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/

相关文章:

php - 如何在不使用 PHP 中的 Adaptive API 或 App ID 的情况下检查给定电子邮件是否为有效的 Paypal 电子邮件 ID

php - iPhone SDK 付款后,我的 php IPN 回调中缺少 POST 参数

mysql 在更新时表现得很奇怪。请帮忙,我已经坚持了一整天了

ios - 将 Phonegap 插件添加到 Xcode - 错误 : Plugin 'PayPalPlugin' not found, 或不是 CDVPlugin

html - 我如何使用定制的按钮类作为 Paypal 立即购买按钮?

Paypal IPN 返回在沙盒上验证,但在实时无效

paypal - 我需要 IPN 来处理预核准付款吗?

asp.net - 没有 IPN 的 Paypal 集成

ruby-on-rails - rails paypal 通知验证日语

paypal - "handling_cart"被 Paypal 忽略