On step onvalidatemerchant I call service that make response to apple and should returns "apple session", when I make request to Apple apple enpoint returns 417 code.
I'm trying to get "merchant session" from Apple Pay Sandbox but my code always returns an error "417 (Expectation Failed)". I tried different ways with WebRequestHandler, httpclient, different headers but result is the same.
Example of my service logic:
static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = false;
using (var httpClient = GetSecureHttpClient())
{
var jsonData = "{\"merchantIdentifier\" : \"merchant.com.domain.www\", \"domainName\" : \"www.domain.com\", \"displayName\" : \"MySite\" }";
using (var content = new StringContent(jsonData, Encoding.UTF8, "application/json"))
{
try
{
httpClient.DefaultRequestHeaders.ExpectContinue = false;
using (var response = httpClient.PostAsync("https://apple-pay-gateway-cert.apple.com/paymentservices/startSession", content).Result)
{
response.EnsureSuccessStatusCode();
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}
}
catch (Exception ex) { Console.WriteLine("Apple Pay Gateway error: " + ex.ToString()); }
}
}
}
public static HttpClient GetSecureHttpClient()
{
var handler = new WebRequestHandler();
handler.ClientCertificates.Add(new X509Certificate2(("C:\\merchantid_certificate.p12"), "", X509KeyStorageFlags.MachineKeySet));
return new HttpClient(handler, true);
}