6

我将测试应用程序与 Paypal 快速结帐集成在一起,并且运行良好。但现在似乎有些问题。当我的 IPN 处理程序检查响应 paypal 将响应返回为 html 页面而不是“已验证”或“无效”时,在贝宝上成功付款后,因此我无法验证付款。Paypal 最近是否有任何关于快速结账的变化?下面是完整的代码

<form id="Paypal" name="Paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr"
    method="post">
    @Html.Hidden("cmd", "_xclick")
    @Html.Hidden("business", "myemail@test.com")
    @Html.Hidden("item_name", "Payment for course registration")
    @Html.Hidden("amount", 100 )
    @Html.Hidden("no_shipping", "1")
    @Html.Hidden("return", "http://localhost:49319/cart/IPN")
    @Html.Hidden("rm", "2")
    @Html.Hidden("notify_url", "http://localhost:49319/cart/IPN")
    @Html.Hidden("cancel_return", "http://localhost:49319/cart/PaymentFailure")
    @Html.Hidden("currency_code", "CAD")
    @Html.Hidden("tax_cart", "1")
    @Html.Hidden("custom", "12")
    <div class="checkout-button">
        <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"
            align="left" style="margin-right: 7px;" />
    </div>
    </form>

IPN 处理程序代码:

 string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
            : "https://www.paypal.com/cgi-bin/webscr";


        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);

        // Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";

        byte[] param = Request.BinaryRead(Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);

        StringBuilder sb = new StringBuilder();
        sb.Append(strRequest);

        foreach (string key in formVals.Keys)
        {
            sb.AppendFormat("&{0}={1}", key, formVals[key]);
        }
        strRequest += sb.ToString();
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://urlort#");
        //req.Proxy = proxy;
        //Send the request to PayPal and get the response
        string response = "";
        using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
        {

            streamOut.Write(strRequest);
            streamOut.Close();
            using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
            {
                response = streamIn.ReadToEnd();
            }
        }

        return response;

编辑:这是发送到 Paypal 的请求字符串

CONTEXT = wtgSziM4C5x0SI-9CmKcv2vkSeTLK5P_g6HqzC__YTYkcqziFNcB84p79Ja&myAllTextSubmitID = CMD = _flow&transaction_subject = 12&txn_type = web_accept&PAYMENT_DATE = 01%3A59%3A21 +月+ 02%2C + 2011 + PDT&姓氏=用户&residence_country = CA&pending_reason = paymentreview&ITEM_NAME =付款+为+当然+登记&payment_gross =&mc_currency = CAD&业务= pramod_1298956597_biz% 40sumerusolutions.com&payment_type =即时与protection_eligibility =不合格的&payer_status =验证的&verify_sign = Ag7LtkvrF1u9.1ScLJwRM4btR1G1A16qsCs-xUl6EpI1rE1UWpodXJsc&txn_id = 15Y20623GD922445F&PAYER_EMAIL = pramod_1298961722_per%40sumerusolutions.com&税= 0.00&的test_ipn = 1&FIRST_NAME =测试与RECEIVER_EMAIL = pramod_1298956597_biz%40sumerusolutions.com和数量= 1&payer_id = Z2MRT3Q9L6E28&receiver_id = RT3M59WESZHEE&ITEM_NUMBER = PAYMENT_STATUS =待定&handling_amount = 0.00及运送= 0.00&mc_gross = 850.00和定制= 12&的charset =窗口1252&notify_version = 3.1&merchant_return_link =点击+这里与form_charset = UTF-8CONTEXT = wtgSziM4C5x0SI-9CmKcv2vkSeTLK5P_g6HqzC__YTYkcqziFNcB84p79Ja&myAllTextSubmitID = CMD = _flow&transaction_subject = 12&txn_type = web_accept&PAYMENT_DATE = 01%3A59% 3A21 +月+ 02%2C + 2011 + PDT&姓氏=用户&residence_country = CA&pending_reason = paymentreview&ITEM_NAME =付款+为+当然+登记&payment_gross =&mc_currency = CAD&业务= pramod_1298956597_biz%40sumerusolutions.com&payment_type =即时&protection_eligibility =不合格的&payer_status =验证的&verify_sign = Ag7LtkvrF1u9.1ScLJwRM4btR1G1A16qsCs-xUl6EpI1rE1UWpodXJsc&txn_id = 15Y20623GD922445F&PAYER_EMAIL = pramod_1298961722_per%40sumerusolutions.com&税= 0.00&的test_ipn = 1&如first_name =测试&RECEIVER_EMAIL = pramod_1298956597_biz%40sumerusolutions.com&量= 1&payer_id = Z2MRT3Q9L6E28&receiver_id = RT3M59WESZHEE&ITEM_NUMBER =&PAYMENT_STATUS =待定&handling_amount = 0.00及运送= 0.00&mc_gross = 850.00&定制= 12&字符集=窗口1252&notify_version = 3.1&merchant_return_link =点击+这里&form_charset=UTF-8&cmd=_notify-validate00&mc_gross=850.00&custom=12&charset=windows-1252¬ify_version=3.1&merchant_return_link=click+here&form_charset=UTF-8&cmd=_notify-validate00&mc_gross=850.00&custom=12&charset=windows-1252¬ify_version=3.1&merchant_return_link=click+here&form_charset=UTF-8&cmd=_notify-validate

4

5 回答 5

5

行。经过大量试验和错误并在贝宝论坛上发布此问题后,我的支付网关开始工作。虽然我对这个解决方案并不满意。解决方案是使用 PDT,不使用 IPN。我从贝宝支持得到的回复是“问题是 IPN 是一个额外的通知系统,它有一点延迟。所以它不是 100% 的自动返回页面的完美解决方案。”

Paypal 建议我使用 PDT,它现在正在工作。我将步骤放在这里,以便它可以帮助同样面临此类问题的人:

  1. 在您的 PayPal 帐户中激活“自动退货”和 PDT 功能。步骤: 登录到您的 PayPal 帐户,点击个人资料,点击网站支付首选项,将自动返回设置为打开,在返回 URL 文本框中输入有效的 URL,将支付数据传输设置为打开。记下显示的 PDT 令牌。滚动到页面底部,然后单击“保存”

  2. 将以下参数传递给 paypal cmd、business、item_name、amount、return、currency_code、custom。

  3. 用 PDT 代码更改 IPN 处理程序代码,在我的情况下,PDT 代码如下 -

    字符串 authToken、txToken、查询;字符串str响应;

        authToken = ConfigurationManager.AppSettings["PDTToken"];
    
        //read in txn token from querystring
        txToken = Request.QueryString.Get("tx");
    
    
        query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken);
    
        // Create the request back
        string url = ConfigurationManager.AppSettings["PayPalUrl"];
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    
        // Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = query.Length;
    
        // Write the request back IPN strings
        StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        stOut.Write(query);
        stOut.Close();
    
        // Do the request to PayPal and get the response
        StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
        strResponse = stIn.ReadToEnd();
        stIn.Close();            
    
        // If response was SUCCESS, parse response string and output details
        if (strResponse.StartsWith("SUCCESS"))
        {
    
        }
    
于 2011-05-05T05:36:14.590 回答
0

您需要向自己展示正在返回的 html。您的帐户很可能被暂停或发生了什么,而 Paypal 正在对您做出回应。你能告诉我们那个 HTML 吗?

于 2011-04-21T14:38:55.503 回答
0

首先,我建议你去Paypal 开发者支持网站。虽然他们可能需要很短的时间来回应您的问题,但那里的人对 Paypal 非常有经验,我相信他们能够给您答案。

关于您的特定问题,并且根据我的 Paypal 经验,我相信有两种类型的 Paypal 帐户。

第一种类型的帐户允许您的网站充当第三方 - 即:

  • 用户在您的网站上提交付款信息
  • 您的网站与 Paypal 通信,收到回复
  • 您可以在您的网站上向用户显示该响应

这显然是你想要做的。

但是,我相信还有第二种类型的 Paypal 帐户。此帐户可能更便宜,限制性要求/条款和条件更少,或者更易于集成(否则我不确定为什么会选择它)。我相信这个帐户需要您的网站将用户重定向到 Paypal,在那里他们会得到响应。

  • 用户提交支付信息
  • 您将他们重定向到 Paypal
  • 他们会看到付款状态或其他消息,然后可以单击链接返回您的(供应商)网站。

我可能是错的,但这是我使用 Paypal API 的回忆。我强烈建议您访问上面链接的 Paypal 开发者网站。

于 2011-05-03T06:41:52.523 回答
0

我在尝试设置 IPN 时遇到了同样的问题......当我从沙箱发送“echeck”时它会正常工作,它会返回 VERIFIED,但是当我尝试进行快速结帐时,它不会返回已验证或无效。 ..它返回的东西与echeck完全不同......它很奇怪。

我将尝试询问技术支持这两种服务有什么区别。

于 2011-09-15T03:10:42.450 回答
0

IPN 确实可以从 C# 工作,我遇到了和你一样的问题(得到一个要求我登录的 HTML 页面),然后我发现我在返回 PayPal 的帖子中缺少以下变量

cmd=_notify-validate

一旦我正确添加,对 PayPal 的请求就会按预期工作。

要确保的另一件事是,您将在 IPN 请求中收到的变量传回,只需将上述命令附加到回发的开头即可。

我没有使用 MVC,但我正在使用 WCF 执行此操作,它就像一个魅力。

希望有帮助。

于 2011-10-31T21:29:37.867 回答