gpt4 book ai didi

c# - Pin 支付 API - "Authentication failed because remote party has closed the transport stream"

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:43 25 4
gpt4 key购买 nike

我正在尝试使用 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;
}

最佳答案

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 与我们联系。

关于c# - Pin 支付 API - "Authentication failed because remote party has closed the transport stream",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39951628/

25 4 0