merchant id validation not working in MacOS Sierra

I'm trying to validate the merchant but it does not seems to be working . I have converted the merchant_id.cer file is converted to .pem file. Now, how the .pem file is used in Javascript or MyValidationServlet to validate merchant?


javascript is here


var e = new ApplePaySession(1, g);

console.log("ApplePaySession : " + e);

console.dir("ApplePaySession Contents : " + e);

e.onshippingcontactselected = function(i) {

var h = i.shippingContact;

console.log("Shipping Contact Selected : " + h)

};

e.onvalidatemerchant = function(h) {

console.log("Start Merchant Validation");

c(h.validationURL)

};

function c(j) {

console.log("Performing Validation");

var k = {

merchantIdentifier: "merchant.com.def.abc",

domainName: "abc.def.com",

displayName: "merchant.com.def.abc",

};

var h = "applePayURL=" + j + "&applePayPostData=" + JSON.stringify(k);

var i = new XMLHttpRequest();

i.onreadystatechange = function() {

if (i.readyState == 4 && i.status == 200 && i.responseText) {

var l = JSON.parse(i.responseText);

console.log("HTTP Status 200" + l);

f(l)

}

console.log("XMLHTTP Status : " + i.status + " :: XMLHTTP ReponseText : " + i.responseText)

};

e.onshippingmethodselected = function(j) {

console.log("On Shipping Method Selected : " + j);

const h = j.shippingMethod.identifier === "free" ? "0.00" : "5.00";

const k = j.shippingMethod.identifier === "free" ? "8.99" : "13.99";

const l = [{

label: "Shipping",

amount: h,

}, ];

const i = {

label: "Apple Pay Example",

amount: k,

};

e.completeShippingMethodSelection(ApplePaySession.STATUS_SUCCESS, i, l)

};

i.open("POST", "/cart/MyValidateServlet", true);

i.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

i.send(h);

return false

}




MyValidateServlet.java is below


package com.xyz.test;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import org.apache.http.HttpResponse;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import atg.servlet.GenericServletService;


public class MyValidateServlet extends GenericServletService{

public void service(ServletRequest pServletRequest, ServletResponse pServletResponse) throws IOException, ServletException {


String applePayURL = (String) pServletRequest.getParameter("applePayURL");

String applePayPostData = (String) pServletRequest.getParameter("applePayPostData");


System.out.println("applePayURL : "+applePayURL);

System.out.println("applePayPostData : "+applePayPostData);


System.setProperty("javax.net.debug", "all");


HttpPost request = null;


try {

CloseableHttpClient client = HttpClients.createDefault();

System.out.println("HttpClient : "+client);



request = new HttpPost(applePayURL);

StringEntity stringEntity = new StringEntity(applePayPostData);

request.setEntity(stringEntity);


System.out.println("Request Entity : "+request.getEntity());

System.out.println("Request that is being executed : "+request);

System.out.println("Executing HttpClient request....");


HttpResponse response = client.execute(request);

System.out.println("HTTP Response : "+response);

int statusCode = response.getStatusLine().getStatusCode();

System.out.println("Response Status Code :: " + statusCode);



if(statusCode != 200) {

System.out.println(" Error Validating Apple Pay " + statusCode);

}



} catch (ClientProtocolException e) {

System.out.println("ClientProtocolException : " + e);

} catch (IOException e) {

System.out.println("IOException : " + e);

} finally {

if(request != null) {

System.out.println("Releaseing Connections");

request.releaseConnection();

}

}



}

Replies

Hi ashaik,

Have your resolved this above issue?


It look like cer file access keychain provide don't contain private key and god knows where access keychain put it.

So you chould generate your own certificate with private key:


$ openssl
                    req -sha256 -nodes -newkey rsa:2048
                    -keyout applepaytls.key
                    -out applepaytls.csr


then upload to your profile applepaytls.csr and get signed by apple certFromApple.cer intead. Then you convert it to .pem


$ openssl
                    x509 -inform der
                    -in certFromApple.cer
                    -out merchant_identity.pem


And use merchant_identity.pem with applepaytls.key to validate merchant.

like I do in https://forums.developer.apple.com/thread/104920