Pin Payments API - “身份验证失败,因为远程方已关闭传输流”

时间:2016-10-10 05:12:23

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

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

我读到所述的api文档只接受安全连接。所以我在我的解决方案中启用了SSL。然后,我确保IIS Express生成的自签名证书已添加到我的可信证书中。在我信任证书之后,它工作了一次。但从那时起它一直在失败。它在以下错误消息之间交替显示。没有我对代码进行任何更改。

远程主机强行关闭现有连接

身份验证失败,因为远程方已关闭传输流。

这是我发出请求的代码。卡和费用是没有错误建立的,然后它运行线ChargeResponse响应= ps.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 Payments Library中的代码。它运行第一行,然后跳转到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 个答案:

答案 0 :(得分:1)

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

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

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