【问题标题】:Pin Payments API - "Authentication failed because remote party has closed the transport stream"Pin Payments API - “身份验证失败,因为远程方已关闭传输流”
【发布时间】:2017-02-18 11:35:11
【问题描述】:

我正在尝试使用 Pin Payments 支付网关向我的网站添加付款。我的网站是在 MVC 中开发的,我正在使用 API 文档中建议的 PinPayments C# 库。

我读到说明的 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;
}

【问题讨论】:

    标签: c# asp.net-mvc api ssl payment-gateway


    【解决方案1】:

    Pin Payments 在他们的测试 API 上放弃了对 TLS 1.0 的支持,并将在 2017 年 1 月在他们的实时 API 上放弃它。您能否确认您是通过 TLS 1.1 或更高版本进行连接的?

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

    请随时通过 support@pi​​n.net.au 与我们联系以获得进一步的支持。

    【讨论】:

    • 感谢 Pin 付款。这就是问题所在。我不得不将库重建为 .net 4.5 并强制 GetWebRequest 方法使用 TLS 1.2
    猜你喜欢
    • 2015-08-20
    • 2013-03-24
    • 2017-08-18
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    相关资源
    最近更新 更多