Payment not Complete right after CompleteMerchantValidation

I have done everything needed, I have it running on a verified domain with a SSL certificate, but it still always giving me payment not complete.

{
   "epochTimestamp":1631532235832,
   "expiresAt":1631535835832,
   "merchantSessionIdentifier":"S--3",
   "nonce":"6--6",
   "merchantIdentifier":"DA--2E",
   "domainName":"Company.com",
   "displayName":"Company Name",
   "signature":"4--0",
   "operationalAnalyticsIdentifier":"B--E",
   "retries":0
}

I have checked the epochTimestamp and expiresAt when I convert the epochTimestamp to time and date I get this date

epochTimestamp -----> Fri, 13 Mar 53671 22:50:32 +0000

CurrentDate -----> 13-Sep-2021 11:33:16

When you remove the last 3 digits from the epochTimestamp it gives the correct time. In my code it reaches CompleteMerchantValidation then cancels right after that

onPaymentAuthorized and everything else runs before the session even begins

Could it be that what I'm receiving from apple server is incorrect due to having something wrong with the certificates

applePayButton.addEventListener("click", function(){

const request = {
    countryCode: 'US',
    currencyCode: 'USD',
    merchantCapabilities: [
        'supports3DS'
    ],
    supportedNetworks: [
        'visa',
        'masterCard',
        'amex',
        'discover'
    ],
    lineItems: [{
            label: 'Amount',
            amount: 0.95,
        },
        {
            label: 'Tax',
            amount: 0.05,
        }
    ],
    total: {
        label: 'Total',
        amount: 10,
    }
};
var session = new ApplePaySession(10, request);
session.begin();

try{
    session.onvalidatemerchant = function(event){
        printMessage("starting session.onvalidatemerchant" + JSON.stringify(event));

        var promise = performValidation(event.validationURL);

            promise.then(function(merchantSession) {
                printMessage("Complete Merchant Validation: " + JSON.stringify(merchantSession));
                session.completeMerchantValidation(merchantSession);
            }).catch((error) => printMessage("OnCompleteMerchantValidation: " + error));
    }
}
catch(error){
    printMessage("On Validate Merchant Error: " + error)
}

try{
    printMessage("onpaymentmethodselected");

    session.onpaymentmethodselected = function(event) {
        printMessage("In On Payment Method Selected");
        //var myPaymentMethod = event.paymentMethod;

        const update = {};
        session.completePaymentMethodSelection(update);
    };

}
catch(error){
    printMessage("On Payment Method Selected Error: " + error)
}

try{
    printMessage("onpaymentauthorized");
    session.onpaymentauthorized = function(event) {
        printMessage("starting session.onpaymentauthorized");

        var applePaymentToken = event.payment.token;

        printMessage("Token" + applePaymentToken);

        // Define ApplePayPaymentAuthorizationResult
        session.completePayment(session.STATUS_SUCCESS);
    };

}
catch(error){
    printMessage("On Payment Authorized Error: " + error)
}

try{
    session.oncancel = function(event) {
        printMessage("starting session.oncancel" + JSON.stringify(event));

        // Payment cancelled by WebKit
    };
}
catch(error){
    printMessage("On Cancel Error: " + error)
}

These are the messages that comes when I start apple pay Session: Step 1: applePay working

Step 2: onpaymentmethodselected

Step 3: onpaymentauthorized

Step 4: starting session.onvalidatemerchant{"isTrusted":true}

Step 5: Complete Merchant Validation:

Step 6: starting session.oncancel{"isTrusted":true}

Could it be that what I'm receiving from apple server is incorrect due to having something wrong with the certificates

If this was the case, typically you would see the issue when your server requests the payment session from the Apple Pay servers. However, it looks like you are getting a Payment Session, so from there I would do the following:

  1. Make sure you are using the correct Merchant ID by verifying the shasum. Take your Merchant ID and run it through this command on the Terminal:
echo -n "merchant.com.testbed.applepay" | shasum -a 256
12953b72a8db15cf4a079b49a87ddd5eed1b0ba2eb249c7907265a7b04cff6ce 

Then compare it against the value you have in merchantIdentifier in your Payment Session, if that is good then you are using the correct Merchant Identifier.

  1. Make sure you are using the correct domain. For example, make sure if you registered test.example.com in the Developer Portal that you are using explicitly test.example.com and not example.com. This even counts for www.example.com.

  2. Make sure that to isolate a device that is being used for Sandbox testing. For example, make sure you only have a Sandbox test user signed into this device and that you are only using a production card or Sandbox test card. Do not mix cards and accounts.

Create a Sandbox Tester Account https://developer.apple.com/apple-pay/sandbox-testing/

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

If you're operating on multiple domains, I'll suggest you to check the sessions response. If you're on domain XYZ.com and you're getting session response for ABC.com (somehow due to a bug or your environmental setup) the applepay dailogue will close abruptly with message saying Payment failed

We had similar issue where-in we had multiple domains running on single api, hence we were getting session response for just one domain whose api and frontend was on same domain. A tiny miss but yeah this was our cause of issue.

Have to point that need ti be fixed // 1. Fix JSON parsing error session.completeMerchantValidation(JSON.parse(merchantSession));

// 2. Handle session.onpaymentmethodselected function // Option 1: Remove the function if unnecessary // Option 2: Update the function to handle correctly

Have to point that need to be fixed

1. Fix JSON parsing error session.completeMerchantValidation(JSON.parse(merchantSession));

2. Handle session.onpaymentmethodselected function 
Option 1: Remove the function if unnecessary 

Option 2: Update the function to handle correctly
Payment not Complete right after CompleteMerchantValidation
 
 
Q