I am creating payment functionality with Apple Pay. I have used the CSR file to create a merchant_id.CER file from Apple developer portal.
using curl
โ10-05-2022 07:42 AM
To create a Payment Processing certificate
In Member Center, select Certificates, Identifiers & Profiles. Under Identifiers, select Merchant IDs. Select the merchant ID from the list, and click Edit. In the Payment Processing Certificates section. click Create Certificate.
โ12-07-2022 10:52 PM - last edited on โ12-08-2022 08:22 AM by Kh-SabW
I also want to create the .pem file. I have the merchant_id.cer and apple_pay.cer but don't know how to create it.
โ06-08-2023 02:39 AM
I have create the files. I followed the following link
https://github.com/norfolkmustard/ApplePayJS/blob/master/README.md
if you do not want to create the separate files from p12 file then you can use the below command to create a single file.
$ openssl pkcs12 -in Certificates.p12 -out apple-pay-cert.pem -nodes -clcerts
you can test the created fine using the curl command.
$ curl -gv --data '{"merchantIdentifier":"merchant.com.testbed.applepay", "initiativeContext":"mydomain.com", "initiative":"web", "displayName":"Apple Pay Testbed"}' --cert /path/to/pem/apple-pay-cert.pem https://apple-pay-gateway.apple.com/paymentservices/paymentSession
modify the different values according to your setup.
Using curl I am getting the proper response but when I host my asp.net core code on server the it is not working.
Below is the code sample.
var certificateBytes = await System.IO.File.ReadAllBytesAsync(certificatePath);
var certificate = new X509Certificate2(certificateBytes);
// Prepare the request data
var requestData1 = new
{
merchantIdentifier = "merchant.com.staggerallfilters",
initiativeContext = "stagger.allfilters.com",
initiative = "web",
displayName = "Stagger.AllFilters.Com"
};
var jsonRequestData = JsonConvert.SerializeObject(requestData1);
var content = new StringContent(jsonRequestData, Encoding.UTF8, "application/json");
// Create the HTTP client
var handler = new HttpClientHandler()
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
};
handler.ClientCertificates.Add(certificate);
var client = new HttpClient(handler);
// Send the request
var response = await client.PostAsync(requestData.validationUrl, content);
// Read the response
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return Ok(responseContent);
}
else
{
return BadRequest(responseContent);
}
โ06-09-2023 04:26 AM