-
Notifications
You must be signed in to change notification settings - Fork 69
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
Register Expresss Checkout block only when enabled in the settings #9646
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Size Change: +8 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
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.
Clear change and tests well, I just left one minor comment, up to you to decide on whether you want to apply it or not. Thanks @gpressutto5
if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) { | ||
if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) { | ||
registerExpressPaymentMethod( | ||
tokenizedCartPaymentRequestPaymentMethod( api ) | ||
); | ||
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) { | ||
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) ); | ||
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) ); | ||
} else { | ||
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) ); | ||
} | ||
} |
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.
This is a matter of preference, but I started to find the below approach more readable after some time in our back-end PHP:
if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) { | |
if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) { | |
registerExpressPaymentMethod( | |
tokenizedCartPaymentRequestPaymentMethod( api ) | |
); | |
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) { | |
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) ); | |
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) ); | |
} else { | |
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) ); | |
} | |
} | |
if (!getUPEConfig('isPaymentRequestEnabled')) { | |
return; | |
} | |
if (getUPEConfig('isTokenizedCartPrbEnabled')) { | |
registerExpressPaymentMethod(tokenizedCartPaymentRequestPaymentMethod(api)); | |
return; | |
} | |
if (getUPEConfig('isExpressCheckoutElementEnabled')) { | |
registerExpressPaymentMethod(expressCheckoutElementApplePay(api)); | |
registerExpressPaymentMethod(expressCheckoutElementGooglePay(api)); | |
return; | |
} | |
registerExpressPaymentMethod(paymentRequestPaymentMethod(api)); |
feel free to ignore it if the change does not seem convincing.
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 is indeed more readable, but we have more code after that we want to execute regardless of PRB/ECE settings. If we want to early return we need to create a new function for this so it doesn't affect the rest of the code. But then I think it starts to get less readable, what do you think?
if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) { | |
if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) { | |
registerExpressPaymentMethod( | |
tokenizedCartPaymentRequestPaymentMethod( api ) | |
); | |
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) { | |
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) ); | |
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) ); | |
} else { | |
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) ); | |
} | |
} | |
const maybeRegisterExpressCheckoutMethod = () => { | |
if (!getUPEConfig('isPaymentRequestEnabled')) { | |
return; | |
} | |
if (getUPEConfig('isTokenizedCartPrbEnabled')) { | |
registerExpressPaymentMethod(tokenizedCartPaymentRequestPaymentMethod(api)); | |
return; | |
} | |
if (getUPEConfig('isExpressCheckoutElementEnabled')) { | |
registerExpressPaymentMethod(expressCheckoutElementApplePay(api)); | |
registerExpressPaymentMethod(expressCheckoutElementGooglePay(api)); | |
return; | |
} | |
registerExpressPaymentMethod(paymentRequestPaymentMethod(api)); | |
} | |
maybeRegisterExpressCheckoutMethod(); |
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.
Yeah, agreed, I'd keep it as it is then without changing your final version 👍 🚢
Thanks for the review ping, just got round to it but looks like I'm a bit late. Great to see this shipped though, nice work! 🎉 |
Fixes #9444
Changes proposed in this Pull Request
The Google & Apple Pay buttons were displayed in editor even when the payment method is disabled in WooPayments settings because they were always registered. This PR adds a check before registering them.
Testing instructions
develop
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge