支付成功,我们的数据与querystring数据匹配,但仍然落入INVALID状态

本文关键字:数据 状态 INVALID querystring 成功 我们 | 更新日期: 2023-09-27 18:01:49

为什么我写的ipn脚本总是失败?它总是无效的,即使它匹配所有的查询字符串paypal发送给我?

notification.cshtml ? tx = b78v54b5b55rby92S&圣= Completed& amt = 3.04, cc = USD&厘米=,item_number =, merchant_return_link =返回+ +网络+网站+ name& form_charset utf - 8 =

检查它的部分是:

string LiveURL = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LiveURL);
// Set request back values.
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] parameters = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string RequestString = System.Text.Encoding.ASCII.GetString(parameters);
RequestString += "&cmd=_notify-validate";
request.ContentLength = RequestString.Length;
// Send request to PP and get response.
StreamWriter Sout = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
Sout.Write(RequestString);
Sout.Close();
StreamReader Sin = new StreamReader(request.GetResponse().GetResponseStream());
string response = Sin.ReadToEnd();
Sin.Close();
if(result != null && result.OrderStatus == "Confirmed")
{
    switch(response)
    {
        case "VERIFIED":
            if(Request["st"] == "Completed")
            {
                var PPQuery = "SELECT TransactionId, OrderTotal FROM Orders WHERE OrderId = '" + Session["OSFOID"] + "' AND UserId = '" + WebSecurity.CurrentUserId + "'";
                var ppQueryResult = database.Query(PPQuery);
                foreach(var item in ppQueryResult)
                {
                    decimal fff = 3.04M;
                    if(item["TransactionId"] != Request["tx"])
                    {
                        if(item["OrderTotal"] == TotalPrice)
                        {
                            // Payment was a success. Convey that to the user.
                            output = "Thanks. Order complete.";
                        }
                        else
                        {
                            // Possible fraud. Log it.
                        }
                    }
                    else
                    {
                        // This is a duplicate transaction. Log it and Redirect to homepage.
                    }
                }
            }
            break;
        case "INVALID":
            output = "Invalid was returned. Investigate further.";
            break;
        default:
            output = "Other exception has occured. Investigate further and log.";
            break;
    }
}

支付成功,我们的数据与querystring数据匹配,但仍然落入INVALID状态

代码看起来很好。问题一定是response"VERIFIED"不匹配。

您不是碰巧在土耳其,并且在比较之前将response更改为大写?*

*)如果区域设置是Turkey,大写字符串将i变为İ,而不是I(只是字符串操作的许多陷阱之一)

在"VERIFIED"块中,检查:

if (Request.Params["payment_status"] == "Completed")
{
        ...
}

请求["st"]不正确。

一定要在PayPal管理员的一个地方设置IPN URL,不要同时使用其他形式的返回URL检查(不能立即记住它的名称)和IPN。

没有"merchant_return_link"参数;我觉得应该是"notify_url"……URL字符串和参数列表看起来不对;例如:&cm=&item_number

我知道你的参数列表将是你的情况下唯一的,但这里有一些示例代码,我构建的URL传递给PayPal:

protected string GetPayPalURL(string SERVER_URL, string business, string[] itemNames,
            int[] quantities, decimal[] amounts, double[] weight, string invoiceID, string transID, string NOTIFY_URL)
        {
            // Customer will be required to specify delivery address to PayPal - VERY IMPORTANT
            const string NO_SHIPPING = "2";
            StringBuilder url = new StringBuilder();
            url.Append(SERVER_URL + "?cmd=_cart&upload=1");
            url.Append("&business=" + HttpUtility.UrlEncode(business));
            for (int i = 0; i < itemNames.Length; i++)
            {
                url.Append("&item_name" + "_" + (i + 1).ToString() + "=" + HttpUtility.UrlEncode(itemNames[i]));
                url.Append("&quantity" + "_" + (i + 1).ToString() + "=" + quantities[i].ToString().Replace(",", "."));
                url.Append("&amount" + "_" + (i + 1).ToString() + "=" + amounts[i].ToString().Replace(",", "."));
                url.Append("&weight" + "_" + (i + 1).ToString() + "=" + weight[i].ToString().Replace(",", "."));
            }
            url.Append("&no_shipping=" + HttpUtility.UrlEncode(NO_SHIPPING));
            url.Append("&custom=" + HttpUtility.UrlEncode(invoiceID));
            url.Append("&txn_id=" + HttpUtility.UrlEncode(transID));
            url.Append("&notify_url=" + HttpUtility.UrlEncode(NOTIFY_URL));
            return url.ToString();
        }

我认为你正在尝试做的Paypal方法如下代码项目如果您得到payment_status = INVALID,则检查payment_reason

中的原因

我在代码中看不到你在哪里定义了在if中检查的结果,也在你检查请求的开关中,当然这应该是针对响应的?