-
Notifications
You must be signed in to change notification settings - Fork 206
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
Conversation
…woocommerce/woocommerce-gateway-stripe into dev/introducing-test-mode-class
…the-new-test-mode-class
…thub.com/woocommerce/woocommerce-gateway-stripe into dev/implementing-the-new-test-mode-class
There was a problem hiding this 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' ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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`
Thanks for the review, Mayisha! I have updated the remaining occurrences in 4a232be.
Yeah, that's a good idea. I will work on that later 👀 |
@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 👍 |
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:
Since this is just a refactoring PR, no behavior should change.
changelog.txt
andreadme.txt
(or does not apply)Post merge