Blocks: load payment request button configuration in the Blocks Checkout PHP handler instead of relying on configuration loaded for the Shortcode checkout #2604
We currently rely on the JS configuration loaded for the shortcode checkout here in the block-based checkout (see for example how we use the wcpayPaymentRequestParams global here).
This is bad for at least 2 reasons:
We already have specific handlers for the Payment Request Buttons in the block-based integration JS, and the shortcode JS may contain some duplicate handlers that can potentially mess with the payment flow.
Loading unnecessary JS has performance impacts that can significantly slow down the checkout experience for no gain.
Proposed solution
Extract the configuration object into it's own function (similar to what we did in the Stripe plugin).
Use that function to load the payment request configuration into the Blocks settings here.
Stop using the wcpayPaymentRequestParams global in the block integration JS.
Are we relying on some JS from the shortcode JS in the block integration JS?
If yes, then we should remove that dependency and implement everything in the block integration JS.
How will this affect other theme builders with their own custom cart and checkout blocks, if at all?
Themes to look out for here that we've made mistakes with in the past (see pc4etw-aT-p2): CartFlows, possibly others.
What possible side effects could a refactor like this have?
Can we introduce unit (or even e2e) tests here that help us make sure the refactor doesn't break any existing functionality? Do these tests already exist?
Similar to the changes introduced in Stripe: https://github.com/woocommerce/woocommerce-gateway-stripe/pull/1585
Problem
We currently rely on the JS configuration loaded for the shortcode checkout here in the block-based checkout (see for example how we use the
wcpayPaymentRequestParams
global here).This is bad for at least 2 reasons:
Proposed solution
wcpayPaymentRequestParams
global in the block integration JS.Look at https://github.com/woocommerce/woocommerce-gateway-stripe/pull/1585 for inspiration.
Things to consider and test