我試圖使用PIN付款付款網關將付款添加到我的網站。我的網站正在使用MVC開發,我正在使用API文檔中建議的PinPayments C#庫。付款API - 「身份驗證失敗,因爲遠程方關閉了傳輸流」
我讀到說明的api文檔只接受安全連接。所以我在我的解決方案中啓用了SSL。然後,我確保將IIS Express生成的自簽名證書添加到我的可信證書中。它在我信任證書後一次工作。但從那以後它一直在失敗。它在以下錯誤消息之間交替。沒有我對代碼進行任何更改。
一個現有的連接被強行遠程主機
和
驗證失敗,因爲遠程方已關閉傳輸流關閉。
這是我的代碼,使請求。卡和充電建立沒有錯誤,然後去運行ChargeResponse response = ps.Charge(charge);.然後它跳轉到pinpayments庫請求者代碼(下面)。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreditCard (CreditCardPayment model)
{
if (ModelState.IsValid)
{
// get application
Application application = db.Applications.Find(model.ApplicationdId);
if (application != null)
{
PinService ps = new PinService(ConfigurationManager.AppSettings["Secret_API"]);
var card = new Card();
card.CardNumber = model.Number;
card.CVC = model.Cvn;
card.ExpiryMonth = model.ExpiryMonth;
card.ExpiryYear = model.ExpiryYear;
card.Name = model.Name;
card.Address1 = model.AddressLine1;
card.City = model.City;
card.Country = model.Country;
var charge = new PostCharge();
charge.Description = "Visa Application " + application.Destination;
charge.Amount = Convert.ToInt64(application.Total) * 100; // Pin payments requires the value in cents
charge.Card = card;
charge.Currency = application.CurrencyCode;
charge.Email = application.Customer.Email;
charge.IPAddress = "127:0:0:1"; //Request.UserHostAddress;
ChargeResponse response = ps.Charge(charge);
if (response.Charge != null && response.Charge.Success)
{
// Update application with payment details.
}
else
{
// Do error stuff
}
}
}
return View(model);
}
以下是PIN付款庫中代碼失敗的代碼。它運行第一行,然後跳轉到var requestStream = request.GetRequestStream();與錯誤消息一致。
private static WebRequest GetWebRequest(string url, string method, string postData)
{
var request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Method = method;
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "C# API Wrapper v001";
string apiKey = PinPaymentsConfig.GetApiKey();
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(apiKey + ":"));
if (postData != "")
{
var paramBytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = paramBytes.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
return request;
}
感謝PIN付款。這是問題。我必須重建庫爲.net 4.5,並強制GetWebRequest方法使用TLS 1.2 – Andrew