【发布时间】: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