Apple Pay completeMerchantValidation调用后会话被取消问题求助
Problem Description
My backend successfully validates the merchant and returns a session, but after completing validation on the browser side, the transaction is canceled immediately. Among all event handlers of the ApplePaymentSession object, only onvalidatemerchant is called. Right after calling completeMerchantValidation with a valid session object, oncancel is triggered immediately.
- Browser session configuration:
const session = new ApplePaySession(3, { currencyCode: 'GBP', countryCode: 'GB', merchantCapabilities: [ 'supports3DS' ], supportedNetworks: ['visa', 'masterCard', 'amex', 'discover' ], total: { type: 'final', label: 'My Product', amount: 9.99, }, });
- Backend request parameters to Apple's gateway:
{ "merchantIdentifier": "merchant.MY.FQDN", "displayName": "My Company Name", "initiative": "web", "initiativeContext": "MY.VERIFIED.FQDN" }
- Apple's response passed to
completeMerchantValidation:
{ "epochTimestamp": 1552090296444, "expiresAt": 1552093896444, "merchantSessionIdentifier": "LONG_STRING", "nonce": "XXXX", "merchantIdentifier": "SAME_AS_IN_MY_MERCHANT_ID_CERT", "domainName": "MY.VERIFIED.FQDN", "signature": "XXXXXX-VERY-LONG-STRING-XXXXX" }
I've confirmed that the parameter passed to completeMerchantValidation is a JSON object, not a string:
console.log('session is a', typeof(result), result); // Output: object session.completeMerchantValidation(result);
The domain (hosted on Firebase) has been verified for the merchant ID. There are no errors in the backend or browser console, no exceptions can be caught. The Apple Pay panel briefly displays then shows "Payment not complete" and hides quickly.
Update: I noticed the startSession API returned by onvalidatemerchant is deprecated, and I've tried replacing it with paymentSession (the official gateway endpoint), but the problem still exists.
Troubleshooting & Solutions
I've run into a nearly identical issue before, so here are some actionable steps to debug and fix this:
Double-check domain verification details
- Even if you think the domain is verified, confirm the
apple-developer-merchantid-domain-associationfile is placed correctly in the.well-knowndirectory of your domain. Access it directly viahttps://[your-domain]/.well-known/apple-developer-merchantid-domain-associationto ensure it returns the exact plain text content generated in Apple Developer Portal—no extra spaces, line breaks, or formatting. - For Firebase-hosted domains, make sure your redirect rules aren't blocking access to the
.well-knownpath. Sometimes overly broad rewrite rules can interfere with Apple's verification checks.
- Even if you think the domain is verified, confirm the
Verify session parameter consistency
- Ensure the
domainNamein the returned merchant session exactly matches the domain your frontend is running on (including whether it useswwwor not—if your site is atexample.com, the session'sdomainNamecan't bewww.example.com). - Cross-check that the
merchantIdentifierin the session matches the one configured in your Apple Developer account perfectly, including case and suffixes.
- Ensure the
Adjust Apple Pay session configuration
- Check if your merchant account actually supports 3DS. If not, remove
supports3DSfrommerchantCapabilitiesor addsupportsEMValongside it (try['supports3DS', 'supportsEMV']as a test). - Try changing the
amountin thetotalobject to a string (e.g.,"9.99"instead of9.99). Some browsers have strict parsing rules for numeric amounts, and this small change can resolve silent failures.
- Check if your merchant account actually supports 3DS. If not, remove
Investigate network and environment factors
- Make sure your backend is using the correct Apple Pay gateway endpoint for your environment: use the sandbox endpoint for testing, and the production endpoint for live transactions—mixing them will cause silent failures.
- Inspect the browser's Network tab carefully after calling
completeMerchantValidation. Even if there's no console error, you might find a failed request to Apple's servers that's triggering the cancel event. - Test exclusively in Safari first. Apple Pay has tighter integration with Safari, and other browsers (like Chrome) have additional restrictions that can cause unexpected behavior. Safari also provides more detailed debug info for Apple Pay-related issues.
Review Apple Developer Portal settings
- Confirm your merchant ID is properly linked to your payment processor and is in an active state. Inactive or unlinked merchant IDs can cause sessions to be canceled immediately.
- Check if there are any pending agreements or required updates in your Apple Developer account. Unresolved account-level issues often lead to silent payment failures.
内容的提问来源于stack exchange,提问作者tommed

