From 7ea9b63865e49f3071e728e7cbe538f17ff2210b Mon Sep 17 00:00:00 2001 From: Ricardo Metring Date: Tue, 5 Mar 2024 12:00:28 -0600 Subject: [PATCH] Add server-side WooPay direct checkout eligibility flag (#8300) Co-authored-by: Rafael Zaleski --- changelog/add-woopay-direct-checkout-eligibility-flag | 4 ++++ includes/class-wc-payments-features.php | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog/add-woopay-direct-checkout-eligibility-flag diff --git a/changelog/add-woopay-direct-checkout-eligibility-flag b/changelog/add-woopay-direct-checkout-eligibility-flag new file mode 100644 index 00000000000..dc736bf3648 --- /dev/null +++ b/changelog/add-woopay-direct-checkout-eligibility-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add WooPay direct checkout flow behind a server-side feature flag. diff --git a/includes/class-wc-payments-features.php b/includes/class-wc-payments-features.php index 715b38b2872..57dbad4a32f 100644 --- a/includes/class-wc-payments-features.php +++ b/includes/class-wc-payments-features.php @@ -262,7 +262,11 @@ public static function is_woopay_first_party_auth_enabled() { * @return bool */ public static function is_woopay_direct_checkout_enabled() { - return '1' === get_option( self::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '0' ) && self::is_woopay_first_party_auth_enabled(); + $account_cache = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY, true ); + $is_direct_checkout_eligible = is_array( $account_cache ) && ( $account_cache['platform_direct_checkout_eligible'] ?? false ); + $is_direct_checkout_flag_enabled = '1' === get_option( self::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '0' ); + + return ( $is_direct_checkout_eligible || $is_direct_checkout_flag_enabled ) && self::is_woopay_first_party_auth_enabled(); } /**