From c15715a02f5e2fb30502479b90894ab291998130 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 26 Jul 2024 17:28:30 +0200
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20More=20reliable=20eligibil?=
=?UTF-8?q?ity-check?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Eligibility better aligns with the ApplePay SDK logic and will not insert a hidden button anymore.
---
.../resources/js/ApplepayButton.js | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-applepay/resources/js/ApplepayButton.js b/modules/ppcp-applepay/resources/js/ApplepayButton.js
index d84870fd9..fb853182c 100644
--- a/modules/ppcp-applepay/resources/js/ApplepayButton.js
+++ b/modules/ppcp-applepay/resources/js/ApplepayButton.js
@@ -163,11 +163,26 @@ class ApplePayButton {
return true;
}
- if ( this.buttonConfig.is_admin ) {
+ if ( CONTEXT.Preview === this.context ) {
return true;
}
- return !! ( this.applePayConfig.isEligible && window.ApplePaySession );
+ /**
+ * Ensure the ApplePaySession is available and accepts payments
+ * This check is required when using Apple Pay SDK v1; canMakePayments() returns false
+ * if the current device is not liked to iCloud or the Apple Wallet is not available
+ * for a different reason.
+ */
+ try {
+ if ( ! window.ApplePaySession?.canMakePayments() ) {
+ return false;
+ }
+ } catch ( error ) {
+ console.warn( error );
+ return false;
+ }
+
+ return !! this.applePayConfig.isEligible;
}
/**