diff --git a/modules/ppcp-applepay/resources/js/ApplepayButton.js b/modules/ppcp-applepay/resources/js/ApplepayButton.js index 1e67e32b8..630be7420 100644 --- a/modules/ppcp-applepay/resources/js/ApplepayButton.js +++ b/modules/ppcp-applepay/resources/js/ApplepayButton.js @@ -232,6 +232,7 @@ class ApplePayButton extends PaymentButton { } super.init(); + this.checkEligibility(); const button = this.addButton(); @@ -256,6 +257,27 @@ class ApplePayButton extends PaymentButton { this.init(); } + /** + * Re-check if the current session is eligible for Apple Pay. + */ + checkEligibility() { + if ( this.isPreview ) { + this.isEligible = true; + return; + } + + try { + if ( ! window.ApplePaySession?.canMakePayments() ) { + this.isEligible = false; + return; + } + + this.isEligible = !! this.#applePayConfig.isEligible; + } catch ( error ) { + this.isEligible = false; + } + } + /** * Starts an Apple Pay session, which means that the user interacted with the Apple Pay button. *