Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function get_settings() {
/* Settings > Express checkouts */
'amazon_pay_button_size' => $this->gateway->get_validated_option( 'amazon_pay_button_size' ),
'amazon_pay_button_locations' => $this->gateway->get_validated_option( 'amazon_pay_button_locations' ),
'is_payment_request_enabled' => $this->gateway->is_payment_request_enabled(),
'is_payment_request_enabled' => $this->gateway->are_apple_pay_and_google_pay_enabled(),
'payment_request_button_type' => $this->gateway->get_validated_option( 'express_checkout_button_type' ),
'payment_request_button_theme' => $this->gateway->get_validated_option( 'express_checkout_button_theme' ),
'payment_request_button_size' => $this->gateway->get_validated_option( 'express_checkout_button_size' ),
Expand Down
12 changes: 11 additions & 1 deletion includes/class-wc-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,21 @@ private function validate_field( $field_key, $field_value ) {
* Returns whether Google Pay and Apple Pay (PRBs) are enabled,
* for the legacy checkout.
*
* @deprecated 10.2.0 Use {@see are_apple_pay_and_google_pay_enabled()} instead.
* @return bool
*/
public function is_payment_request_enabled() {
return $this->are_apple_pay_and_google_pay_enabled();
}

/**
* Returns whether Google Pay and Apple Pay express checkout methods are enabled
*
* WC_Stripe_UPE_Payment_Gateway overrides this method.
*
* @return bool
*/
public function is_payment_request_enabled() {
public function are_apple_pay_and_google_pay_enabled(): bool {
return 'yes' === $this->get_option( 'express_checkout' );
}

Expand Down
9 changes: 6 additions & 3 deletions includes/class-wc-stripe-apple-pay-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public function is_domain_set() {
private function is_enabled() {
$stripe_enabled = 'yes' === $this->get_option( 'enabled', 'no' );

$gateway = WC_Stripe::get_instance()->get_main_stripe_gateway();
$payment_request_button_enabled = $gateway->is_payment_request_enabled();
if ( ! $stripe_enabled ) {
return false;
}

return $stripe_enabled && $payment_request_button_enabled;
return WC_Stripe::get_instance()
->get_main_stripe_gateway()
->are_apple_pay_and_google_pay_enabled();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function get_instance() {
/**
* The main Stripe gateway instance. Use get_main_stripe_gateway() to access it.
*
* @var null|WC_Stripe_Payment_Gateway
* @var null|WC_Stripe_UPE_Payment_Gateway
*/
protected $stripe_gateway = null;

Expand Down Expand Up @@ -803,7 +803,7 @@ public function register_routes() {
/**
* Returns the main Stripe payment gateway class instance.
*
* @return WC_Stripe_Payment_Gateway
* @return WC_Stripe_UPE_Payment_Gateway
*/
public function get_main_stripe_gateway() {
if ( ! $this->stripe_gateway ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,19 @@ public function javascript_params() {
? ( $this->stripe_settings['test_publishable_key'] ?? '' )
: ( $this->stripe_settings['publishable_key'] ?? '' );

$apple_pay_and_google_pay_enabled = $this->express_checkout_helper->are_apple_pay_and_google_pay_enabled();

return [
'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
'stripe' => [
'publishable_key' => $publishable_key,
'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
'locale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ),
'is_link_enabled' => $this->express_checkout_helper->is_link_enabled(),
'is_express_checkout_enabled' => $this->express_checkout_helper->is_express_checkout_enabled(),
'is_amazon_pay_enabled' => $this->express_checkout_helper->is_amazon_pay_enabled(),
'is_payment_request_enabled' => $this->express_checkout_helper->is_payment_request_enabled(),
'publishable_key' => $publishable_key,
'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
'locale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ),
'is_link_enabled' => $this->express_checkout_helper->is_link_enabled(),
'is_express_checkout_enabled' => $this->express_checkout_helper->is_express_checkout_enabled(),
'is_amazon_pay_enabled' => $this->express_checkout_helper->is_amazon_pay_enabled(),
'is_payment_request_enabled' => $apple_pay_and_google_pay_enabled,
'are_apple_pay_google_pay_enabled' => $apple_pay_and_google_pay_enabled,
],
'nonce' => [
'payment' => wp_create_nonce( 'wc-stripe-express-checkout' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ public function is_enabled_for_location( string $express_checkout_type = 'paymen
* @return boolean
*/
public function is_express_checkout_enabled() {
return $this->is_payment_request_enabled() ||
return $this->are_apple_pay_and_google_pay_enabled() ||
$this->is_amazon_pay_enabled() ||
$this->is_link_enabled();
}
Expand Down Expand Up @@ -1668,13 +1668,23 @@ private function is_enabled_for_current_context( string $express_checkout_type )
return true;
}

/**
* Returns whether Apple Pay and Google Pay are enabled.
*
* @deprecated 10.2.0 Use {@see are_apple_pay_and_google_pay_enabled()} instead.
* @return boolean
*/
public function is_payment_request_enabled(): bool {
return $this->are_apple_pay_and_google_pay_enabled();
}

/**
* Checks if Apple Pay and Google Pay buttons are enabled.
*
* @return boolean
*/
public function is_payment_request_enabled() {
$is_enabled = $this->gateway->is_payment_request_enabled();
public function are_apple_pay_and_google_pay_enabled(): bool {
$is_enabled = $this->gateway->are_apple_pay_and_google_pay_enabled();

return $is_enabled && $this->is_enabled_for_current_context( 'payment_request' );
}
Expand Down
12 changes: 7 additions & 5 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,17 @@ public function javascript_params() {
if ( ! is_null( WC()->cart ) && WC()->cart->needs_shipping() ) {
$needs_shipping = 'yes';
}
$apple_pay_and_google_pay_enabled = $this->gateway->are_apple_pay_and_google_pay_enabled();

return [
'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
'stripe' => [
'key' => $this->publishable_key,
'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
'locale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ),
'is_link_enabled' => false, // Link is not available for PRB.
'is_payment_request_enabled' => $this->is_payment_request_enabled(),
'key' => $this->publishable_key,
'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
'locale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ),
'is_link_enabled' => false, // Link is not available for PRB.
'is_payment_request_enabled' => $apple_pay_and_google_pay_enabled,
'are_apple_pay_google_pay_enabled' => $apple_pay_and_google_pay_enabled,
],
'nonce' => [
'payment' => wp_create_nonce( 'wc-stripe-payment-request' ),
Expand Down
13 changes: 8 additions & 5 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ public function javascript_params() {
$is_signup_on_checkout_allowed = 'yes' === get_option( 'woocommerce_enable_signup_and_login_from_checkout', 'no' )
|| ( $this->is_subscription_item_in_cart() && 'yes' === get_option( 'woocommerce_enable_signup_from_checkout_for_subscriptions', 'no' ) );

$apple_pay_and_google_pay_enabled = $express_checkout_helper->are_apple_pay_and_google_pay_enabled();

$stripe_params['isLoggedIn'] = is_user_logged_in();
$stripe_params['isSignupOnCheckoutAllowed'] = $is_signup_on_checkout_allowed;
$stripe_params['isCheckout'] = ( is_checkout() || has_block( 'woocommerce/checkout' ) ) && empty( $_GET['pay_for_order'] ); // wpcs: csrf ok.
Expand All @@ -518,7 +520,8 @@ public function javascript_params() {
$stripe_params['subscriptionManualRenewalEnabled'] = WC_Stripe_Subscriptions_Helper::is_manual_renewal_enabled();
$stripe_params['forceSavePaymentMethod'] = WC_Stripe_Helper::should_force_save_payment_method();
$stripe_params['accountCountry'] = WC_Stripe::get_instance()->account->get_account_country();
$stripe_params['isPaymentRequestEnabled'] = $express_checkout_helper->is_payment_request_enabled();
$stripe_params['isPaymentRequestEnabled'] = $apple_pay_and_google_pay_enabled;
$stripe_params['areApplePayAndGooglePayEnabled'] = $apple_pay_and_google_pay_enabled;
$stripe_params['isAmazonPayEnabled'] = $express_checkout_helper->is_amazon_pay_enabled();
$stripe_params['isLinkEnabled'] = $express_checkout_helper->is_link_enabled();

Expand Down Expand Up @@ -3407,16 +3410,16 @@ public function filter_my_account_my_orders_actions( $actions, $order ) {
}

/**
* Checks if Google Pay and Apple Pay (ECE) are enabled.
* Checks if Google Pay and Apple Pay express checkout methods are enabled.
*
* Overrides WC_Gateway_Stripe::is_payment_request_enabled().
* Overrides WC_Gateway_Stripe::are_apple_pay_and_google_pay_enabled().
*
* @return bool
*/
public function is_payment_request_enabled() {
public function are_apple_pay_and_google_pay_enabled(): bool {
// If the payment method configurations API is not enabled, we fallback to the enabled payment methods stored in the DB.
if ( ! WC_Stripe_Payment_Method_Configurations::is_enabled() ) {
return parent::is_payment_request_enabled();
return parent::are_apple_pay_and_google_pay_enabled();
}

$enabled_payment_method_ids = $this->get_upe_enabled_payment_method_ids();
Expand Down
Loading