【问题标题】:Paypal IPN handler- how to know whose transaction takes placePaypal IPN 处理程序 - 如何知道谁的交易发生
【发布时间】:2012-10-16 11:36:16
【问题描述】:

我第一次在其中一个项目中实现了 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邮箱地址。 (感觉不好)

感谢您提供这方面的任何帮助

【问题讨论】:

    标签: paypal paypal-ipn


    【解决方案1】:

    我通常在购物车信息中发布一个自定义字段,用于标识我的本地交易或我的本地购物车。 IPN 会将该自定义字段发回给您,以便您可以将交易与您的用户进行匹配。或者您可以只传递 USER_ID,然后无论交易如何都将其取回。

    使用此字段将您的自定义数据发送到您的表单中:

    <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# 或其他方式翻译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-12
      • 2012-03-09
      • 2012-11-02
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      • 2012-03-05
      • 2012-11-16
      相关资源
      最近更新 更多