Background: I am implementing Apple Pay on the web in our website with Authorize.NET as payment processor. I am using .NET framework 4.8. We have some the initial set-up done like obtaining the merchant Id, adding and verifying the merchant domains for our prod and test websites. We got the merchant identity certificate and installed that on our test servers.
Issue: I am facing the below issue while calling the validation url for obtaining the merchant session object. I followed https://tech.justeattakeaway.com/2016/10/10/bringing-apple-pay-to-the-web/ article for implementation.
The main extracts from the code are below. it is failing at 'httpClient.SendAsync' call. It looks like a TLS issue to me, but I have already set it to 1.2 and our test servers are also enabled with TLS1.2. Hence, I am not sure what exactly I am missing here. Any help will be highly appreciated. Thank you.
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;
}
EDIT: The below is the result when I call the same from Postman. I have added the client certificate and configured the apple pay domain in Postman.