Hello, I am trying to implement Apple Pay for web on our site and seeing some odd behavior.
I see onvalidatemerchant and completeMerchantValidation being called, but a fairly opaque oncancel event immediately follows.
- I am able to load the Apple Pay JS script and instantiate an
ApplePaySessionon the client. - my server seems to be communicating effectively with the client, and returns a payment session from
https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession. - I have checked the hash of the
merchantIdentifierand it matches what is returned in the payment session - I have implemented all of the
ApplePaySessionevent handler methods (onvalidatemerchant,onpaymentauthorized,onpaymentmethodselected, etc.) -- onlyonvalidatemerchantandoncancelare called - I have registered both
<subdomain>.<mydomain>.comand<mydomain>.com, where the code is deployed - I have created a sandbox tester Apple account and added a test card to it, and am running the test from an iPad that is logged into the sandbox tester account
- the data being passed to
completeMerchantValidationis a JS object, not JSON, which threw a TypeError
Here is the deployed code.
applePaySession = new ApplePaySession(3, request);
applePaySession.onvalidatemerchant = async function (event) {
try {
const { data } = await getApplePayPaymentSession();
applePaySession.completeMerchantValidation(data);
} catch (e) {
console.log(e);
}
};
applePaySession.onpaymentauthorized = function(event) {
const result = {
"status": ApplePaySession.STATUS_SUCCESS
};
applePaySession.completePayment(result);
applePaySession = null;
};
applePaySession.onpaymentmethodselected = event => {
// No updates or errors are needed, pass an empty object.
const update = {};
applePaySession.completePaymentMethodSelection(update);
};
applePaySession.onshippingmethodselected = event => {
// No updates or errors are needed, pass an empty object.
const update = {};
applePaySession.completeShippingMethodSelection(update);
};
applePaySession.onshippingcontactselected = event => {
const update = {};
applePaySession.completeShippingContactSelection(update);
};
applePaySession.oncancel = function(event) {
console.log('oncancel', event);
};
applePaySession.begin();
Any guidance would be highly appreciated!