Apple Pay on the Web localhost testing

I'm wanting to implement and test Apple Pay on the Web using my localhost instance. I've managed to set everything up correctly and so I'm able to get a merchant session from the Apple Pay API, but the client code immediately calls oncancel after calling session.completeMerchantValidation.

After following this I'm seeing the following in the terminal:

com.apple.PassKit.PaymentAuthorizationUIExtension: (PassKitCore) [com.apple.passkit:Payment] Evaluating merchant session using PROD trust policy.
com.apple.PassKit.PaymentAuthorizationUIExtension: (PassKitCore) [com.apple.passkit:Payment] Application failed to provide a valid merchant session. We can't proceed to authorize the transaction.

From reading various online sources, including the documentation referenced above, it seems like this might be happening because localhost isn't a validated/verified domain under our merchant account which also means using localhost seems to be out of the question for local development. I was hoping that using the sandbox account would have been enough to maybe loosen up the domain requirement, but not so. Anything that can be set either on the account or in code to allow for the use of localhost with Sandbox accounts or is there some tool that I need to use for this or is this really only test-able under our sandbox domain?

Replies

Well that was silly of me. Turns out the value assigned to initiativeContext should not include the port, i.e. the value localhost:4200 (what the angular cli fires up) coming from the request headers is no good. After changing it to just localhost I was able to get the session validation to pass.

Hi @DavidIQ , I just wonder how you were able to test with localhost. Did you validate/verify localhost as one of your domain? From what I know, theinitiativeContext needs to use a domain that is validated and verified by apple pay. So, I just want to know how you were able to use localhost for that. Thanks in advance.