🚧 Migrate eligibility check

This commit is contained in:
Philipp Stracker 2024-10-09 14:39:13 +02:00
parent 74e806535e
commit a4b3f2a079
No known key found for this signature in database

View file

@ -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.
*