Show the Apple Pay button:

You will need to check that the window.ApplePaySession class exists to ensure that Apple Pay is supported and available in the browser. After that you will also need to check that the device is capable of making Apple Pay payments by using the canMakePayments() method.

if (window.ApplePaySession) {
                if (ApplePaySession.canMakePayments()) {
                    $(".apple-pay-button").show();
                }
            }

Request Payment Authorization and get EdgePay Pivot token:

Once the Apple Pay button is clicked create an Apple Pay Session using EdgePay’s Payment Request object:

var paymentRequestResponse = await EdgePay.applePay.getPaymentRequest();
                if (!paymentRequestResponse.success) {
                    alert("Error when creating Payment Request" + "Error: " + JSON.stringify(paymentRequestResponse));
                    return;
                }
 
                paymentRequestResponse.paymentRequest.total = {
                    "label": "Demo (Card is not charged)",
                    "type": "final",
                    "amount": 1.00
                };
 
                // Create ApplePaySession
                const session = new ApplePaySession(3, paymentRequestResponse.paymentRequest);

Use the EdgePay’s validate merchant method to complete Apple’s merchant validation process:

session.onvalidatemerchant = async event => {
                    // VALIDATE MERCHANT
                    EdgePay.applePay.validateMerchant({
                        requestPayLoad: {
                            validationURL: event.validationURL,
                            displayName: 'My Store Name'
                        },
                        onSuccess: function (response) {
                            session.completeMerchantValidation(response.merchantSession);
                        },
                        onError: function (error) {
                            console.log(error);
                        }
                    });
                };

Get an EdgePay Pivot token after receiving the Apple Pay payment token:

session.onpaymentauthorized = event => {
                    //Get an EdgePay Pivot token on payment authorized
                    EdgePay.applePay.getToken({
                        paymentToken: event.payment.token,
                        onSuccess: function (response) {
                            submitSale(response.tokenID, "apple");
                        },
                        onError: function (error) {
                            console.log(error);
                        }
                    });
 
                    // DEFINE ApplePayPaymentAuthorizationResult
                    const result = {
                        "status": ApplePaySession.STATUS_SUCCESS
                    };
                    session.completePayment(result);
                };