2016-10-10 19 views
0

我试图使用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; 
} 

回答

1

引脚支付他们的测试API支持下降TLS 1.0,而你能否确认您是通过TLS 1.1或以上的连接将一月2017年下降在他们的生活API?

请注意,TLS 1.1和1.2支持仅在.NET 4.5中添加。

欢迎随时通过[email protected]​​n.net.au与我们联系以获得进一步支持。

+0

感谢PIN付款。这是问题。我必须重建库为.net 4.5,并强制GetWebRequest方法使用TLS 1.2 – Andrew

相关问题