Skip to content

Commit

Permalink
Merge branch 'develop' into fix/ece-load-error
Browse files Browse the repository at this point in the history
  • Loading branch information
annemirasol authored Feb 3, 2025
2 parents d2662c9 + c2ba0fa commit d49c5ec
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 31 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

= 9.2.0 - xxxx-xx-xx =
* Fix - Prevent an express checkout element's load errors from affecting other express checkout elements.
* Add - Adds a new setting to toggle saving of Bancontact and iDEAL methods as SEPA Debit.
* Add - Wrap Amazon Pay in feature flag.
* Fix - Allow the saving of Bancontact tokens when SEPA is disabled.
* Tweak - Use WC Core's rate limiter on "Add payment method" page.
Expand Down
7 changes: 7 additions & 0 deletions client/data/settings/__tests__/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useAmazonPayEnabledSettings,
useAmazonPayLocations,
useAmazonPayButtonSize,
useSepaTokensForOtherMethods,
} from '../hooks';
import { STORE_NAME } from '../../constants';
import {
Expand Down Expand Up @@ -284,6 +285,12 @@ describe( 'Settings hooks tests', () => {
testedValue: true,
fallbackValue: false,
},
useSepaTokensForOtherMethods: {
hook: useSepaTokensForOtherMethods,
storeKey: 'is_sepa_tokens_for_other_methods_enabled',
testedValue: true,
fallbackValue: false,
},
useManualCapture: {
hook: useManualCapture,
storeKey: 'is_manual_capture_enabled',
Expand Down
3 changes: 3 additions & 0 deletions client/data/settings/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export const useAmazonPayLocations = makeSettingsHook(
export const useIsStripeEnabled = makeSettingsHook( 'is_stripe_enabled' );
export const useTestMode = makeSettingsHook( 'is_test_mode_enabled' );
export const useSavedCards = makeSettingsHook( 'is_saved_cards_enabled' );
export const useSepaTokensForOtherMethods = makeSettingsHook(
'is_sepa_tokens_for_other_methods_enabled'
);
export const useManualCapture = makeSettingsHook( 'is_manual_capture_enabled' );
export const useSeparateCardForm = makeSettingsHook(
'is_separate_card_form_enabled'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAccount } from 'wcstripe/data/account';
import {
useManualCapture,
useSavedCards,
useSepaTokensForOtherMethods,
useEnabledPaymentMethodIds,
useIsShortAccountStatementEnabled,
useSeparateCardForm,
Expand All @@ -21,6 +22,7 @@ jest.mock( 'wcstripe/data/account', () => ( {
jest.mock( 'wcstripe/data', () => ( {
useManualCapture: jest.fn(),
useSavedCards: jest.fn(),
useSepaTokensForOtherMethods: jest.fn(),
useIsShortAccountStatementEnabled: jest.fn(),
useSeparateCardForm: jest.fn(),
useGetSavingError: jest.fn(),
Expand All @@ -31,6 +33,7 @@ describe( 'PaymentsAndTransactionsSection', () => {
beforeEach( () => {
useManualCapture.mockReturnValue( [ true, jest.fn() ] );
useSavedCards.mockReturnValue( [ true, jest.fn() ] );
useSepaTokensForOtherMethods.mockReturnValue( [ true, jest.fn() ] );
useIsShortAccountStatementEnabled.mockReturnValue( [
false,
jest.fn(),
Expand Down
17 changes: 17 additions & 0 deletions client/settings/payments-and-transactions-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
useSeparateCardForm,
useEnabledPaymentMethodIds,
useIsShortAccountStatementEnabled,
useSepaTokensForOtherMethods,
} from 'wcstripe/data';
import UpeToggleContext from 'wcstripe/settings/upe-toggle/context';
import { PAYMENT_METHOD_CASHAPP } from 'wcstripe/stripe-utils/constants';
Expand All @@ -39,6 +40,10 @@ const StatementDescriptorInputWrapper = styled.div`

const PaymentsAndTransactionsSection = () => {
const [ isSavedCardsEnabled, setIsSavedCardsEnabled ] = useSavedCards();
const [
isSepaTokensForOtherMethodsEnabled,
setIsSepaTokensForOtherMethodsEnabled,
] = useSepaTokensForOtherMethods();
const [
isSeparateCardFormEnabled,
setIsSeparateCardFormEnabled,
Expand Down Expand Up @@ -93,6 +98,18 @@ const PaymentsAndTransactionsSection = () => {
'woocommerce-gateway-stripe'
) }
/>
<CheckboxControl
checked={ isSepaTokensForOtherMethodsEnabled }
onChange={ setIsSepaTokensForOtherMethodsEnabled }
label={ __(
'Enable SEPA Direct Debit tokens for other methods',
'woocommerce-gateway-stripe'
) }
help={ __(
'If enabled, users will be able to pay with iDEAL or Bancontact and save the method as a SEPA Direct Debit method.',
'woocommerce-gateway-stripe'
) }
/>
{ ! isUpeEnabled && (
<CheckboxControl
checked={ isSeparateCardFormEnabled }
Expand Down
62 changes: 42 additions & 20 deletions includes/admin/class-wc-rest-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public function register_routes() {
'type' => 'boolean',
'validate_callback' => 'rest_validate_request_arg',
],
'is_sepa_tokens_for_other_methods_enabled' => [
'description' => __( 'If "SEPA tokens for other methods" should be enabled.', 'woocommerce-gateway-stripe' ),
'type' => 'boolean',
'validate_callback' => 'rest_validate_request_arg',
],
'is_separate_card_form_enabled' => [
'description' => __( 'If credit card number field, expiry date field, and CVC field should be separate.', 'woocommerce-gateway-stripe' ),
'type' => 'boolean',
Expand Down Expand Up @@ -241,34 +246,35 @@ public function get_settings() {
return new WP_REST_Response(
[
/* Settings > General */
'is_stripe_enabled' => $this->gateway->is_enabled(),
'is_test_mode_enabled' => $this->gateway->is_in_test_mode(),
'is_stripe_enabled' => $this->gateway->is_enabled(),
'is_test_mode_enabled' => $this->gateway->is_in_test_mode(),

/* Settings > Payments accepted on checkout */
'enabled_payment_method_ids' => array_values( array_intersect( $enabled_payment_method_ids, $available_payment_method_ids ) ), // only fetch enabled payment methods that are available.
'available_payment_method_ids' => $available_payment_method_ids,
'ordered_payment_method_ids' => array_values( array_diff( $ordered_payment_method_ids, [ WC_Stripe_Payment_Methods::LINK ] ) ), // exclude Link from this list as it is a express methods.
'individual_payment_method_settings' => $is_upe_enabled ? WC_Stripe_Helper::get_upe_individual_payment_method_settings( $this->gateway ) : WC_Stripe_Helper::get_legacy_individual_payment_method_settings(),
'enabled_payment_method_ids' => array_values( array_intersect( $enabled_payment_method_ids, $available_payment_method_ids ) ), // only fetch enabled payment methods that are available.
'available_payment_method_ids' => $available_payment_method_ids,
'ordered_payment_method_ids' => array_values( array_diff( $ordered_payment_method_ids, [ WC_Stripe_Payment_Methods::LINK ] ) ), // exclude Link from this list as it is a express methods.
'individual_payment_method_settings' => $is_upe_enabled ? WC_Stripe_Helper::get_upe_individual_payment_method_settings( $this->gateway ) : WC_Stripe_Helper::get_legacy_individual_payment_method_settings(),

/* Settings > Express checkouts */
'is_amazon_pay_enabled' => 'yes' === $this->gateway->get_option( 'amazon_pay' ),
'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' => 'yes' === $this->gateway->get_option( 'payment_request' ),
'payment_request_button_type' => $this->gateway->get_validated_option( 'payment_request_button_type' ),
'payment_request_button_theme' => $this->gateway->get_validated_option( 'payment_request_button_theme' ),
'payment_request_button_size' => $this->gateway->get_validated_option( 'payment_request_button_size' ),
'payment_request_button_locations' => $this->gateway->get_validated_option( 'payment_request_button_locations' ),
'is_amazon_pay_enabled' => 'yes' === $this->gateway->get_option( 'amazon_pay' ),
'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' => 'yes' === $this->gateway->get_option( 'payment_request' ),
'payment_request_button_type' => $this->gateway->get_validated_option( 'payment_request_button_type' ),
'payment_request_button_theme' => $this->gateway->get_validated_option( 'payment_request_button_theme' ),
'payment_request_button_size' => $this->gateway->get_validated_option( 'payment_request_button_size' ),
'payment_request_button_locations' => $this->gateway->get_validated_option( 'payment_request_button_locations' ),

/* Settings > Payments & transactions */
'is_manual_capture_enabled' => ! $this->gateway->is_automatic_capture_enabled(),
'is_saved_cards_enabled' => 'yes' === $this->gateway->get_option( 'saved_cards' ),
'is_separate_card_form_enabled' => 'no' === $this->gateway->get_option( 'inline_cc_form' ),
'is_short_statement_descriptor_enabled' => 'yes' === $this->gateway->get_option( 'is_short_statement_descriptor_enabled' ),
'is_manual_capture_enabled' => ! $this->gateway->is_automatic_capture_enabled(),
'is_saved_cards_enabled' => 'yes' === $this->gateway->get_option( 'saved_cards' ),
'is_sepa_tokens_for_other_methods_enabled' => 'yes' === $this->gateway->get_option( 'sepa_tokens_for_other_methods' ),
'is_separate_card_form_enabled' => 'no' === $this->gateway->get_option( 'inline_cc_form' ),
'is_short_statement_descriptor_enabled' => 'yes' === $this->gateway->get_option( 'is_short_statement_descriptor_enabled' ),

/* Settings > Advanced settings */
'is_debug_log_enabled' => 'yes' === $this->gateway->get_option( 'logging' ),
'is_upe_enabled' => $is_upe_enabled,
'is_debug_log_enabled' => 'yes' === $this->gateway->get_option( 'logging' ),
'is_upe_enabled' => $is_upe_enabled,
]
);
}
Expand Down Expand Up @@ -296,6 +302,7 @@ public function update_settings( WP_REST_Request $request ) {
/* Settings > Payments & transactions */
$this->update_is_manual_capture_enabled( $request );
$this->update_is_saved_cards_enabled( $request );
$this->update_is_sepa_tokens_for_other_methods_enabled( $request );
$this->update_is_separate_card_form_enabled( $request );
$this->update_is_short_account_statement_enabled( $request );

Expand Down Expand Up @@ -436,6 +443,21 @@ private function update_is_saved_cards_enabled( WP_REST_Request $request ) {
$this->gateway->update_option( 'saved_cards', $is_saved_cards_enabled ? 'yes' : 'no' );
}

/**
* Updates "SEPA tokens for other methods" feature.
*
* @param WP_REST_Request $request Request object.
*/
private function update_is_sepa_tokens_for_other_methods_enabled( WP_REST_Request $request ) {
$is_sepa_tokens_for_other_methods_enabled = $request->get_param( 'is_sepa_tokens_for_other_methods_enabled' );

if ( null === $is_sepa_tokens_for_other_methods_enabled ) {
return;
}

$this->gateway->update_option( 'sepa_tokens_for_other_methods', $is_sepa_tokens_for_other_methods_enabled ? 'yes' : 'no' );
}

/**
* Updates "saved cards" feature.
*
Expand Down
10 changes: 9 additions & 1 deletion includes/admin/stripe-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@
'default' => 'yes',
'desc_tip' => true,
],
'sepa_tokens_for_other_methods' => [
'title' => __( 'SEPA Direct Debit tokens for other methods', 'woocommerce-gateway-stripe' ),
'label' => __( 'Enable SEPA Direct Debit tokens for other methods', 'woocommerce-gateway-stripe' ),
'type' => 'checkbox',
'description' => __( 'If enabled, users will be able to pay with iDEAL or Bancontact and save the method as a SEPA Direct Debit method.', 'woocommerce-gateway-stripe' ),
'default' => 'yes',
'desc_tip' => true,
],
'logging' => [
'title' => __( 'Logging', 'woocommerce-gateway-stripe' ),
'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
Expand All @@ -233,7 +241,7 @@
'default' => 'no',
'desc_tip' => true,
],
'amazon_pay_button_locations' => [
'amazon_pay_button_locations' => [
'title' => __( 'Amazon Pay Button Locations', 'woocommerce-gateway-stripe' ),
'type' => 'multiselect',
'description' => __( 'Select where you would like Amazon Pay Button to be displayed', 'woocommerce-gateway-stripe' ),
Expand Down
35 changes: 26 additions & 9 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
*/
public $saved_cards;

/**
* Should SEPA tokens be used for other payment methods (iDEAL and Bancontact)
*
* @var bool
*/
public $sepa_tokens_for_other_methods;

/**
* API access secret key
*
Expand Down Expand Up @@ -192,15 +199,16 @@ public function __construct() {
// Check if pre-orders are enabled and add support for them.
$this->maybe_init_pre_orders();

$main_settings = WC_Stripe_Helper::get_stripe_settings();
$this->title = $this->payment_methods['card']->get_title();
$this->description = $this->payment_methods['card']->get_description();
$this->enabled = $this->get_option( 'enabled' );
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' );
$this->testmode = WC_Stripe_Mode::is_test();
$this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
$this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
$main_settings = WC_Stripe_Helper::get_stripe_settings();
$this->title = $this->payment_methods['card']->get_title();
$this->description = $this->payment_methods['card']->get_description();
$this->enabled = $this->get_option( 'enabled' );
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' );
$this->sepa_tokens_for_other_methods = 'yes' === $this->get_option( 'sepa_tokens_for_other_methods' );
$this->testmode = WC_Stripe_Mode::is_test();
$this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
$this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';

// When feature flags are enabled, title shows the count of enabled payment methods in settings page only.
if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() && WC_Stripe_Feature_Flags::is_upe_preview_enabled() && isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] ) {
Expand Down Expand Up @@ -1707,6 +1715,15 @@ public function is_saved_cards_enabled() {
return $this->saved_cards;
}

/**
* Checks if the setting to allow the saving of SEPA tokens for other payment methods (iDEAL and Bancontact) is enabled.
*
* @return bool Whether the setting to allow SEPA tokens for other payment methods is enabled.
*/
public function is_sepa_tokens_for_other_methods_enabled() {
return $this->sepa_tokens_for_other_methods;
}

/**
* Set formatted readable payment method title for order,
* using payment method details from accompanying charge.
Expand Down
2 changes: 1 addition & 1 deletion includes/payment-tokens/class-wc-stripe-payment-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function woocommerce_get_customer_upe_payment_tokens( $tokens, $user_id,
}

// Add SEPA if it is disabled and iDEAL or Bancontact are enabled. iDEAL and Bancontact tokens are saved as SEPA tokens.
if ( ! $gateway->payment_methods[ WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID ]->is_enabled()
if ( $gateway->is_sepa_tokens_for_other_methods_enabled() && ! $gateway->payment_methods[ WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID ]->is_enabled()
&& ( $gateway->payment_methods[ WC_Stripe_UPE_Payment_Method_Ideal::STRIPE_ID ]->is_enabled()
|| $gateway->payment_methods[ WC_Stripe_UPE_Payment_Method_Bancontact::STRIPE_ID ]->is_enabled() ) ) {
$payment_methods[] = $customer->get_payment_methods( WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o

= 9.2.0 - xxxx-xx-xx =
* Fix - Prevent an express checkout element's load errors from affecting other express checkout elements.
* Add - Adds a new setting to toggle saving of Bancontact and iDEAL methods as SEPA Debit.
* Add - Wrap Amazon Pay in feature flag.
* Fix - Allow the saving of Bancontact tokens when SEPA is disabled.
* Tweak - Use WC Core's rate limiter on "Add payment method" page.
Expand Down

0 comments on commit d49c5ec

Please sign in to comment.