【问题标题】:Paypal multiple IPN setupPaypal 多个 IPN 设置
【发布时间】:2012-12-09 17:27:01
【问题描述】:

在使用 IPN 来假设 3 个网站时,我并不是 100% 清楚这一点,如果有知识的人可以根据我的情况向我解释这一点,我将不胜感激。

我已设置我的 sanbox 测试业务帐户以使用 IPN 侦听器:site1.com/listener.php(工作正常)。

我想知道如何使用同一个贝宝帐户为我的其他网站设置更多听众。

在我的场景中,我正在为所有网站仅订阅付款。

问题 1: ipn_notification_url 变量。 如果设置了此变量,是否会在付款时告诉贝宝,始终将其用作侦听器 ipn url?例子;如果下个月付款时订阅失败或类似情况?

所以当paypal需要IPN我的监听器时,它会使用变量中的监听器而不是帐户配置文件设置中的设置url?或者这个变量是否只用于处理蜜蜂时的实际付款?

问题 2: 如果需要有一个主侦听器来处理转发到正确的侦听器 url,是否可以将网站区分开来?示例:custom = userId,receiver_id = Sitename

问题 2 实际上与问题 1 类似。POSTED 变量 是否会从初始付款,坚持到付款 将在未来自动为我的订阅.这样当 paypal 需要向我发送 IPN 更新时,它将始终使用我在初始付款时设置的变量中的 url??

感谢您对此的任何启发。

【问题讨论】:

    标签: php paypal-ipn


    【解决方案1】:

    我从http://codeseekah.com/ 找到了这个脚本,它可以让您设置多个 PayPal IPN 侦听器。它允许您过滤通知,这意味着您可以根据设置的条件发送给不同的侦听器(非常有用!):

    <?php
    
        ini_set( 'max_execution_time', 0 ); // Do not abort with timeouts
        ini_set( 'display_errors', 'Off' ); // Do not display any errors to anyone
        $urls = array(); // The broadcast session queue
    
        // List of IPN listener points ** ADJUST THESE TO POINT TO YOUR LISTENERS
        $ipns = array(
                'first' => 'http://www.yourwebsite1.co.uk//paypal/ipn.php',
                'second' => 'http://www.yourwebsite2.co.uk//paypal/ipn.php',
                'third' => 'http://www.yourwebsite3.co.uk//paypal/ipn.php'
            );
    
        // ** ADJUST THESE CONDITIONS TO FILTER 
        if($_POST['txn_type']!='cart') $urls []= $ipns['first']; // Choose this IPN URL if all conditions have been met
        if(isset($_POST['auction_buyer_id'])) $urls []= $ipns['second']; // Choose this IPN URL if all conditions have been met
        $urls []= $ipns['third']; // maybe this one is always sent to
    
        // Broadcast
        if ( !sizeof($urls) ) $urls = $ipns; // No URLs have been matched
        $urls = array_unique( $urls ); // Unique, just in case
    
        // Broadcast (excluding IPNs from the list according to filter is possible
        foreach ( $urls as $url ) broadcast( $url );
    
        header( 'HTTP/1.1 200 OK', true, 200 );
        exit();
    
        // Perform a simple cURL-powered proxy request to broadcast
        function broadcast( $url ) {
    
            // Format POST data accordingly
            $data = array();
            foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
            $data = implode('&', $data);
    
            // Log the broadcast
            file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
    
            $ch = curl_init(); // Initialize
    
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, count($data));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
            curl_exec($ch); // Execute HTTP request
            curl_close($ch); // Close
        }
    
        function reverse_lookup( $url ) {
            global $ipns;
            foreach ( $ipns as $tag => $_url ) {
                if ( $url == $_url ) return $tag;
            }
            return 'unknown';
        }
    ?>
    

    只需自定义您需要的部分(使用 **s),将其保存在一个文件中,例如名为“multiple-paypal-ipn.php”的文件,然后将其放在您的一台服务器上。然后在您的 PayPal IPN URL 设置(在 PayPal 中)输入您刚刚放置的完整 URL,例如http://www.yourwebsite/paypal/multiple-paypal-ipn.php

    这为我节省了很多时间,所以希望对其他人有用!_g

    【讨论】:

      【解决方案2】:

      您可以通过表单中的隐藏输入元素提供三个 URL,它们的名称如下:

      1. notify_url:这是 此次购买的所有通知将发送到的 URL。
      2. return:这是用户成功完成结帐后返回的 URL。
      3. cancel_return:这是用户在 paypal 取消结帐时返回的 URL。

      因此,如果您在按钮中使用notify_url,则每个站点、每个按钮甚至每个按钮渲染都可能不同,如果您有这样的用途的话。

      请注意,notify_url 会覆盖您在付款首选项中设置的任何内容。

      关于(2),您还可以提供rm 变量,如下所示:

      0:通过 GET 返回用户 1:用户通过 GET 返回,没有支付变量。 2. 通过 PUT 返回用户并返回所有付款变量,即作为按钮发送到 PayPal 的回声。

      我不清楚 0 和 1 之间的区别。

      见PayPal HTML Variables。

      编辑在我现在找不到的 SO 的另一个答案中,一位 PayPal 人员表示您可以在 notify_url 本身中传递任意参数,这将与您发送它们的方式相同。

      【讨论】:

        猜你喜欢
        • 2012-01-17
        • 2012-02-23
        • 2013-07-28
        • 2020-07-14
        • 2011-12-26
        • 2015-04-10
        • 2020-12-18
        • 2018-02-11
        • 2016-02-08
        相关资源
        最近更新 更多