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

chore: ECE copy for tokenized cart implementation #9730

Merged

Conversation

frosso
Copy link
Contributor

@frosso frosso commented Nov 15, 2024

Fixes #9721

Changes proposed in this Pull Request

Continuing the groundwork to pave the path for a modification of the ECE to leverage the Store API.

I'm creating a copy of the ECE JS, so it can be modified.
This allows us to modify it in isolation, making safe changes.

Testing instructions

  • Update your WooPayments Dev Tools
  • Enable the "Enable Cart-Token implementation for ECE" feature flag
  • Restart your webpack build (npm run start)
  • As a merchant, ensure you have GooglePay/ApplePay enabled in the WooPayments settings (for product pages, cart, checkout)
  • As a customer, go to a product page for a simple product
  • You should see the GooglePay button in Chrome
  • If you look at the dev tools, the tokenized-express-checkout JS should be enqueued, indicating that the new scripts are being used

  • Run npm run changelog to add a changelog file, choose patch 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.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Nov 15, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 9730 or branch name chore/copy-of-express-checkout-ece-for-tokenized-feature-flag in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

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:

  • Latest commit: eb1222f
  • Build time: 2024-11-15 14:45:39 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Nov 15, 2024

Size Change: -3.93 kB (0%)

Total Size: 1.33 MB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.66 kB +4 B (0%)
release/woocommerce-payments/dist/blocks-checkout.css 2.66 kB +5 B (0%)
release/woocommerce-payments/dist/blocks-checkout.js 52.7 kB -3.86 kB (-7%)
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 0 B -230 B (removed) 🏆
release/woocommerce-payments/dist/tokenized-payment-request.css 0 B -230 B (removed) 🏆
release/woocommerce-payments/dist/tokenized-payment-request.js 0 B -14.9 kB (removed) 🏆
release/woocommerce-payments/dist/tokenized-express-checkout-rtl.css 230 B +230 B (new file) 🆕
release/woocommerce-payments/dist/tokenized-express-checkout.css 230 B +230 B (new file) 🆕
release/woocommerce-payments/dist/tokenized-express-checkout.js 14.8 kB +14.8 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.37 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.37 kB
release/woocommerce-payments/assets/css/success.css 172 B
release/woocommerce-payments/assets/css/success.rtl.css 173 B
release/woocommerce-payments/dist/cart-block.js 16.8 kB
release/woocommerce-payments/dist/cart.js 5.73 kB
release/woocommerce-payments/dist/checkout-rtl.css 1.23 kB
release/woocommerce-payments/dist/checkout.css 1.23 kB
release/woocommerce-payments/dist/checkout.js 33 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 230 B
release/woocommerce-payments/dist/express-checkout.css 230 B
release/woocommerce-payments/dist/express-checkout.js 14.8 kB
release/woocommerce-payments/dist/frontend-tracks.js 854 B
release/woocommerce-payments/dist/index-rtl.css 52.6 kB
release/woocommerce-payments/dist/index.css 52.5 kB
release/woocommerce-payments/dist/index.js 302 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 4.46 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.6 kB
release/woocommerce-payments/dist/multi-currency.css 4.46 kB
release/woocommerce-payments/dist/multi-currency.js 57.3 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/order.js 42 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.32 kB
release/woocommerce-payments/dist/payment-gateways.css 1.32 kB
release/woocommerce-payments/dist/payment-gateways.js 38.4 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 20.1 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12.1 kB
release/woocommerce-payments/dist/settings-rtl.css 11.6 kB
release/woocommerce-payments/dist/settings.css 11.5 kB
release/woocommerce-payments/dist/settings.js 224 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.2 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.3 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21.8 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.13 kB
release/woocommerce-payments/dist/woopay-express-button.js 24.5 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.52 kB
release/woocommerce-payments/dist/woopay.css 4.49 kB
release/woocommerce-payments/dist/woopay.js 71.6 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 767 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/react-jsx-runtime.js 553 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.2 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 417 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 584 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 621 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

@@ -22,7 +22,10 @@ import {
expressCheckoutElementApplePay,
expressCheckoutElementGooglePay,
} from '../../express-checkout/blocks';
import tokenizedCartPaymentRequestPaymentMethod from '../../tokenized-payment-request/blocks';
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 left the old JS there to reduce the number of changes & so it can be removed later.
I replaced it with the copy of the ECE implementation (from client/express-checkout to client/tokenized-express-checkout).

@@ -0,0 +1,154 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from client/express-checkout/blocks/components/express-checkout-component.js

@@ -0,0 +1,42 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from client/express-checkout/blocks/components/express-checkout-container.js

@@ -0,0 +1,108 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from client/express-checkout/blocks/components/express-checkout-preview.js

@@ -0,0 +1,23 @@
// Cart Block
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from client/express-checkout/blocks/express-checkout-element.scss

@@ -0,0 +1,44 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from client/express-checkout/utils/test/index.ts

Comment on lines -74 to -80
$script_dependencies = [ 'stripe' ];

if ( WC_Payments_Features::is_tokenized_cart_ece_enabled() && ( is_cart() || is_checkout() || is_product() || has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' ) ) ) {
$script_dependencies[] = 'WCPAY_PAYMENT_REQUEST';
}

WC_Payments::register_script_with_dependencies( 'WCPAY_BLOCKS_CHECKOUT', 'dist/blocks-checkout', $script_dependencies );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how the PRBs were enqueued. The ECE is enqueued differently, we're keeping it that way.
So this block with the WCPAY_PAYMENT_REQUEST script has become deprecated, and can now be simplified.


$express_checkout_ajax_handler = new WC_Payments_Express_Checkout_Ajax_Handler( self::get_express_checkout_helper() );
$express_checkout_element_button_handler = new WC_Payments_Express_Checkout_Button_Handler( self::$account, self::get_gateway(), self::get_express_checkout_helper(), $express_checkout_ajax_handler );
$express_checkout_button_display_handler = new WC_Payments_Express_Checkout_Button_Display_Handler( self::get_gateway(), $payment_request_button_handler, $woopay_button_handler, $express_checkout_element_button_handler, $express_checkout_ajax_handler, self::get_express_checkout_helper() );
$express_checkout_button_display_handler = new WC_Payments_Express_Checkout_Button_Display_Handler( self::get_gateway(), $woopay_button_handler, $express_checkout_element_button_handler, $express_checkout_ajax_handler, self::get_express_checkout_helper() );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I removed the WC_Payments_Payment_Request_Button_Handler as part of the dependencies of WC_Payments_Express_Checkout_Button_Display_Handler. We won't need that in the ECE.
But I'm keeping the file for future reference.
I marked the WC_Payments_Payment_Request_Button_Handler as @deprecated, but it's not enqueued anywhere.

@@ -21,13 +21,6 @@ class WC_Payments_Express_Checkout_Button_Display_Handler {
*/
private $gateway;

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above - removed WC_Payments_Payment_Request_Button_Handler as part of the dependencies of WC_Payments_Express_Checkout_Button_Display_Handler

@@ -260,14 +260,39 @@ public function scripts() {
'is_checkout_page' => $this->express_checkout_helper->is_checkout(),
];

WC_Payments::register_script_with_dependencies( 'WCPAY_EXPRESS_CHECKOUT_ECE', 'dist/express-checkout', [ 'jquery', 'stripe' ] );
if ( WC_Payments_Features::is_tokenized_cart_ece_enabled() ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating some branching logic to enqueue the "tokenized" ECE vs the non-tokenized ECE.
The "tokenized" ECE is the copy of the files, all part of this PR.
They're not "tokenized" yet - they're just a copy of the ECE implementation.
The tokenization efforts are part of #9722

@frosso frosso marked this pull request as ready for review November 15, 2024 13:57
@frosso frosso requested review from a team and mdmoore and removed request for a team November 15, 2024 13:57
@frosso frosso self-assigned this Nov 15, 2024
@@ -442,7 +442,6 @@ public static function init() {
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-ajax-handler.php';
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-button-display-handler.php';
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-button-handler.php';
include_once __DIR__ . '/class-wc-payments-payment-request-button-handler.php';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I deprecated the class, I figured I'd also remove its include_once.
It is still included in the tests/unit/bootstrap.php PHPunit bootstrap file, but just because there's a UT that still exists.

Comment on lines -306 to -325
public function test_display_express_checkout_buttons_only_payment_request() {
$this->mock_woopay_button_handler
->method( 'should_show_woopay_button' )
->willReturn( false );

$this->mock_payment_request_button_handler
->method( 'should_show_payment_request_button' )
->willReturn( true );

$this->mock_express_checkout_helper
->method( 'is_checkout' )
->willReturn( true );

ob_start();
$this->express_checkout_button_display_handler->display_express_checkout_buttons();

$this->assertStringContainsString( 'wcpay-express-checkout-button-separator', ob_get_contents() );
$this->assertStringContainsString( 'display:none;', ob_get_contents() );
ob_end_clean();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole test case is no longer needed because the payment_request_button_handler has been removed.

@frosso frosso changed the title chore: ECE copy for tokenized cart chore: ECE copy for tokenized cart implementation Nov 15, 2024
Copy link
Member

@mdmoore mdmoore left a comment

Choose a reason for hiding this comment

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

The changes look good and the tokenized-express-checkout script is enqueued as expected. 🚢

@frosso frosso added this pull request to the merge queue Nov 15, 2024
Merged via the queue into develop with commit f358e9d Nov 15, 2024
25 checks passed
@frosso frosso deleted the chore/copy-of-express-checkout-ece-for-tokenized-feature-flag branch November 15, 2024 20:51
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.

Create Copy of ECE JavaScript Implementation for Store API Integration
3 participants