Skip to content

Commit

Permalink
Using constants when checking for payment method detach (#3581)
Browse files Browse the repository at this point in the history
* Using constants when checking for payment method detach

* Changelog and readme.txt entries

* Replacing all occurrences in the same file
  • Loading branch information
wjrosa authored Nov 11, 2024
1 parent d77461f commit 09caab4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 8.9.0 - xxxx-xx-xx =
* Dev - Replace two occurrences of payment method names with their constant equivalents.
* Fix - Hide express checkout when credit card payments are not enabled.
* Fix - Fix issues when detaching payment methods on staging sites (with the new checkout experience enabled).
* Fix - Display a notice if taxes vary by customer's billing address when checking out using the Stripe Express Checkout Element.
Expand Down
18 changes: 9 additions & 9 deletions includes/class-wc-stripe-payment-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function get_token_from_request( array $request ) {
* @return bool
*/
public static function customer_has_saved_methods( $customer_id ) {
$gateways = [ 'stripe', 'stripe_sepa' ];
$gateways = [ WC_Gateway_Stripe::ID, WC_Gateway_Stripe_Sepa::ID ];

if ( empty( $customer_id ) ) {
return false;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
$stored_tokens[ $token->get_token() ] = $token;
}

if ( 'stripe' === $gateway_id ) {
if ( WC_Gateway_Stripe::ID === $gateway_id ) {
$stripe_customer = new WC_Stripe_Customer( $customer_id );
$stripe_sources = $stripe_customer->get_sources();

Expand All @@ -175,7 +175,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
if ( ! isset( $stored_tokens[ $source->id ] ) ) {
$token = new WC_Payment_Token_CC();
$token->set_token( $source->id );
$token->set_gateway_id( 'stripe' );
$token->set_gateway_id( WC_Gateway_Stripe::ID );

if ( WC_Stripe_Helper::is_card_payment_method( $source ) ) {
$token->set_card_type( strtolower( $source->card->brand ) );
Expand All @@ -194,7 +194,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
if ( ! isset( $stored_tokens[ $source->id ] ) && WC_Stripe_Payment_Methods::CARD === $source->object ) {
$token = new WC_Payment_Token_CC();
$token->set_token( $source->id );
$token->set_gateway_id( 'stripe' );
$token->set_gateway_id( WC_Gateway_Stripe::ID );
$token->set_card_type( strtolower( $source->brand ) );
$token->set_last4( $source->last4 );
$token->set_expiry_month( $source->exp_month );
Expand All @@ -209,7 +209,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
}
}

if ( 'stripe_sepa' === $gateway_id ) {
if ( WC_Gateway_Stripe_Sepa::ID === $gateway_id ) {
$stripe_customer = new WC_Stripe_Customer( $customer_id );
$stripe_sources = $stripe_customer->get_sources();

Expand All @@ -218,7 +218,7 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
if ( ! isset( $stored_tokens[ $source->id ] ) ) {
$token = new WC_Payment_Token_SEPA();
$token->set_token( $source->id );
$token->set_gateway_id( 'stripe_sepa' );
$token->set_gateway_id( WC_Gateway_Stripe_Sepa::ID );
$token->set_last4( $source->sepa_debit->last4 );
$token->set_user_id( $customer_id );
$token->save();
Expand Down Expand Up @@ -272,7 +272,7 @@ public function woocommerce_get_customer_upe_payment_tokens( $tokens, $user_id,
// - APM tokens from before Split PE was in place.
// - Non-credit card tokens using the sources API. Payments using these will fail with the PaymentMethods API.
if (
( 'stripe' === $token->get_gateway_id() && WC_Stripe_Payment_Methods::SEPA === $token->get_type() ) ||
( WC_Gateway_Stripe::ID === $token->get_gateway_id() && WC_Stripe_Payment_Methods::SEPA === $token->get_type() ) ||
! $this->is_valid_payment_method_id( $token->get_token(), $this->get_payment_method_type_from_token( $token ) )
) {
$deprecated_tokens[ $token->get_token() ] = $token;
Expand Down Expand Up @@ -435,7 +435,7 @@ public function woocommerce_payment_token_deleted( $token_id, $token ) {

$stripe_customer->detach_payment_method( $token->get_token() );
} else {
if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
if ( WC_Gateway_Stripe::ID === $token->get_gateway_id() || WC_Gateway_Stripe_Sepa::ID === $token->get_gateway_id() ) {
$stripe_customer->delete_source( $token->get_token() );
}
}
Expand All @@ -460,7 +460,7 @@ public function woocommerce_payment_token_set_default( $token_id ) {
$stripe_customer->set_default_payment_method( $token->get_token() );
}
} else {
if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
if ( WC_Gateway_Stripe::ID === $token->get_gateway_id() || WC_Gateway_Stripe_Sepa::ID === $token->get_gateway_id() ) {
$stripe_customer->set_default_source( $token->get_token() );
}
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 8.9.0 - xxxx-xx-xx =
* Dev - Replace two occurrences of payment method names with their constant equivalents.
* Fix - Hide express checkout when credit card payments are not enabled.
* Fix - Fix issues when detaching payment methods on staging sites (with the new checkout experience enabled).
* Fix - Display a notice if taxes vary by customer's billing address when checking out using the Stripe Express Checkout Element.
Expand Down

0 comments on commit 09caab4

Please sign in to comment.