c# - Apple Pay 网页版 - 商户验证问题
问题描述
背景: 我在我们的网站上使用 Authorize.NET 作为支付处理器在网络上实施 Apple Pay。我正在使用 .NET 框架 4.8。我们完成了一些初始设置,例如获取商家 ID、为我们的产品和测试网站添加和验证商家域。我们获得了商家身份证书并将其安装在我们的测试服务器上。
问题: 我在调用验证 url 以获取商家会话对象时遇到以下问题。我按照https://tech.justeattakeaway.com/2016/10/10/bringing-apple-pay-to-the-web/文章进行实施。
代码的主要摘录如下。它在“httpClient.SendAsync”调用中失败。对我来说,这似乎是一个 TLS 问题,但我已经将其设置为 1.2,并且我们的测试服务器也启用了 TLS1.2。因此,我不确定我到底错过了什么。任何帮助将不胜感激。谢谢你。
var validationURL = "https://apple-pay-gateway.apple.com/paymentservices/startSession";
if (!Uri.TryCreate(validationURL, UriKind.Absolute, out Uri requestUri))
{
throw new UserInputException("An error occurred while serving your request. Please try again later");
}
MerchantCertificate mc = new MerchantCertificate(new ApplePayOptions() { UseCertificateStore = true, MerchantCertificateThumbprint = "5cdf3xxxxxxxxx345345" });
ApplePayClient applePayClient = new ApplePayClient(mc.GetCertificate());
var extension = applePayClient._certificate.Extensions["1.2.840.113635.100.6.32"];
var merchantId = System.Text.Encoding.ASCII.GetString(extension.RawData).Substring(2);
var request = new MerchantSessionRequest()
{
DisplayName = "My Store",
Initiative = "web",
MerchantIdentifier = merchantId,
InitiativeContext = "example.com"
};
Task<HttpResponseMessage> sessionReq = applePayClient.GetMerchantSessionAsync(requestUri, request);
public async Task<HttpResponseMessage> GetMerchantSessionAsync(Uri requestUri, MerchantSessionRequest request)
{
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(_certificate);
var httpClient = new HttpClient(handler, true);
//Set security protocol to TLS 1.2 only (REQUIRED by Apple Pay)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//Post the validation data object to the Apple Pay web service through secure channel
var requestData = CreateContentRequest<MerchantSessionRequest>(HttpMethod.Post, requestUri, request, ContentType);
var response = await httpClient.SendAsync(requestData);
return response;
}
private static HttpRequestMessage CreateContentRequest<TReq>(HttpMethod method, Uri requestUri, TReq content, string contentType)
{
var r = CreateRequest(method, requestUri);
r.Content = new StringContent(JsonConvert.SerializeObject(content, JsonSettings), Encoding.UTF8, contentType);
return r;
}
private static HttpRequestMessage CreateRequest(HttpMethod method, Uri requestUri)
{
var r = new HttpRequestMessage(method, requestUri);
r.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(ContentType));
return r;
}
编辑:下面是我从邮递员那里打电话时的结果。我已经添加了客户端证书并在 Postman 中配置了苹果支付域。
解决方案
推荐阅读
- ruby-on-rails - 需要其他宝石的宝石(宝石依赖问题)
- objective-c - AFNetworkReachabilityManager:如果我设置 setReachabilityChangeBlock 两次或更多次会发生什么?
- eclipse - 如何将下面提到的代码修复到 Eclipse 中以滚动移动应用程序?
- flume - Flume hdfs sink 继续制作 .tmp 文件
- python - 看门狗和 matplotlib:当目录中有新文件时处理图像并显示结果
- ios - AWSCognito/DynamoDB 问题(未经身份验证的访问 - 不支持)
- php - 我已经在我的 macOs Mojave 上安装了 php trade 扩展,但我无法使用它
- julia - 没有方法匹配 write(::IOStream, ::MyClass)
- rust - Rust 中有传统风格的 switch 语句吗?
- sonarqube - SonarQube - 具有相同方法签名但不提供类的两个方法