I'm using Apple Pay JS to integrate it into my website what should I sent onMerchantValidate

1k Views Asked by At

what I know so far is that I have to send a POST request to the apple server.

How or where can I get the merchIdentityCert cert and key??

NOTE: I'm going to send the post request from PHP

   const options= {
       url: endpointURL,
       cert: merchIdentityCert,
       key: merchIdentityCert,
       method: 'post',
       body:{
               merchantIdentifier: "merchant.com.example.mystore",
               displayName: "MyStore",
               initiative: "web",
               initiativeContext: "mystore.example.com"
             },
        json: true,
   }
1

There are 1 best solutions below

1
On

I figured how to connect to apple Servers and create the needed certificates for the POST request to work.

These steps must be done from a mac

  1. Go to Apple Developer -> Create Certificate -> Apple Pay Merchant Identity

  2. From your Mac go to KeyChain Access-> On the top right Select Keychain Access-> Certificate Assistant -> Request a Certificate From a Certificate Authority

  3. Select Save to Disk & Let me specify key pair information

  4. Key Size = 2048 bits / Algorithm = RSA

  5. Upload the CSR to your Apple Pay Merchant Identity

  6. Download the certificate given by Apple Pay and upload it to your Keychain Access

  7. Export the certificate from Keychain Access as .p12 format

  8. Open terminal direct it to the folder with the exported .p12 certificate

  9. Run these commands "openssl pkcs12 -in ApplePayMerchantIdentity_and_privatekey.p12 -out ApplePay.crt.pem -clcerts -nokeys" "openssl pkcs12 -in ApplePayMerchantIdentity_and_privatekey.p12 -out ApplePay.key.pem -nocerts"

    $path = "yourPath/ApplePay.crt.pem"; $path_key = "yourPath/ApplePay.key.pem";

    // create a new cURL resource $ch = curl_init();

    $data = array( "merchantIdentifier" => "Your merchant Name", "displayName" => "Your Shop Name", "initiative" => "web", // If you're going to use it on the web "initiativeContext" => "Domain" );

    $data = json_encode($data);

    $header = array( 'Content-Type: application/json' );

    curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSLCERT, $path); curl_setopt($ch, CURLOPT_SSLCERTPASSWD, ""); // For the Certificate Password curl_setopt($ch, CURLOPT_SSLKEY, $path_key); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    $serverOutput = curl_exec($ch);