Skip to content

Commit 9166a10

Browse files
wjrosadaledupreez
andauthored
Replacing the SEPA legacy constant identifier (#4802)
* Replacing the SEPA legacy constant identifier * Update includes/constants/class-wc-stripe-payment-methods.php Co-authored-by: daledupreez <[email protected]> * Update readme.txt Co-authored-by: daledupreez <[email protected]> * Changelog entry update * Removing unused import * Removing unused import --------- Co-authored-by: daledupreez <[email protected]>
1 parent 6a4e36a commit 9166a10

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 10.2.0 - xxxx-xx-xx =
4+
* Dev - Replace the constant reference for the legacy SEPA payment method
45
* Update - Changes the list of payment methods shown in the Stripe account connection modal
56
* Update - Changes labels related to saved payment methods from "cards" to "payment methods"
67
* Fix - Ensure Amazon Pay, Apple Pay, and Google Pay display settings are managed correctly

includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ private function set_subscription_updated_payment_method( WC_Subscription $subsc
158158
*/
159159
private function set_subscription_updated_payment_gateway_id( WC_Subscription $subscription ) {
160160
// The subscription is not using the legacy SEPA gateway ID.
161-
if ( WC_Gateway_Stripe_Sepa::ID !== $subscription->get_payment_method() ) {
161+
if ( WC_Stripe_Payment_Methods::LEGACY_SEPA !== $subscription->get_payment_method() ) {
162162
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
163163
throw new \Exception( sprintf( '---- Skipping migration of subscription #%d. Subscription is not using the legacy SEPA payment method.', $subscription->get_id() ) );
164164
}
165165

166166
// Add a meta to the subscription to flag that its token got updated.
167-
$subscription->update_meta_data( self::LEGACY_TOKEN_PAYMENT_METHOD_META_KEY, WC_Gateway_Stripe_Sepa::ID );
167+
$subscription->update_meta_data( self::LEGACY_TOKEN_PAYMENT_METHOD_META_KEY, WC_Stripe_Payment_Methods::LEGACY_SEPA );
168168
$subscription->set_payment_method( $this->updated_sepa_gateway_id );
169169

170170
$subscription->save();

includes/constants/class-wc-stripe-payment-methods.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class WC_Stripe_Payment_Methods {
3535
const WECHAT_PAY = 'wechat_pay';
3636
const OC = 'card'; // This is a special case for the Optimized Checkout
3737

38+
public const LEGACY_SEPA = 'stripe_sepa'; // Sepa method identifier for the legacy checkout (now removed)
39+
3840
// Express method constants
3941
const AMAZON_PAY = 'amazon_pay';
4042
const GOOGLE_PAY = 'google_pay';

includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function get_items_to_repair( $page ) {
145145
'posts_per_page' => 20,
146146
'status' => 'any',
147147
'paged' => $page,
148-
'payment_method' => WC_Gateway_Stripe_Sepa::ID,
148+
'payment_method' => WC_Stripe_Payment_Methods::LEGACY_SEPA,
149149
'order' => 'ASC',
150150
'orderby' => 'ID',
151151
]
@@ -177,7 +177,7 @@ public function maybe_migrate_before_renewal( $subscription_id ) {
177177
}
178178

179179
// Run the full repair if the subscription is using the Legacy SEPA gateway ID.
180-
if ( $subscription->get_payment_method() === WC_Gateway_Stripe_Sepa::ID ) {
180+
if ( $subscription->get_payment_method() === WC_Stripe_Payment_Methods::LEGACY_SEPA ) {
181181
$this->repair_item( $subscription_id );
182182

183183
// Unschedule the repair action as it's no longer needed.
@@ -369,7 +369,7 @@ private function has_legacy_sepa_subscriptions() {
369369
'type' => 'shop_subscription',
370370
'status' => 'any',
371371
'posts_per_page' => 1,
372-
'payment_method' => WC_Gateway_Stripe_Sepa::ID,
372+
'payment_method' => WC_Stripe_Payment_Methods::LEGACY_SEPA,
373373
]
374374
);
375375
$subscriptions_count = count( $subscriptions );

includes/payment-tokens/class-wc-stripe-payment-tokens.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static function get_token_from_request( array $request ) {
122122
* @return bool
123123
*/
124124
public static function customer_has_saved_methods( $customer_id ) {
125-
$gateways = [ WC_Stripe_UPE_Payment_Gateway::ID, WC_Gateway_Stripe_Sepa::ID ];
125+
$gateways = [ WC_Stripe_UPE_Payment_Gateway::ID, WC_Stripe_Payment_Methods::LEGACY_SEPA ];
126126

127127
if ( empty( $customer_id ) ) {
128128
return false;
@@ -220,7 +220,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
220220
}
221221
}
222222

223-
if ( WC_Gateway_Stripe_Sepa::ID === $gateway_id ) {
223+
if ( WC_Stripe_Payment_Methods::LEGACY_SEPA === $gateway_id ) {
224224
$stripe_customer = new WC_Stripe_Customer( $customer_id );
225225
$stripe_sources = $stripe_customer->get_sources();
226226

@@ -229,7 +229,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
229229
if ( ! isset( $stored_tokens[ $source->id ] ) ) {
230230
$token = new WC_Payment_Token_SEPA();
231231
$token->set_token( $source->id );
232-
$token->set_gateway_id( WC_Gateway_Stripe_Sepa::ID );
232+
$token->set_gateway_id( WC_Stripe_Payment_Methods::LEGACY_SEPA );
233233
$token->set_last4( $source->sepa_debit->last4 );
234234
$token->set_user_id( $customer_id );
235235
if ( isset( $source->sepa_debit->fingerprint ) ) {
@@ -496,7 +496,7 @@ public function woocommerce_payment_token_deleted( $token_id, $token ) {
496496
}
497497

498498
$stripe_customer->detach_payment_method( $token->get_token() );
499-
} elseif ( WC_Stripe_UPE_Payment_Gateway::ID === $token->get_gateway_id() || WC_Gateway_Stripe_Sepa::ID === $token->get_gateway_id() ) {
499+
} elseif ( WC_Stripe_UPE_Payment_Gateway::ID === $token->get_gateway_id() || WC_Stripe_Payment_Methods::LEGACY_SEPA === $token->get_gateway_id() ) {
500500
$stripe_customer->delete_source( $token->get_token() );
501501
}
502502
} catch ( WC_Stripe_Exception $e ) {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 10.2.0 - xxxx-xx-xx =
114+
* Dev - Replace the constant reference for the legacy SEPA payment method
114115
* Update - Changes the list of payment methods shown in the Stripe account connection modal
115116
* Update - Changes labels related to saved payment methods from "cards" to "payment methods"
116117
* Fix - Ensure Amazon Pay, Apple Pay, and Google Pay display settings are managed correctly

tests/phpunit/Admin/Migrations/WC_Stripe_Subscriptions_Repairer_Legacy_SEPA_Tokens_Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Exception;
66
use PHPUnit\Framework\MockObject\MockObject;
7+
use WC_Stripe_Payment_Methods;
78
use WooCommerce\Stripe\Tests\Helpers\UPE_Test_Helper;
8-
use WC_Gateway_Stripe_Sepa;
99
use WC_Logger;
1010
use WC_Stripe_API;
1111
use WC_Stripe_Database_Cache;
@@ -68,7 +68,7 @@ class WC_Stripe_Subscriptions_Repairer_Legacy_SEPA_Tokens_Test extends WP_UnitTe
6868
*
6969
* @var string
7070
*/
71-
private $legacy_sepa_gateway_id = WC_Gateway_Stripe_Sepa::ID;
71+
private $legacy_sepa_gateway_id = WC_Stripe_Payment_Methods::LEGACY_SEPA;
7272

7373
public function set_up() {
7474
parent::set_up();

tests/phpunit/Helpers/WC_Helper_Token.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace WooCommerce\Stripe\Tests\Helpers;
44

55
use WC_Stripe_UPE_Payment_Gateway;
6-
use WC_Gateway_Stripe_Sepa;
76
use WC_Payment_Token_CC;
87
use WC_Payment_Token_SEPA;
98
use WC_Payment_Tokens;
@@ -42,9 +41,9 @@ public static function create_token( $payment_method, $user_id = null, $gateway
4241
*
4342
* @param string $payment_method Token payment method.
4443
* @param int $user_id ID of the token's user, defaults to get_current_user_id().
45-
* @param string $gateway Token's Gateway ID, default to WC_Gateway_Stripe_Sepa::ID
44+
* @param string $gateway Token's Gateway ID, default to WC_Stripe_Payment_Methods::LEGACY_SEPA
4645
*/
47-
public static function create_sepa_token( $payment_method, $user_id = null, $gateway = WC_Gateway_Stripe_Sepa::ID ) {
46+
public static function create_sepa_token( $payment_method, $user_id = null, $gateway = WC_Stripe_Payment_Methods::LEGACY_SEPA ) {
4847
$token = new WC_Payment_Token_SEPA();
4948
$token->set_payment_method_type( WC_Stripe_Payment_Methods::SEPA_DEBIT );
5049
$token->set_token( $payment_method );

0 commit comments

Comments
 (0)