When I excecute ApplePaySession.begin(); The Error occurs

I have implemented a website that makes payments with Apple Pay on the web.

After new Payment Session Created, ApplePayJS Executes ApplePaySession. begin();

But I only executed it once, The Error Occurs like Below

 InvalidAccessError:there is already has an active payment session

Test Info

I had created Apple Pay merchant ID and certificates, and verify your domain and set up server for secure communications with Apple Pay.

Apple Pay JS Version is 11

I have been using Sandbox account (Visa, Mastercard), iOS 14.6, and iphone8

Here's my code

const version = 11;
const paymentRequest = {
countryCode: "JP",
currencyCode: "JPY",
supportedNetworks: supportedNetworks,
merchantCapabilities: ["supports3DS",],
total: { label: label, type: type, amount: amount } ,
applicationData: applicationData
};

applePaySession = new ApplePaySession(version, paymentRequest);

applePaySession.onvalidatemerchant = function (event) {
const reqParam = {
validationUrl: event.validationURL};

applePaySession.completeMerchantValidation(data.merchantSession);
applePaySession.onpaymentauthorized = function (event) {
const paymentDataStr =
JSON.stringify(event.payment.token.paymentData);
const paymentToken = common_base64_encode(paymentDataStr);
inJsonObj.applePayToken = paymentToken;

applePaySession.begin();

Accepted Reply

I debugged and checked console.log

onValidateMerchant isn't received ApplePayValidateMerchantEvent, so My JS doesn't call out My server

Replies

InvalidAccessError:there is already has an active payment session

This error implies that your code may be running through the process of requesting a Payment Session again. To debug this I would check the following:

  1. The code that calls out to your server and receives the Payment Session to pass into completeMerchantValidation. If this is being hit twice then your client side code may have an error.

  2. Along with #1 you could also debug your server to see if the same validationURL request is being run twice from the client, prompting two responses.

  3. Lastly, the entire process could being running twice starting with new ApplePaySession, so checkout the code that runs this path, I am assuming it is when the user clicks or taps the Apple Pay button?

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
  • Sorry. I commented on the answer because I wanted to share an image of the current error situation. In doing so, I put a check mark by mistake.

Add a Comment

I debugged and checked console.log

onValidateMerchant isn't received ApplePayValidateMerchantEvent, so My JS doesn't call out My server