Skip to content

Commit 4758d8c

Browse files
committed
Remove Stripe keys from the DB when uninstalling the plugin (#3385)
* Update the options list to remove * Remove webhook data when uninstalling * Disable the gateway before removing the plugin
1 parent 10a0783 commit 4758d8c

File tree

3 files changed

+101
-23
lines changed

3 files changed

+101
-23
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Update - Specify the JS Stripe API version as 2024-06-20.
2727
* Tweak - Use order ID from 'get_order_number' in stripe intent metadata.
2828
* Fix - Ensure payment tokens are detached from Stripe when a user is deleted, regardless of if the admin user has a Stripe account.
29+
* Fix - Remove the Stripe OAuth Keys when uninstalling the plugin.
2930
* Fix - Address Klarna availability based on correct presentment currency rules.
3031
* Fix - Use correct ISO country code of United Kingdom in supported country and currency list of AliPay and WeChat.
3132
* Fix - Prevent duplicate order notes and emails being sent when purchasing subscription products with no initial payment.

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
154154
* Update - Specify the JS Stripe API version as 2024-06-20.
155155
* Tweak - Use order ID from 'get_order_number' in stripe intent metadata.
156156
* Fix - Ensure payment tokens are detached from Stripe when a user is deleted, regardless of if the admin user has a Stripe account.
157+
* Fix - Remove the Stripe OAuth Keys when uninstalling the plugin.
157158
* Fix - Address Klarna availability based on correct presentment currency rules.
158159
* Fix - Use correct ISO country code of United Kingdom in supported country and currency list of AliPay and WeChat.
159160
* Fix - Prevent duplicate order notes and emails being sent when purchasing subscription products with no initial payment.

uninstall.php

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,120 @@
11
<?php
2-
if ( ! defined( 'ABSPATH' ) ) {
3-
exit; // Exit if accessed directly.
4-
}
2+
/**
3+
* WooCommerce Stripe Gateway Uninstall
4+
*
5+
* @version x.x.x
6+
*/
57

6-
// if uninstall not called from WordPress exit.
7-
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
8-
exit;
9-
}
8+
// Exit if accessed directly.
9+
defined( 'ABSPATH' ) || exit;
10+
11+
// Exit if uninstall not called from WordPress.
12+
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
13+
14+
// Remove OAuth access_token refresh scheduled job.
15+
wp_clear_scheduled_hook( 'wc_stripe_refresh_connection' );
1016

1117
/*
12-
* Only remove ALL product and page data if WC_REMOVE_ALL_DATA constant is set to true in user's
13-
* wp-config.php. This is to prevent data loss when deleting the plugin from the backend
18+
* ONLY remove the Stripe keys and keep the other configuration.
19+
* This is to prevent data loss when deleting the plugin from the backend
1420
* and to ensure only the site owner can perform this action.
1521
*/
16-
if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
17-
// Delete options.
22+
if ( ! defined( 'WC_REMOVE_ALL_DATA' ) || true !== WC_REMOVE_ALL_DATA ) {
23+
// Remove OAuth keys from the settings
24+
$settings = get_option( 'woocommerce_stripe_settings', [] );
25+
if ( is_array( $settings ) ) {
26+
// Disable the gateway before removing the plugin, to avoid an invalid API keys notice when reinstalling.
27+
$settings['enabled'] = 'no';
28+
// Live keys
29+
unset( $settings['publishable_key'], $settings['secret_key'] );
30+
unset( $settings['connection_type'], $settings['refresh_token'] );
31+
unset( $settings['webhook_data'] );
32+
unset( $settings['webhook_secret'] );
33+
// Test keys
34+
unset( $settings['test_publishable_key'], $settings['test_secret_key'] );
35+
unset( $settings['test_connection_type'], $settings['test_refresh_token'] );
36+
unset( $settings['test_webhook_data'] );
37+
unset( $settings['test_webhook_secret'] );
38+
}
39+
update_option( 'woocommerce_stripe_settings', $settings );
40+
41+
} else {
42+
// If WC_REMOVE_ALL_DATA constant is set to true in the merchant's wp-config.php,
43+
// remove ALL plugin settings.
1844
delete_option( 'woocommerce_stripe_settings' );
45+
46+
// Individual payment methods settings
47+
delete_option( 'woocommerce_stripe_affirm_settings' );
48+
delete_option( 'woocommerce_stripe_afterpay_clearpay_settings' );
49+
delete_option( 'woocommerce_stripe_alipay_settings' );
50+
delete_option( 'woocommerce_stripe_bancontact_settings' );
51+
delete_option( 'woocommerce_stripe_boleto_settings' );
52+
delete_option( 'woocommerce_stripe_cashapp_settings' );
53+
delete_option( 'woocommerce_stripe_card_settings' );
54+
delete_option( 'woocommerce_stripe_eps_settings' );
55+
delete_option( 'woocommerce_stripe_giropay_settings' );
56+
delete_option( 'woocommerce_stripe_ideal_settings' );
57+
delete_option( 'woocommerce_stripe_klarna_settings' );
58+
delete_option( 'woocommerce_stripe_link_settings' );
59+
delete_option( 'woocommerce_stripe_multibanco_settings' );
60+
delete_option( 'woocommerce_stripe_oxxo_settings' );
61+
delete_option( 'woocommerce_stripe_p24_settings' );
62+
delete_option( 'woocommerce_stripe_sepa_settings' );
63+
delete_option( 'woocommerce_stripe_sepa_debit_settings' );
64+
delete_option( 'woocommerce_stripe_sofort_settings' );
65+
delete_option( 'woocommerce_stripe_wechat_pay_settings' );
66+
67+
delete_option( 'woocommerce_gateway_stripe_retention' );
68+
delete_option( 'woocommerce_stripe_subscriptions_legacy_sepa_tokens_updated' );
69+
70+
delete_option( 'wc_stripe_elements_options' );
71+
delete_option( 'wc_stripe_version' );
72+
73+
delete_option( 'wc_stripe_show_style_notice' );
1974
delete_option( 'wc_stripe_show_styles_notice' );
75+
delete_option( 'wc_stripe_show_ssl_notice' );
2076
delete_option( 'wc_stripe_show_request_api_notice' );
2177
delete_option( 'wc_stripe_show_apple_pay_notice' );
22-
delete_option( 'wc_stripe_show_ssl_notice' );
2378
delete_option( 'wc_stripe_show_keys_notice' );
79+
delete_option( 'wc_stripe_show_3ds_notice' );
80+
delete_option( 'wc_stripe_show_phpver_notice' );
81+
delete_option( 'wc_stripe_show_wcver_notice' );
82+
delete_option( 'wc_stripe_show_curl_notice' );
83+
delete_option( 'wc_stripe_show_sca_notice' );
84+
delete_option( 'wc_stripe_show_changed_keys_notice' );
85+
delete_option( 'wc_stripe_show_customization_notice' );
86+
delete_option( 'wc_stripe_show_payment_methods_notice' );
87+
delete_option( 'wc_stripe_show_upe_payment_methods_notice' );
2488
delete_option( 'wc_stripe_show_alipay_notice' );
2589
delete_option( 'wc_stripe_show_bancontact_notice' );
26-
delete_option( 'wc_stripe_show_bitcoin_notice' );
2790
delete_option( 'wc_stripe_show_eps_notice' );
2891
delete_option( 'wc_stripe_show_giropay_notice' );
2992
delete_option( 'wc_stripe_show_ideal_notice' );
3093
delete_option( 'wc_stripe_show_multibanco_notice' );
94+
delete_option( 'wc_stripe_show_oxxo_notice' );
3195
delete_option( 'wc_stripe_show_p24_notice' );
3296
delete_option( 'wc_stripe_show_sepa_notice' );
3397
delete_option( 'wc_stripe_show_sofort_notice' );
34-
delete_option( 'wc_stripe_version' );
35-
delete_option( 'woocommerce_stripe_bancontact_settings' );
36-
delete_option( 'woocommerce_stripe_alipay_settings' );
37-
delete_option( 'woocommerce_stripe_bitcoin_settings' );
38-
delete_option( 'woocommerce_stripe_ideal_settings' );
39-
delete_option( 'woocommerce_stripe_p24_settings' );
40-
delete_option( 'woocommerce_stripe_giropay_settings' );
41-
delete_option( 'woocommerce_stripe_sepa_settings' );
42-
delete_option( 'woocommerce_stripe_sofort_settings' );
43-
delete_option( 'woocommerce_stripe_subscriptions_legacy_sepa_tokens_updated' );
98+
99+
// Webhook stats
100+
delete_option( 'wc_stripe_wh_monitor_began_at' );
101+
delete_option( 'wc_stripe_wh_last_success_at' );
102+
delete_option( 'wc_stripe_wh_last_failure_at' );
103+
delete_option( 'wc_stripe_wh_last_error' );
104+
delete_option( 'wc_stripe_wh_test_monitor_began_at' );
105+
delete_option( 'wc_stripe_wh_test_last_success_at' );
106+
delete_option( 'wc_stripe_wh_test_last_failure_at' );
107+
delete_option( 'wc_stripe_wh_test_last_error' );
108+
109+
// OAuth connection stats
110+
delete_option( 'wc_stripe_oauth_updated_at' );
111+
delete_option( 'wc_stripe_oauth_failed_attempts' );
112+
delete_option( 'wc_stripe_oauth_last_failed_at' );
113+
delete_option( 'wc_stripe_test_oauth_updated_at' );
114+
delete_option( 'wc_stripe_test_oauth_failed_attempts' );
115+
delete_option( 'wc_stripe_test_oauth_last_failed_at' );
116+
117+
// Feature flags
118+
delete_option( '_wcstripe_feature_upe' );
119+
delete_option( 'upe_checkout_experience_accepted_payments' );
44120
}

0 commit comments

Comments
 (0)