0

我正在使用沙盒模式。我有一个沙盒模式下的“立即购买”按钮,该按钮链接到我的沙盒业务帐户,该帐户已启用 ipn,并带有我网站的 URL。ipn实现与这里的示例代码完全相同:https ://cms.paypal.com/cms_content/GB/en_GB/files/developer/IPN_ASP_NET_C.txt

我单击按钮并使用成功的沙盒个人帐户进行购买。它在企业帐户 ipn 历史记录中显示为使用代码 200 发送,但在我网站的 ipn 页面上,响应无效。

已经在这几天了..无法弄清楚:(

4

1 回答 1

0

这是我用于https://ASPSecurityKit.net的内容

    private void ProcessPayment(bool test)
    {
        try
        {
           string callbackResponse = null;
            string content = null;
            string callbackUrl = test ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
            : "https://www.paypal.com/cgi-bin/webscr";

            var req = (HttpWebRequest) WebRequest.Create(callbackUrl);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            content = Encoding.ASCII.GetString(
                Request.BinaryRead(HttpContext.Request.ContentLength)
                );
            content += "&cmd=_notify-validate";
            req.ContentLength = content.Length;
                                                using (var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
            {
                streamOut.Write(content);
            }
            using (var streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
            {
            callbackResponse = streamIn.ReadToEnd();
            }


            if (callbackResponse.Equals("VERIFIED", StringComparison.OrdinalIgnoreCase))
            {
                // Now validate whether gross_amount is ok, receiver_email is your business acount mail id and so on.
            }
        }
        catch (Exception ex)
        {
            // Logger.Log(ex); // Uncomment this line if you have a logger
        }
    }

注意:我将所有交易都存储在数据库中,无论是可变的还是无效的。该逻辑是ASPSecurityKit.net特定的,因此我在这里省略了。

于 2013-08-10T20:57:40.557 回答