__( 'Express payments', 'aiolos-checkout-for-woocommerce' ), 'group' => 'checkout', 'sections' => array( 'placements' => array( 'label' => __( 'Where the buttons show', 'aiolos-checkout-for-woocommerce' ), 'description' => __( 'Apple Pay, Google Pay, PayPal and similar one-tap buttons come from your payment plugins; turn them on in each plugin\'s own settings. Here you choose whether Aiolos Checkout shows them at the top of the checkout; the side cart has its own switch in the Side cart tab.', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'express_checkout' => array( 'type' => 'toggle', 'label' => __( 'At the top of the checkout', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Above the contact details, with "or pay below" under them.', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ); return $fields; } /** * Express-capable gateways by id: name, and how to tell whether their buttons are on. * * @return array */ public static function known(): array { $known = array( 'stripe' => array( 'name' => 'WooCommerce Stripe (Apple Pay, Google Pay, Link)', 'keys' => array( 'express_checkout', 'payment_request' ), ), 'woocommerce_payments' => array( 'name' => 'WooPayments (Apple Pay, Google Pay, WooPay)', 'keys' => array( 'payment_request', 'is_woopay_enabled' ), ), 'ppcp-gateway' => array( 'name' => 'WooCommerce PayPal Payments' ), 'ppcp' => array( 'name' => 'Payment Plugins for PayPal' ), 'square_credit_card' => array( 'name' => 'Square (Apple Pay, Google Pay)', 'keys' => array( 'enable_digital_wallets' ), ), 'stripe_applepay' => array( 'name' => 'Payment Plugins Stripe: Apple Pay' ), 'stripe_googlepay' => array( 'name' => 'Payment Plugins Stripe: Google Pay' ), 'stripe_payment_request' => array( 'name' => 'Payment Plugins Stripe: Payment Request' ), 'stripe_link_checkout' => array( 'name' => 'Payment Plugins Stripe: Link' ), 'amazon_payments_advanced' => array( 'name' => 'Amazon Pay' ), 'mollie_wc_gateway_applepay' => array( 'name' => 'Mollie: Apple Pay', 'keys' => array( 'mollie_apple_pay_button_enabled_cart', 'mollie_apple_pay_button_enabled_express_checkout' ), ), 'braintree_paypal' => array( 'name' => 'Braintree: PayPal' ), 'klarna_payments' => array( 'name' => 'Klarna (Express button)', 'keys' => array( 'express_button_enabled' ), ), ); /** * Filters the express-capable gateways the Express payments tab looks for. * * @since 1.6.0 * * @param array $known Gateway id => [ 'name' => string, 'keys' => setting keys that turn the buttons on ]. */ return (array) apply_filters( 'aiolos_express_gateways', $known ); } /** * The express-capable gateways installed here. * * @return array */ public static function detected(): array { static $found = null; if ( null !== $found ) { return $found; } $found = array(); if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways() ) { return $found; } $gateways = WC()->payment_gateways()->payment_gateways(); foreach ( self::known() as $id => $info ) { if ( ! isset( $gateways[ $id ] ) || ! is_object( $gateways[ $id ] ) ) { continue; } $gateway = $gateways[ $id ]; $enabled = 'yes' === ( $gateway->enabled ?? 'no' ); $buttons = null; $keys = isset( $info['keys'] ) && is_array( $info['keys'] ) ? $info['keys'] : array(); if ( $keys ) { // Read the gateway's saved settings directly: some gateways' methods need a cart or // a configured account and fail on an admin screen. $settings = get_option( 'woocommerce_' . $id . '_settings', array() ); $settings = is_array( $settings ) ? $settings : array(); $buttons = false; foreach ( $keys as $key ) { if ( isset( $settings[ $key ] ) && in_array( $settings[ $key ], array( 'yes', '1', 1, true ), true ) ) { $buttons = true; } } } $found[] = array( 'id' => (string) $id, 'name' => (string) ( $info['name'] ?? $id ), 'enabled' => $enabled, 'buttons' => $enabled ? $buttons : false, 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . rawurlencode( (string) $id ) ), ); } return $found; } /** * The gateways list, under the tab's settings. * * @param string $tab Tab shown. */ public static function render( $tab ): void { if ( self::TAB !== $tab ) { return; } $found = self::detected(); ?>