Unable to get any response from the apple pay - This resource came from a local override

1k views Asked by At

I am integrating the apple pay and following the payment request API! According to the documentation (https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/requesting_an_apple_pay_payment_session)

cert: merchIdentityCert and key: merchIdentityCert both are the same. I append my merchantIdentityCertificate.pem to both cert and key.

But, Unable to get any response from the apple pay servers. After my request it is throwing an error and safari is displaying a message as “This resource came from a local override”

Code:

const merchIdentityCert = fs.readFileSync("./merchIdentityCert.pem")
const httpsAgent = new https.Agent({
  cert: merchIdentityCert,
  key: merchIdentityCert,
  maxVersion: "TLSv1.2",
  minVersion: "TLSv1.2"
})
const post = (url, body) => {
logger.info({ message: "apple pay START", url, body })
fetch(url, {
  body: JSON.stringify(body),
  method: "POST",
  agent: httpsAgent
}).then(resp => {
logger.info({ message: "apple pay SUCCESS", resp })
return resp
}).catch((error) => {
logger.info({ message: "apple pay ERROR", error })
return error
})
}

Logs:

message: "apple pay START", url: "https://-pay-gateway-cert.apple.com/paymentservices/startSession", body: {"merchantIdentifier":"..","displayName":"Test Pay","initiative":"web","initiativeContext":"--**.***."}

message: "apple pay ERROR", error: {}*

I am using a node-fetch library. My web app and node app deployed in AWS servers. I have fulfilled server setup and environment setup requirements with certificates. [https://developer.apple.com/documentation/apple_pay_on_the_web/setting_up_your_server]

Does anyone have an idea about this?

2

There are 2 answers

1
inod wagachchi On BEST ANSWER

Able to resolve the {"size":0,"timeout":0} issue and it is related to node fetch library. I fixed it from my code level. (Node-fetch problems with POST requests, https://www.npmjs.com/package/node-fetch)

Apart from that, I used the below request to debug using the remote server, and It was giving the session object to me.

curl -XPOST -H "Content-type: application/json" -d '{"merchantIdentifier":"merchant.***.xxxxx","displayName":"TestPay","initiative":"web","initiativeContext":"***-***-xxxxxx.xxxxxxxxxx.xx"}' --cert cert.pem:cert.pem 'https://apple-pay-gateway-cert.apple.com/paymentservices/startSession'

my code:

import fetch from "node-fetch"
import fs from "fs"
import { promiseReject } from "../utils/misc"
import { Logger } from "../services/Logger"
import https from "https"
const logger = new Logger("Apple Pay Client")
const checkStatusAndGetJSON = (fetchResponse) =>
    fetchResponse.ok
        ? fetchResponse.json()
        : fetchResponse.json().then(promiseReject)
const merchIdentityCert = fs.readFileSync("./merchIdentityCert.pem")
const httpsAgent = new https.Agent({
    cert: merchIdentityCert,
    key: merchIdentityCert,
    maxVersion: "TLSv1.2",
    minVersion: "TLSv1.2"
})
const basicHeaders = {
    "Accept": "application/json",
    "lang": "en",
    "Content-Type": "application/json"
}
const post = (url, body) => {
    const start = Date.now()
    return fetch(url, {
        body: JSON.stringify(body),
        headers: basicHeaders,
        method: "POST",
        agent: httpsAgent
    }).then(resp => {
        const duration = Date.now() - start
        logger.debug(`apple pay call took ${duration} millis.`, { endpoint: url, method: "POST", duration })
        return resp
    }).then(checkStatusAndGetJSON)
}
/** Apple Pay */
export const performValidation = (url, body) => post(url, body)
0
inod wagachchi On

There was an issue with the private key of my merchIdentityCert and I fixed it. After installing the .cer file, expand it from the Keychain Access, and export 2 items as .p12 and convert it to .pem using OpenSSL. Now, I have a PEM file that contains both assets. Then I continued my process and didn’t get the below error in this time which I mentioned in the above post.

message: "apple pay ERROR", error: {}

But, After the request, I am getting below log,

message: "apple pay SUCCESS", resp: {"size":0,"timeout":0}

As well, In the Inspect Element → Network → (click on my request) → Preview

Top of the response Preview, It is displaying a message as “Reveal | This resource came from a local override”

Does anyone have an idea? I am getting {"size":0,"timeout":0} from apple pay servers