Search code examples
safariapplepayjs

ApplePayJS InvalidAccessError


Trying to integrate ApplePayJS into my website and getting this annoying message::

InvalidAccessError Code 15

"The object does not support the operation or argument"

Everything seems to have been going well and now nothing works.


Solution

  • If you get this error, in my experience Safari is now dead to ApplePayJS and you must start by force quitting and reopening it again.

    Turns out the reason for me what that the ApplePay API completely craps out if you pass a string instead of an object into the completeMerchantValidation.

    If what you return from your server is not JSON object, but a string instead then you can do this:

    session.completeMerchantValidation(JSON.parse(merchantSession));
    

    Or better still - fix your server to return a JSON object instead of a string.


    Update 4 years later:

    I just saw this again today for a real customer as opposed to during my own testing. In this instance the order had succeeded and the customer thought it had failed so attempted to go through the process again.

    Oddly it was on this call with the same error "The object does not support the operation or argument."

    applePayTokenize.session.completePayment(ApplePaySession.STATUS_SUCCESS);
    

    Since the payment succeeded I've changed my logic to just ignore the exception (for STATUS_SUCCESS only) and proceed to the final page. I don't even know if the ApplePay sheet was still open but even if it was at least when it cancels it will be on the receipt page.