Problems with getting Apple Pay payment session

We are a SaaS team providing websites for restaurants. A year ago we implemented ApplePay on the web in our project and everything worked just fine. We have about 20 websites with Apple Pay. But now it's unstable and payment can be successful on the third try sometimes. We are facing an ECONNRESET error while requesting POST https://apple-pay-gateway.apple.com/paymentservices/startSession and an error message “Payment not completed” on the client side


Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -104,
code: 'ECONNRESET',
config: {
    url: 'https://apple-pay-gateway.apple.com/paymentservices/startSession',
    method: 'post',
    data: '{"merchantIdentifier":"merchant.com.xxxxxxxx","displayName":"xxxxxxxxxx","initiative":"web","initiativeContext":"xxxxxxxx.xxx","domainName":"xxxxxxxx.xxx"}',
    headers: {
        Accept: 'application/json, text/plain, */*',
            'Content-Type': 'application/json',
            'User-Agent': 'axios/0.19.2',
            'Content-Length': 191
    }
},
...
response: undefined,
isAxiosError: true,


Client side code:

applePaySession.onvalidatemerchant = async (event) => {
  try {
    const data = {
      url: event.validationURL,
      method: 'post',
      body: {
        merchantIdentifier,
        displayName,
        initiative: "web",
        initiativeContext: window.location.hostname
      },
      json: true,
    }
    const merchantSession = await this.$axios.$post('/apple_pay_session', data);
    if (merchantSession && merchantSession.merchantSessionIdentifier) {
      applePaySession.completeMerchantValidation(merchantSession)
    } else {
      applePaySession.abort();
    }
  } catch (error) {
    logReqError(error)
    applePaySession.abort();
  }
};


Server side:

    const httpsAgent = new https.Agent({
        rejectUnauthorized: false,
        keepAlive: true,
        cert: fs.readFileSync(`uploads/apple_pay/${id}/certificate.pem`),
        key: fs.readFileSync(`uploads/apple_pay/${id}/private.key`)
    });

    const sessionRes = await axios({
        url: request.body.url,
        method: request.body.method.toLowerCase(),
        data: request.body.body,
        headers: {'Content-Type': 'application/json'}, httpsAgent
    })


We checked the status of Merchant Domain - it's verified, Apple Pay Payment Processing Certificate and Apple Pay Merchant Identity Certificate are valid. I also checked project code with the official documentation, as well as with other sources. I hope anyone has had a similar problem. Any code samples or guesses will be helpful anyway

Posted on Feb 9, 2022 1:32 AM

Reply

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problems with getting Apple Pay payment session

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.