0

对于我的项目,我一直在集成 PayPal 沙箱。我已将以下代码用于标准方法。但我无法收到来自 PayPal 的通知电话(notify-url)。怎么了?

<form id="form1" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" style="display:none;"  accept-charset="utf-8">
  <input type="hidden" name="business" value="test2_biz@gmail.com" />
  <input type="hidden" name="cmd" value="_cart" />
  <input type="hidden" name="paymentaction" value="sale" />
  <input type="hidden" name="item_name_1" value="lap" />
  <input type="hidden" name="amount_1" value="1" />
  <input type="hidden" name="quantity_1" value="1" />
  <input type="hidden" name="first_name" value="1" /><!--customer first name -->
  <input type="hidden" name="last_name" value="1" /><!--customer last name -->
  <input type="hidden" name="address1" value="1" /><!--customer address 1 name -->
  <input type="hidden" name="address2" value="1" /><!--customer add2 name -->
  <input type="hidden" name="email" value="dfd@rr.ee" /><!--customer email name -->
  <input type="hidden" name="city" value="1" /><!--customer city name -->
  <input type="hidden" name="state" value="1" /><!--customer state name -->
  <input type="hidden" name="country" value="1" /><!--customer country name -->
  <input type="hidden" name="zip" value="1" /><!--customer zip name -->
  <input type="hidden" name="currency_code" value="USD" /><!--currrecy in which payment u need-->
  <input type="hidden" name="upload" value="1" /><!--paypal parameter-->
  <input type="hidden" name="return" value="HOST_NAME/default/index/order-return" />
  <input type="hidden" name="cancel_return" id="cancel_return" value="" />
  <input type="hidden" name="notify_url" id="notify_url" value="HOST_NAME/default/index/notify-url/order/222">
  <input type="submit" value="submit">
  </form>
4

1 回答 1

0

正如我在评论中写给你的那样,你应该有一个适当的 IPN 侦听器和 PayPal 的消息验证,以认为对你的 URL 的调用是成功的。这是一个基本监听器的粗略示例:

    <?php

    function validateIpnMessage() {
        $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&".http_build_query($_POST));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

        if( !curl_errno($ch)) {
            $res = curl_exec($ch);
            curl_close($ch);
            if ($res === "VERIFIED") {
                return TRUE;
            }
        }

        return FALSE;
    }


    if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
        if(validateIpnMessage()) {
            // THE MESSAGE IS VALIDATED

            // REST OF YOUR CODE GOES HERE
        }
    }
?>

您是否确保在您的个人资料中启用了 IPN?无论如何,我建议您首先通过使用 IPN 测试工具手动测试来检查您的侦听器 URL 是否有效(可在您的PayPal Sandbox帐户中的“测试工具”下找到)

于 2013-01-05T19:31:45.963 回答