We are trying to implement apple pay on the web in our project. When trying to implement apple pay the session.completeMerchantValidation returns the error InvalidAccessError : The object does not support the operation or argument . Below is the code snippet of my code. I am passing an object to session.completeMerchantValidation(as mentioned in other stackoverflow posts) but still getting the error. The domain name in the merchantSession object matches with the host name in the request url also. Not sure what is the issue here.Any help to fix this error is highly appreciated
session.onvalidatemerchant = (event) => {
var promise = validateMerchant2(event.validationURL);
promise.then(function (merchantSession) {
try{
session.completeMerchantValidation(merchantSession);
}
catch(err){alert("error while completing merchant validation : "+err);}
});
};
function validateMerchant2(url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
var sessionURL='/getAppleSession2?url='+url;
alert('sessionURL is'+sessionURL);
xhr.open('GET',sessionURL);
xhr.onload = function () {
alert("status " + this.status);
if (this.status >= 200 && this.status < 300) {
alert('xhr.response is : '+typeof(xhr.response)+': '+JSON.stringify(xhr.response));
try{
resolve(JSON.parse(xhr.response));
}
catch(e){
alert('Error while doing JSON parse on xhr.response'+e);
}
} else {
alert('in reject of validateMerchant2 '+this.status+' ' +xhr.statusText);
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send();
});
}