gpt4 book ai didi

c# - PayPal 快速结帐在 MVC .net 中以 html 形式返回响应

转载 作者:太空狗 更新时间:2023-10-29 21:41:42 24 4
gpt4 key购买 nike

我有一个与 Paypal 快速结账集成的测试应用程序,它运行良好。但是现在好像有点问题。在 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+May+02%2C+2011+PDT&last_name=User&residence_country=CA&pending_reason=paymentreview&item_name=Payment+for+course+registration&payment_gross=&mc_currency=CAD&business =pramod_1298956597_biz%40sumerusolutions.com&payment_type=instant&protection_eligibility=Ineligible&payer_status=verified&verify_sign=Ag7LtkvrF1u9.1ScLJwRM4btR1G1A16qsCs-xUl6EpI1rE1UWpodXJsc&txn_id=15Y20623GD922445F&payer_email=pramod_1298961722_per%40sumerusolutions.com&tax=0.00&test_ipn=1&first_name=Test&receiver_email=pramod_1298956597_biz%40sumerusolutions.com&quantity=1&payer_id=Z2MRT3Q9L6E28&receiver_id=RT3M59WESZHEE&item_number=&payment_status=Pending&handling_amount= 0.00&shipping=0.00&mc_gross=850.00&custom=12&charset=windows-1252&notify_version=3.1&merchant_return_link=click+here&form_charset=UTF-8CONTEXT=wtgSziM4C5x0SI-9CmKcv2vkSeTLK5P_g6HqzC__YTYk cqziFNcB84p79Ja&myAllTextSubmitID=&cmd=_flow&transaction_subject=12&txn_type=web_accept&payment_date=01%3A59%3A21+May+02%2C+2011+PDT&last_name=User&residence_country=CA&pending_reason=paymentreview&item_name=Payment+for+course+registration&payment_gross=&mc_currency=CAD&business=pramod_1298956597_biz%40sumerusolutions.com&payment_type= instant&protection_eligibility=Ineligible&payer_status=verified&verify_sign=Ag7LtkvrF1u9.1ScLJwRM4btR1G1A16qsCs-xUl6EpI1rE1UWpodXJsc&txn_id=15Y20623GD922445F&payer_email=pramod_1298961722_per%40sumerusolutions.com&tax=0.00&test_ipn=1&first_name=Test&receiver_email=pramod_1298956597_biz%40sumerusolutions.com&quantity=1&payer_id=Z2MRT3Q9L6E28&receiver_id=RT3M59WESZHEE&item_number=&payment_status=Pending&handling_amount=0.00&shipping=0.00&mc_gross=850.00 &custom=12&charset=windows-1252&notify_version=3.1&merchant_return_link=click+here&form_charset=UTF-8&cmd=_notify-validate

最佳答案

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

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

  1. 在您的 PayPal 账户中激活“AutoReturn”和 PDT 功能。脚步:登录您的 Paypal 账户点击个人资料点击网站支付首选项将自动返回设置为开在返回 URL 文本框中输入有效的 URL将支付数据传输设置为开。记下显示的 PDT token 。滚动到页面底部并点击“保存”

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

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

    string authToken, txToken, query; 字符串 strResponse;

        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"))
    {

    }

关于c# - PayPal 快速结帐在 MVC .net 中以 html 形式返回响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com