Ich bekomme immer eine ungültige Antwort. Hier ist mein Code:Erhalten Sie immer noch ungültige Antwort von PayPal
protected void Page_Load(object sender, EventArgs e)
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.Expect100Continue = true;
mclog.Info("entered PayPalListener Page_Load");
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
mclog.Info(string.Format("strSandbox = [{0}]", strSandbox));
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] Param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(Param);
strRequest = strRequest + "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
mclog.Info(string.Format("strRequest = [{0}]", strRequest));
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
mclog.Info(string.Format("Response was [{0}]", strResponse));
if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//Response wasn't VERIFIED or INVALID, log for manual investigation
}
ich die Log-Ausgabe enthalten habe und zitierte auch das Ergebnis auf der Sandbox-Seite angezeigt:
2016-07-19 16:16:54:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 entered PayPalListener Page_Load
2016-07-19 16:16:54:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strSandbox = [https://www.sandbox.paypal.com/cgi-bin/webscr]
2016-07-19 16:16:54:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strRequest = [payment_type=instant&payment_date=Wed%20Jul%2020%202016%2008%3A08%3A21%20GMT+0930%20%28AUS%20Central%20Standard%20Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&[email protected]&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&[email protected]&[email protected]&[email protected]&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=919215415¬ify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31Ak5zhWFvRQAir0SAm0lY6s-KEoQl&cmd=_notify-validate]
2016-07-19 16:16:55:448 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 Response was [INVALID]
Ich habe auch versucht Encoding.UTF8 sowohl in der Decodierung und Encodierung dies schlägt jedoch fehl, wenn es sowohl beim Empfangen als auch beim Senden verwendet wird, aber nicht nur beim Empfangen. Beim Senden von UTF8 schlägt der Handshake insgesamt fehl.
Codierung der gesamten Parameterzeichenfolge in einem Vorgang ist nicht korrekt. Sicherlich müssen Sie jeden Namen und Wert separat kodieren? – EJP
EJP: Ich habe beide Methoden mit dem gleichen Ergebnis ausprobiert. – David