Paypal IPN 检测退款,PHP

发布于 2024-10-18 22:46:53 字数 1383 浏览 3 评论 0原文

我正在 iDev 附属公司 paypal IPN 上进行一些定制工作,并且正在尝试设置退款项目的捕获。我的数据库工作正常,但我似乎无法正确捕获 IF 。

关于我应该将其更改为什么有什么建议吗?

if($_REQUEST["payment_status"] == "refunded"||$testing==1) 
{
    $email = $_REQUEST["payer_email"];
    $sid = $_REQUEST["subscr_id"];
    $tid = $_REQUEST["txn_id"];

    if (!$tid)
    {
        $tid='xxx';
    }

    if ($testing==1)
    {
        echo  "testing on";
        $sid = "I-E5E34E0DTMUS"; 
    }

    $query = "SELECT * FROM idevaff_sales WHERE tid1='$tid'";
    $result = mysql_query($query);
    if (!$result)
    {
        //echo $query; exit;
        mail('***@gmail.com',"1",$query); 
    }

    $arr = mysql_fetch_array($result);
    $aid = $arr['id'];

    $query = "SELECT * FROM idevaff_affiliates WHERE tid1='$tid'";
    $result = mysql_query($query);
    if ($result)
    {
        //echo $query; 
        mail('***@gmail.com',"2","$query"); 
    }

    $arr = mysql_fetch_array($result);
    $email = $arr['email'];
    $f_name = $arr['f_name'];

    mail($email,"Affiliate Message - A refund has granted for recent affiliate commission.","Dear $f_name,  \n\n Message here about refund" );

    $query = "UPDATE idevaff_sales SET approved=3 WHERE tracking='$sid'";
    $result = mysql_query($query);
    if (!$result)
    {
        //echo $query; exit;
        mail('***@gmail.com',"3","$query"); 
    }
}

哈德逊

I'm doing some custom work on the iDev affiliate paypal IPN and I am trying to set up a catch for refunded items. I have my database work correct, but I can't seem to get the IF catch right.

Any advise on what I should change it to?

if($_REQUEST["payment_status"] == "refunded"||$testing==1) 
{
    $email = $_REQUEST["payer_email"];
    $sid = $_REQUEST["subscr_id"];
    $tid = $_REQUEST["txn_id"];

    if (!$tid)
    {
        $tid='xxx';
    }

    if ($testing==1)
    {
        echo  "testing on";
        $sid = "I-E5E34E0DTMUS"; 
    }

    $query = "SELECT * FROM idevaff_sales WHERE tid1='$tid'";
    $result = mysql_query($query);
    if (!$result)
    {
        //echo $query; exit;
        mail('***@gmail.com',"1",$query); 
    }

    $arr = mysql_fetch_array($result);
    $aid = $arr['id'];

    $query = "SELECT * FROM idevaff_affiliates WHERE tid1='$tid'";
    $result = mysql_query($query);
    if ($result)
    {
        //echo $query; 
        mail('***@gmail.com',"2","$query"); 
    }

    $arr = mysql_fetch_array($result);
    $email = $arr['email'];
    $f_name = $arr['f_name'];

    mail($email,"Affiliate Message - A refund has granted for recent affiliate commission.","Dear $f_name,  \n\n Message here about refund" );

    $query = "UPDATE idevaff_sales SET approved=3 WHERE tracking='$sid'";
    $result = mysql_query($query);
    if (!$result)
    {
        //echo $query; exit;
        mail('***@gmail.com',"3","$query"); 
    }
}

Hudson

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走走停停 2024-10-25 22:46:53

这是我最终成功使用的:

if($_REQUEST["payment_status"] == "Refunded" || $_REQUEST["payment_status"] == "Reversed"  || $testing==1)  
{
    /*do database work here*/
}

Here is what I ended up using successfully:

if($_REQUEST["payment_status"] == "Refunded" || $_REQUEST["payment_status"] == "Reversed"  || $testing==1)  
{
    /*do database work here*/
}
森末i 2024-10-25 22:46:53

我目前正在与 PayPal 协商此事。
问题是,有时您会收到以下消息序列:

  • 已完成(销售)
  • 已撤销(买家投诉)

有时您会收到:

  • 已完成(销售)
  • 已退款(买家向您投诉,您在没有“官方”投诉的情况下退款)

有时您会收到this:

  • Completed (sale)
  • Reversed (买家投诉)
  • Refunded (您在投诉后退款)

因此,除非 PayPal 同意实施我的解决方案,以便在后一个示例中的 Refunded 之前始终发送 Canceled_Reversal (几年前的情况),或者来如果有另一种解决方案可以为此事提供一定的确定性,您需要使用自己的机制来避免重复计算退款。

如果您将事务存储在数据库中,从我的角度来看,以下内容可能非常可靠:

if (($stat == 'Refunded' || $stat == 'Reversed') && !empty($_POST['parent_txn_id'])) 
{
  $sum = $db->query('SELECT SUM(`mc_gross`) FROM `transactions` WHERE `parent_txn_id`= ?', $_POST['parent_txn_id'])->fetchColumn();
  if ($sum && $sum < 0) {
    // already had reversed/refunded call,
    // ignore this one
  }
}

I am currently negotiating the matter with PayPal.
The thing is that sometimes you would get this sequence of messages:

  • Completed (sale)
  • Reversed (buyer complaint)

Sometimes you get this:

  • Completed (sale)
  • Refunded (buyer complained to you, and you refunded without "official" complaint)

Sometimes you get this:

  • Completed (sale)
  • Reversed (buyer complaint)
  • Refunded (you refunded after complaint)

So, unless PayPal agrees to implement my solution to always send Canceled_Reversal before Refunded in the latter example (which was the case a few years ago), or comes up with another solution that will provide some certainty on the matter, you need to use your own mechanisms not to double-count a refund.

If you store transactions in a DB, the following may be pretty solid, from my POV:

if (($stat == 'Refunded' || $stat == 'Reversed') && !empty($_POST['parent_txn_id'])) 
{
  $sum = $db->query('SELECT SUM(`mc_gross`) FROM `transactions` WHERE `parent_txn_id`= ?', $_POST['parent_txn_id'])->fetchColumn();
  if ($sum && $sum < 0) {
    // already had reversed/refunded call,
    // ignore this one
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文