paypal - 如何在同一表单中使用Paypal IPN通知和notify_url?

标签 paypal paypal-ipn

我正在使用这样的 Paypal 表单(付款正常)作为订阅计划,并且没有收到任何 IPN 通知,但是当我使用 Paypal 生成的标准 Paypal 表单时,带有 IPN 通知的所有内容都正常。有没有办法通过此表格获得 IPN?谢谢

这是我的表格。如果我从此表单中删除notify_url,我只能通过notify_url 或通过IPM 获取数据。

PS>主要问题!有没有办法同时使用 ipn + notify_url?示例?

<form action="https://www.paypal.com/a-bin/webscr" method="post" target="_top">

        <!-- Identify your business so that you can collect the payments. -->
        <input type="hidden" name="business" value="info@****.***">

        <!-- Specify a Buy Now button. -->
        <input type="hidden" name="cmd" value="_xclick-subscriptions">

        <!-- Specify details about the item that buyers will purchase. -->
        <table>
            <tbody><tr>
                <td>
                    <input type="hidden" name="on1" value="Mobile/Cell Phone number:"><strong>Mobile/Cell Phone number:</strong>
                </td>
                <td>
                    <input type="text" maxlength="200" name="os1" required="">
                </td>
            </tr>
            <tr>
                <td>
                    <input id="item_name" type="hidden" name="item_name" value="kp4">
                    <input id="item_number" type="hidden" name="item_number" value="1">
                    <label>Subscription Plans</label>
                </td>
                <td>
                    <!-- <input type="hidden" name="a3" value="5.00"> -->
                    <input data-name="kp4" data-id="1" type="radio" name="a3" value="0.01" checked=""> 0,01 /month <br>
                    <input data-name="kp5" data-id="2" type="radio" name="a3" value="0.02"> 0,01 /month <br>
                    <input data-name="kp6" data-id="3" type="radio" name="a3" value="0.03">0,01 /month <br>
                    <input data-name="kp7" data-id="4" type="radio" name="a3" value="0.04> 0,01 /month <br>
                    <input data-name="kp8+" data-id="5" type="radio" name="a3" value="0.05"> 0,05 /month <br>
                    <input type="hidden" name="p3" value="1"> 

                    <input type="hidden" name="t3" value="M">
                    <input type="hidden" name="src" value="1">
                    <input type="hidden" name="sra" value="1">
                    <input type="hidden" name="custom" value="ORG">
                </td>
            </tr>
        </tbody></table>
        <!-- Specify Currency Code -->
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="no_shipping" value="1">
        <input type="hidden" name="rm" value="2">

        <!-- Specify URLs -->
        <input type="hidden" name="notify_url" value="***payment-success.php?site_name=ORG">
        <input type="hidden" name="cancel_return" value="****payment-cancel.php">
        <input type="hidden" name="return" value="***payment-success.php">

        <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" alt="PayPal - The safer, easier way to pay online">
        <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
    </form>

最佳答案

PS> The main question! Is there a way to use both ipn + notify_url? Example?

简而言之:

但是能达到你想要的结果吗?

这个问题多年来一直困扰着 Paypal,现在仍然如此。

有一种非常流行的方法(对于那些知道的人来说)可以使用 php 和curl 来解决这个问题,并且由 Codeseekah 分发。 (不隶属)

The concept

An single IPN URL is setup for PayPal to notify your application of payments. The IPN handler code broadcasts PayPal’s payload to other IPN URLs you may have selectively or in bulk.

  • multiple PayPal IPN URLs now possible
  • no need to change any IPN code unless it filters requests by IP
  • can centralize IP filtering into the broadcast IPN, which means easier to maintain when PayPal’s IP ranges change
  • can centralize logging
  • can have queuing and rebroadcast if satellites (all your other IPN URLs) are unreachable

代码

此 IPN 广播代码采用 PHP 编写,但概念与语言无关。只需移植代码,它就会表现得同样好甚至更好。

<?php
  /*
   * This is a PayPal IPN (Instant Payment Notification) broadcaster
   * Since PayPal does not provide any straightforward way to add
   * multiple IPN listeners we'll have to create a central IPN
   * listener that will broadcast (or filter and dispatch) Instant
   * Payment Notifications to different destinations (IPN listeners)
   *
   * Destination IPN listeners must not panic and recognize IPNs sent
   * by this central broadcast as valid ones in terms of source IP
   * and any other fingerprints. Any IP filtering must add this host,
   * other adjustments made as necessary.
   *
   * IPNs are logged into files for debugging and maintenance purposes
   *
   * this code comes with absolutely no warranty
   * https://codeseekah.com
  */

  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 */
  $ipns = array(
      'mystore' => 'http://mystore.com/ipn.php',
      'myotherstore' => 'http://mybigstore.com/paypal_ipn.php',
      'myotherandbetterstore' => 'http://slickstore.com/paypal/ipn.php'
    );

  /* Fingerprints */

  if ( /* My Store IPN Fingerprint */
    preg_match( '#^\d+\|[a-f0-9]{32}$#', $_POST['custom'] ) /* Custom hash */
    and $_POST['num_cart_items'] == 2 /* alwayst 1 item in cart */
    and strpos( $_POST['item_name1'], 'MySite.com Product' ) == 0 /* First item name */
  ) $urls []= $ipns['mystore']; /* Choose this IPN URL if all conditions have been met */

  if ( /* My Other Store IPN Fingerprint */
    sizeof( explode('_', $_POST['custom']) ) == 7 /* has 7 custom pieces */
  ) $urls []= $ipns['myotherstore']; /* Choose this IPN URL if all conditions have been met */

  /* My Other And Better Store IPN Fingerprint */
  $custom = explode('|', $_POST['custom']);
  if (
    isset($custom[2]) and $custom[2] == 'FROM_OB_STORE' /* custom prefixes */
  ) $urls []= $ipns['myotherandbetterstore']; /* Choose this IPN URL if all conditions have been met */

  /* ... */


  /* 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(); /* Thank you, bye */

  /* 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';
  }
?>

全文位于https://codeseekah.com/2012/02/11/how-to-setup-multiple-ipn-receivers-in-paypal/

注意:作者非常活跃,回复了所有问题。

关于paypal - 如何在同一表单中使用Paypal IPN通知和notify_url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40981837/

相关文章:

PayPal 批量付款已停止。还有其他选择吗?

PayPal 按钮 IPN 处理

javascript - 使用 Javascript 更改表单信息?

ruby-on-rails - Ruby on Rails 如何构建支付模型来处理 Paypal REST SDK

paypal - 如何更改快速结帐上 "cancel and return to"链接中的名称

PayPal IPN - 自动返回

Paypal 沙箱给出内部服务器错误

php - 在我的本地服务器中用php模拟外部页面请求

curl - axios:在 axios 中传递 curl 的 -d

Paypal IPN 验证 - 尽管已到达成功页面但仍不起作用