Paypal标准方法

时间:2013-01-05 19:14:03

标签: paypal

对于我的项目,我一直在整合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>

1 个答案:

答案 0 :(得分: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吗? 无论如何,我建议您首先通过手动测试来检查您的侦听器URL是否有效 使用IPN测试工具(可在PayPal Sandbox

帐户中的“测试工具”下找到)