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

Implementing the new test mode class #3584

Merged
merged 18 commits into from
Nov 14, 2024

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Nov 4, 2024

Base PR #3583

Changes proposed in this Pull Request:

This is a simple refactoring PR implementing the new WC_Stripe_Mode (added in #3583). The purpose here is to reduce many of our duplicated codes by checking for the test mode setting and centralizing the logic on that class.

This is based on the same approach we have in WooPayments.

Testing instructions

Code review. Check if the tests are still passing. You can also perform some smoke testing:

  • Connect your Stripe account to your test store (test mode and live)
  • Enable and disable some payment methods
  • Purchase some products as a customer

Since this is just a refactoring PR, no behavior should change.


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

@wjrosa wjrosa self-assigned this Nov 4, 2024
@wjrosa wjrosa mentioned this pull request Nov 12, 2024
6 tasks
Base automatically changed from dev/introducing-test-mode-class to develop November 13, 2024 11:32
@wjrosa wjrosa marked this pull request as ready for review November 13, 2024 11:33
@wjrosa wjrosa requested review from a team and Mayisha and removed request for a team November 13, 2024 11:50
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good 👍

✅ Reconnected to my Stripe account in live mode.
✅ Reconnected to my Stripe account in test mode.
✅ Payment with regular card.
✅ Payment with 3ds card.
✅ Payment with regular card.
✅ Payment with GPay
✅ Payment with SEPA, iDeal
✅ Payment with Multibanco (voucher)
✅ Payment with Cash App (wallet)
✅ Payment with Klarna (bnpl)

Noticed that there are still a couple of places where we have $stettings['testmode'] instead of calling the new function. Those instances are from recently merged PRs like this one. Before merging this, let's give the codebase another scan.

I have another thought for future enhancement. With this newly introduced class, we are still getting the settings or testmode from the DB option everytime we make a call to this function. We can keep the data in the class to avoid this.

@@ -24,6 +24,6 @@ public static function is_live() {
*/
public static function is_test() {
$settings = WC_Stripe_Helper::get_stripe_settings();
return 'yes' === $settings['testmode'];
return 'yes' === ( $settings['testmode'] ?? 'no' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a very unusual scenario, but if in any case $settings['testmode'] is not defined the is_live and is_test both functions will return false.

Probably is_live should return true in this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that as well. But I did a test here, and it behaves as you suggested already:

var_dump( 'yes' !== ( $settings['testmode'] ?? 'no' ) ); // `is_live()`: prints `true`
var_dump( 'yes' === ( $settings['testmode'] ?? 'no' ) ); // `is_test()`: prints `false`

@wjrosa
Copy link
Contributor Author

wjrosa commented Nov 14, 2024

Noticed that there are still a couple of places where we have $stettings['testmode'] instead of calling the new function. Those instances are from recently merged PRs like this one. Before merging this, let's give the codebase another scan.

Thanks for the review, Mayisha! I have updated the remaining occurrences in 4a232be.

I have another thought for future enhancement. With this newly introduced class, we are still getting the settings or testmode from the DB option everytime we make a call to this function. We can keep the data in the class to avoid this.

Yeah, that's a good idea. I will work on that later 👀

@wjrosa
Copy link
Contributor Author

wjrosa commented Nov 14, 2024

@Mayisha I have rewritten the class in ac19e7a making it simpler and persisting the mode inside the static property. In case you think it is not good, I can revert this change.

Edit: tests broke. Looking into it

Edit 2: I decided to revert the change for now and merge this. I will work on refactoring this later 👍

@wjrosa wjrosa merged commit 3fc2608 into develop Nov 14, 2024
33 of 35 checks passed
@wjrosa wjrosa deleted the dev/implementing-the-new-test-mode-class branch November 14, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants