Apple Pay payment sheet won't open

983 views Asked by At

I'm trying to debug Apple code example to open the payment sheet. Yesterday it worked and the payment sheet opened, but today I think I can't pass the session.onvalidatemerchant stage. When I debug, it won't stop in the getApplePaySession(event.validationURL) and instead will jump right to the session.onshippingmethodselected (which doesn't make sense because the light-box wasn't opened yet, right?!).

I don't have any error in the console. "Validate merchant" is not written to the console. This is the JS code Apple provided and which i'm using:

const session = new ApplePaySession(1, paymentRequest);

/**
* Merchant Validation
* We call our merchant session endpoint, passing the URL to use
*/
session.onvalidatemerchant = (event) => {
    console.log("Validate merchant");
    const validationURL = event.validationURL;
    getApplePaySession(event.validationURL).then(function(response) {
        console.log(response);
        session.completeMerchantValidation(response);
    });
};

/**
* Shipping Method Selection
* If the user changes their chosen shipping method we need to recalculate
* the total price. We can use the shipping method identifier to determine
* which method was selected.
*/
session.onshippingmethodselected = (event) => {
    const shippingCost = event.shippingMethod.identifier === 'free' ? '0.00' : '5.00';
    const totalCost = event.shippingMethod.identifier === 'free' ? '8.99' : '13.99';

    const lineItems = [
        {
            label: 'Shipping',
            amount: shippingCost,
        },
    ];

    const total = {
        label: 'Apple Pay Example',
        amount: totalCost,
    };

    session.completeShippingMethodSelection(ApplePaySession.STATUS_SUCCESS, total, lineItems);
};
1

There are 1 answers

0
co.zohar On BEST ANSWER

I solved the problem. The Mac and iPhone weren't configured with the same iCloud user.