Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes _doing_it_wrong() messages being displayed on WordPress 6.7 due to translating too early #3616

Merged
merged 5 commits into from
Nov 22, 2024
Merged
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
* Fix - Do not load express payment buttons on switch subscription page.
* Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account.
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).

= 8.9.0 - 2024-11-14 =
* Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata.
Expand Down
14 changes: 11 additions & 3 deletions includes/admin/class-wc-stripe-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ class WC_Stripe_Privacy extends WC_Abstract_Privacy {
* Constructor
*/
public function __construct() {
parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) );
parent::__construct();

add_action( 'init', [ $this, 'register_erasers_exporters' ] );
add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] );
}

/**
* Register erasers and exporters.
*/
public function register_erasers_exporters() {
$this->name = __( 'Stripe', 'woocommerce-gateway-stripe' );

$this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_exporter' ] );

Expand All @@ -20,8 +30,6 @@ public function __construct() {

$this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), [ $this, 'customer_data_eraser' ] );
$this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_eraser' ] );

add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] );
}

/**
Expand Down
20 changes: 16 additions & 4 deletions includes/admin/class-wc-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WC_Stripe_Settings_Controller {
/**
* The Stripe gateway instance.
*
* @var WC_Stripe_Payment_Gateway
* @var WC_Stripe_Payment_Gateway|null
*/
private $gateway;

Expand All @@ -29,9 +29,10 @@ class WC_Stripe_Settings_Controller {
*
* @param WC_Stripe_Account $account Stripe account
*/
public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway ) {
public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway = null ) {
$this->account = $account;
$this->gateway = $gateway;

add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
add_action( 'wc_stripe_gateway_admin_options_wrapper', [ $this, 'admin_options' ] );
add_action( 'woocommerce_order_item_add_action_buttons', [ $this, 'hide_refund_button_for_uncaptured_orders' ] );
Expand All @@ -44,6 +45,17 @@ public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gatew
add_action( 'update_option_woocommerce_gateway_order', [ $this, 'set_stripe_gateways_in_list' ] );
}

/**
* Fetches the Stripe gateway instance.
*/
private function get_gateway() {
if ( ! $this->gateway ) {
$this->gateway = WC_Stripe::get_instance()->get_main_stripe_gateway();
}

return $this->gateway;
}

/**
* Sets the Stripe gateways in the 'woocommerce_gateway_order' option which contains the list of all the gateways.
* This function is called when the 'woocommerce_gateway_order' option is updated.
Expand All @@ -69,7 +81,7 @@ public function set_stripe_gateways_in_list( $ordering ) {
*/
public function hide_refund_button_for_uncaptured_orders( $order ) {
try {
$intent = $this->gateway->get_intent_from_order( $order );
$intent = $this->get_gateway()->get_intent_from_order( $order );

if ( $intent && 'requires_capture' === $intent->status ) {
$no_refunds_button = __( 'Refunding unavailable', 'woocommerce-gateway-stripe' );
Expand Down Expand Up @@ -171,7 +183,7 @@ public function admin_scripts( $hook_suffix ) {
'stripe_oauth_url' => $oauth_url,
'stripe_test_oauth_url' => $test_oauth_url,
'show_customization_notice' => get_option( 'wc_stripe_show_customization_notice', 'yes' ) === 'yes' ? true : false,
'is_test_mode' => $this->gateway->is_in_test_mode(),
'is_test_mode' => $this->get_gateway()->is_in_test_mode(),
'plugin_version' => WC_STRIPE_VERSION,
'account_country' => $this->account->get_account_country(),
'are_apms_deprecated' => WC_Stripe_Feature_Flags::are_apms_deprecated(),
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
* Fix - Do not load express payment buttons on switch subscription page.
* Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account.
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
9 changes: 6 additions & 3 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function init() {
require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-payment-requests-controller.php';
new WC_Stripe_Payment_Requests_Controller();
} else {
new WC_Stripe_Settings_Controller( $this->account, $this->get_main_stripe_gateway() );
new WC_Stripe_Settings_Controller( $this->account );
}

if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) {
Expand Down Expand Up @@ -318,6 +318,7 @@ public function init() {

// Intitialize the class for updating subscriptions' Legacy SEPA payment methods.
add_action( 'init', [ $this, 'initialize_subscriptions_updater' ] );
add_action( 'init', [ $this, 'load_plugin_textdomain' ] );
}

/**
Expand Down Expand Up @@ -787,6 +788,10 @@ public function initialize_subscriptions_updater() {
$updater->init();
$updater->maybe_update();
}

public function load_plugin_textdomain() {
load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
}

$plugin = WC_Stripe::get_instance();
Expand All @@ -799,8 +804,6 @@ public function initialize_subscriptions_updater() {
add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' );

function woocommerce_gateway_stripe_init() {
load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );

if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' );
return;
Expand Down
Loading