1

背景: 我在我们的网站上使用 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 中配置了苹果支付域。

在此处输入图像描述

4

0 回答 0