微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

网络上的 Apple Pay - 商家验证问题

如何解决网络上的 Apple Pay - 商家验证问题

背景: 我在我们的网站上使用 Authorize.NET 作为支付处理器在网络上实施 Apple Pay。我正在使用 .NET 框架 4.8。 我们已经完成了一些初始设置,例如获取商家 ID,为我们的产品和测试网站添加和验证商家域。我们获得了商家身份证书并将其安装在我们的测试服务器上。

问题: 我在调用验证 url 以获取商家会话对象时遇到以下问题。我按照 https://tech.justeattakeaway.com/2016/10/10/bringing-apple-pay-to-the-web/ 文章进行了实施。

enter image description here

代码的主要摘录如下。它在“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中添加了客户端证书并配置了apple pay域。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。