Skip to content

Commit 67c924b

Browse files
wjrosadaledupreez
andauthored
Fixing and simplifying payment tokens comparison (#4667)
* Simplifying payment tokens comparison * Fix cashapp token gateway ID * Fix CashApp comparison method * Changelog and readme entries * Update includes/payment-tokens/class-wc-stripe-ach-payment-token.php Co-authored-by: daledupreez <[email protected]> * Update includes/payment-tokens/class-wc-stripe-becs-debit-payment-token.php Co-authored-by: daledupreez <[email protected]> --------- Co-authored-by: daledupreez <[email protected]>
1 parent 16fc507 commit 67c924b

12 files changed

+32
-41
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
= 9.10.0 - xxxx-xx-xx =
4+
* Fix - Minor fixes and code improvements for the saved payment methods comparison logic
45
* Dev - Upgrades Node to v20
56
* Add - Allow the purchase of free trials using the Express Payment methods when the product does not require shipping
67
* Update - Changes the documentation page URL for the Optimized Checkout feature to https://woocommerce.com/document/stripe/admin-experience/optimized-checkout-suite/

includes/payment-methods/class-wc-stripe-upe-payment-method-cash-app-pay.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public function get_retrievable_type() {
7474
public function create_payment_token_for_user( $user_id, $payment_method ) {
7575
$token = new WC_Payment_Token_CashApp();
7676

77-
$gateway_id = $this->is_oc_enabled() ? 'stripe' : $this->id;
78-
79-
$token->set_gateway_id( $gateway_id );
77+
$token->set_gateway_id( WC_Stripe_Payment_Tokens::UPE_REUSABLE_GATEWAYS_BY_PAYMENT_METHOD[ self::STRIPE_ID ] );
8078
$token->set_token( $payment_method->id );
8179
$token->set_user_id( $user_id );
8280

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,11 @@ public function set_last4( $last4 ) {
161161
* @inheritDoc
162162
*/
163163
public function is_equal_payment_method( $payment_method ): bool {
164-
if (
165-
WC_Stripe_Payment_Methods::ACH === $payment_method->type
166-
&& ( $payment_method->{WC_Stripe_Payment_Methods::ACH}->fingerprint ?? null ) === $this->get_fingerprint() ) {
167-
return true;
164+
if ( WC_Stripe_Payment_Methods::ACH !== $payment_method->type ) {
165+
return false;
168166
}
169167

170-
return false;
168+
// ACH uses the `us_bank_account` property
169+
return ( $payment_method->us_bank_account->fingerprint ?? null ) === $this->get_fingerprint();
171170
}
172171
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ class WC_Payment_Token_ACSS extends WC_Payment_Token implements WC_Stripe_Paymen
4141
* @return bool
4242
*/
4343
public function is_equal_payment_method( $payment_method ): bool {
44-
if ( WC_Stripe_Payment_Methods::ACSS_DEBIT === $payment_method->type
45-
&& ( $payment_method->acss_debit->fingerprint ?? null ) === $this->get_fingerprint() ) {
46-
return true;
44+
if ( WC_Stripe_Payment_Methods::ACSS_DEBIT !== $payment_method->type ) {
45+
return false;
4746
}
4847

49-
return false;
48+
return ( $payment_method->acss_debit->fingerprint ?? null ) === $this->get_fingerprint();
5049
}
5150

5251
/**

includes/payment-tokens/class-wc-stripe-amazon-pay-payment-token.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ public function set_email( $email ) {
7979
* @inheritDoc
8080
*/
8181
public function is_equal_payment_method( $payment_method ): bool {
82-
if ( WC_Stripe_Payment_Methods::AMAZON_PAY === $payment_method->type
83-
&& ( $payment_method->billing_details->email ?? null ) === $this->get_email() ) {
84-
return true;
82+
if ( WC_Stripe_Payment_Methods::AMAZON_PAY !== $payment_method->type ) {
83+
return false;
8584
}
8685

87-
return false;
86+
return ( $payment_method->billing_details->email ?? null ) === $this->get_email();
8887
}
8988
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ class WC_Payment_Token_Bacs_Debit extends WC_Payment_Token implements WC_Stripe_
4040
* @return bool
4141
*/
4242
public function is_equal_payment_method( $payment_method ): bool {
43-
if ( WC_Stripe_Payment_Methods::BACS_DEBIT === $payment_method->type
44-
&& ( $payment_method->bacs_debit->fingerprint ?? null ) === $this->get_fingerprint() ) {
45-
return true;
43+
if ( WC_Stripe_Payment_Methods::BACS_DEBIT !== $payment_method->type ) {
44+
return false;
4645
}
4746

48-
return false;
47+
return ( $payment_method->bacs_debit->fingerprint ?? null ) === $this->get_fingerprint();
4948
}
5049

5150
/**

includes/payment-tokens/class-wc-stripe-becs-debit-payment-token.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ public function set_last4( $last4 ) {
111111
* @inheritDoc
112112
*/
113113
public function is_equal_payment_method( $payment_method ): bool {
114-
if (
115-
WC_Stripe_Payment_Methods::BECS_DEBIT === $payment_method->type
116-
&& ( $payment_method->{WC_Stripe_Payment_Methods::BECS_DEBIT}->fingerprint ?? null ) === $this->get_fingerprint() ) {
117-
return true;
114+
if ( WC_Stripe_Payment_Methods::BECS_DEBIT !== $payment_method->type ) {
115+
return false;
118116
}
119117

120-
return false;
118+
// Becs Debit uses the au_becs_debit property.
119+
return ( $payment_method->au_becs_debit->fingerprint ?? null ) === $this->get_fingerprint();
121120
}
122121
}

includes/payment-tokens/class-wc-stripe-cash-app-payment-token.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ public function get_cashtag() {
6767
* @inheritDoc
6868
*/
6969
public function is_equal_payment_method( $payment_method ): bool {
70-
if ( WC_Stripe_Payment_Methods::CASHAPP_PAY === $this->get_type()
71-
&& ( $payment_method->cashapp->cashtag ?? null ) === $this->get_cashtag() ) {
72-
return true;
70+
if ( WC_Stripe_Payment_Methods::CASHAPP_PAY !== $payment_method->type ) {
71+
return false;
7372
}
7473

75-
return false;
74+
return ( $payment_method->cashapp->cashtag ?? null ) === $this->get_cashtag();
7675
}
7776

7877
/**

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public function __construct( $token = '' ) {
3535
* @inheritDoc
3636
*/
3737
public function is_equal_payment_method( $payment_method ): bool {
38-
if ( WC_Stripe_Payment_Methods::CARD === $payment_method->type
39-
&& ( $payment_method->card->fingerprint ?? null ) === $this->get_fingerprint() ) {
40-
return true;
38+
if ( WC_Stripe_Payment_Methods::CARD !== $payment_method->type ) {
39+
return false;
4140
}
4241

43-
return false;
42+
return ( $payment_method->card->fingerprint ?? null ) === $this->get_fingerprint();
4443
}
4544
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ public function set_email( $email ) {
9898
* @inheritDoc
9999
*/
100100
public function is_equal_payment_method( $payment_method ): bool {
101-
if ( WC_Stripe_Payment_Methods::LINK === $payment_method->type
102-
&& ( $payment_method->link->email ?? null ) === $this->get_email() ) {
103-
return true;
101+
if ( WC_Stripe_Payment_Methods::LINK !== $payment_method->type ) {
102+
return false;
104103
}
105104

106-
return false;
105+
return ( $payment_method->link->email ?? null ) === $this->get_email();
107106
}
108107
}

0 commit comments

Comments
 (0)