Skip to content

Conversation

@frosso
Copy link
Contributor

@frosso frosso commented Nov 20, 2025

Fixes WOOPMNT-5514

(for the most part) Fixes #10366
Fixes #9683
Fixes WOOPMNT-4453
Fixes #10310

Changes proposed in this Pull Request

As part of having Google Pay and Apple Pay be part of the payment methods displayed at checkout, I am slightly refactoring the codebase to ensure that Google Pay and Apple Pay have their own payment definition (and payment method defined) in WooPayments.
Before these changes, Google Pay and Apple Pay "piggyback" off the "card" payment method.
With these changes, we're ensuring that they have their own separate definition.

With these new changes, the available_payment_method_ids returned in the settings also returns apple_pay and google_pay, paving the path for unified settings storage.
RIght now, the Google Pay and Apple Pay enablement is controlled by the payment_request setting.
Moving forward, we can deprecate such setting and simplify part of the codebase to ensure that Google Pay and Apple Pay can be enabled/disabled like any other payment method.

Since we have a Google Pay/Apple Pay payment definition, I also refactored some of the hardcoded strings in the settings to use the wooPaymentsPaymentMethodDefinitions global.

Within these changes, I also reviewed the payment flow.
I noticed we have both payment_request_type and express_payment_type as part of the $_POST data.
The two attributes contain the same value.
They were introduced as part of the ECE refactor, but never removed.
I am ensuring that we'll always use express_payment_type moving forward, and I removed payment_request_type.

I also tweaked the behavior of the payment method label on the "order success" page.

I added inline comments on most changes of the PR, let me know if you have any questions.

Testing instructions

  • Enable Google Pay/Apple Pay under Payments > Settings
  • Ensure that the store is accessible via public HTTPS URL (e.g. with Jurassic Ninja/Jurassic Tube)
  • Add a product to the cart and go to checkout
  • Click on the Google Pay button and complete the checkout
  • Make sure that the payment is completed & order confirmation is received
  • The "Order success" page should show Google Pay ending in 4242
Screenshot 2025-11-21 at 2 46 03 PM

(the icon size is similar to other payment methods)
Screenshot 2025-11-21 at 2 46 06 PM

  • As a merchant, navigate to the order in WooCommerce > Orders
  • The page should show Payment via Google Pay (WooPayments)
Screenshot 2025-11-21 at 10 35 36 AM
  • 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

@frosso frosso requested a review from Copilot November 20, 2025 21:04
Copilot finished reviewing on behalf of frosso November 20, 2025 21:08
@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 11144 or branch name feat/add-apple-pay-google-pay-definitions 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: 91afd58
  • Build time: 2025-11-24 12:02:09 UTC

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors Apple Pay and Google Pay implementation by introducing centralized payment method definitions and standardizing field naming from payment_request_type to express_payment_type.

  • Adds ApplePayDefinition and GooglePayDefinition classes following the existing payment method definition pattern
  • Migrates hardcoded payment method titles and descriptions to use centralized definitions from the payment method map
  • Removes deprecated payment_request_type field in favor of express_payment_type throughout the codebase

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
includes/payment-methods/Configs/Definitions/ApplePayDefinition.php New payment method definition for Apple Pay with complete implementation of PaymentMethodDefinitionInterface
includes/payment-methods/Configs/Definitions/GooglePayDefinition.php New payment method definition for Google Pay with complete implementation of PaymentMethodDefinitionInterface
includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php Registers the new Apple Pay and Google Pay definitions in the registry
includes/class-wc-payments-token-service.php Adds wallet metadata support for tokenized payment methods and filter to display wallet names
includes/express-checkout/class-wc-payments-express-checkout-ajax-handler.php Refactors to use payment method definitions for titles instead of hardcoded array
includes/express-checkout/class-wc-payments-express-checkout-button-helper.php Removes deprecated method that's now handled in ajax handler
includes/express-checkout/class-wc-payments-express-checkout-button-handler.php Removes hook for deprecated method
includes/class-wc-payments-order-success-page.php Adds support for displaying express checkout payment methods on order success page
includes/class-wc-payment-gateway-wcpay.php Maps Apple Pay and Google Pay to card_payments capability and handles fee availability
includes/woopay/services/class-checkout-service.php Removes check for deprecated payment_request_type field
includes/constants/class-payment-method.php Adds GOOGLE_PAY and APPLE_PAY constants
includes/admin/class-wc-payments-admin.php Fixes trailing comma typo in multiCurrencySetup configuration
client/constants/payment-method.ts Adds APPLE_PAY and GOOGLE_PAY to TypeScript enum
client/payment-methods-icons.tsx Removes ApplePayIcon and GooglePayIcon exports (now from definitions)
client/settings/express-checkout/apple-google-pay-item.tsx Refactors to use icons and labels from payment methods map
client/settings/express-checkout-settings/index.js Refactors to use icons from payment methods map
client/settings/payment-methods-section/index.js Filters out Apple Pay and Google Pay from main payment methods section
client/disable-confirmation-modal/index.js Refactors to use icons and labels from payment methods map
client/express-checkout/utils/normalize.js Removes deprecated payment_request_type field
client/express-checkout/transformers/stripe-to-wc.js Removes deprecated payment_request_type field
tests/js/jest-test-file-setup.js Adds mock definitions for Google Pay and Apple Pay
tests/unit/test-class-wc-payments-token-service.php Adds comprehensive test coverage for wallet metadata handling
tests/unit/test-class-wc-payment-gateway-wcpay.php Updates test to use express_payment_type
tests/unit/payment-methods/test-class-upe-payment-gateway.php Updates test to use express_payment_type
client/express-checkout/utils/tests/normalize.test.js Updates tests to remove deprecated payment_request_type field
changelog/feat-add-apple-pay-google-pay-definitions Adds changelog entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Size Change: +796 B (0%)

Total Size: 876 kB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout.js 54.6 kB +15 B (0%)
release/woocommerce-payments/dist/checkout.js 34.6 kB +21 B (0%)
release/woocommerce-payments/dist/express-checkout.js 16.8 kB -8 B (0%)
release/woocommerce-payments/dist/index-rtl.css 21.2 kB +12 B (0%)
release/woocommerce-payments/dist/index.css 21.3 kB +11 B (0%)
release/woocommerce-payments/dist/index.js 154 kB +859 B (+1%)
release/woocommerce-payments/dist/multi-currency.js 24.7 kB -78 B (0%)
release/woocommerce-payments/dist/settings.js 141 kB -36 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.45 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.45 kB
release/woocommerce-payments/assets/css/success.css 1.06 kB
release/woocommerce-payments/assets/css/success.rtl.css 1.06 kB
release/woocommerce-payments/dist/blocks-checkout-rtl.css 3.05 kB
release/woocommerce-payments/dist/blocks-checkout.css 3.05 kB
release/woocommerce-payments/dist/cart-block-rtl.css 113 B
release/woocommerce-payments/dist/cart-block.css 112 B
release/woocommerce-payments/dist/cart-block.js 16.7 kB
release/woocommerce-payments/dist/cart.js 5.27 kB
release/woocommerce-payments/dist/checkout-rtl.css 1.13 kB
release/woocommerce-payments/dist/checkout.css 1.13 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 367 B
release/woocommerce-payments/dist/express-checkout.css 367 B
release/woocommerce-payments/dist/frontend-tracks.js 833 B
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.82 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 18.2 kB
release/woocommerce-payments/dist/multi-currency.css 3.83 kB
release/woocommerce-payments/dist/order-rtl.css 740 B
release/woocommerce-payments/dist/order.css 740 B
release/woocommerce-payments/dist/order.js 21.3 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 484 B
release/woocommerce-payments/dist/plugins-page.css 484 B
release/woocommerce-payments/dist/plugins-page.js 2.64 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.3 kB
release/woocommerce-payments/dist/settings-rtl.css 11.8 kB
release/woocommerce-payments/dist/settings.css 11.7 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 1.98 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 1.9 kB
release/woocommerce-payments/dist/success.js 6.03 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 3 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 5.68 kB
release/woocommerce-payments/dist/woopay-express-button.js 22.8 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.27 kB
release/woocommerce-payments/dist/woopay.css 4.25 kB
release/woocommerce-payments/dist/woopay.js 70.8 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 957 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.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.css 10.1 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.js 29.7 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.rtl.css 10.1 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/jetpack-users-connection.js 161 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 585 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 625 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

Comment on lines +45 to +48
// methods displayed in the Express Checkout section
PAYMENT_METHOD_IDS.LINK !== id &&
PAYMENT_METHOD_IDS.APPLE_PAY !== id &&
PAYMENT_METHOD_IDS.GOOGLE_PAY !== id
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this could be refactored in the future with a is_express attribute in the payment method, kinda like is_bnpl 🤷

'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
'multiCurrencySetup' => [
'isSetupCompleted' => filter_var( get_option( 'wcpay_multi_currency_setup_completed' ), FILTER_VALIDATE_BOOLEAN ) ? 'yes' : 'no,',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tweaking a little comma that I found by chance

*
* @return void
*/
public function add_order_payment_method_title( $order_id ) {
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 was not used in the payment flow. See explanation in includes/express-checkout/class-wc-payments-express-checkout-button-handler.php.

add_filter( 'woocommerce_cart_needs_shipping_address', [ $this, 'filter_cart_needs_shipping_address' ], 11, 1 );
add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );
add_filter( 'woocommerce_gateway_title', [ $this, 'filter_gateway_title' ], 10, 2 );
add_action( 'woocommerce_checkout_order_processed', [ $this->express_checkout_helper, 'add_order_payment_method_title' ], 10, 2 );
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 hook was not used in the payment flow.
The woocommerce_checkout_order_processed action is invoked on the "classic" checkout.
The older implementation of the ECE/PRB leveraged the classic checkout.
But the newer one uses the Store API. And the Store API doesn't call this action.


$methods_with_fees = array_keys( $this->account->get_fees() );

// Google Pay and Apple Pay use card payment fees, so if card is available, they should be too.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically, this change also ensures that google_pay and apple_pay are returned as part of the available_payment_method_ids in the settings.
This change will also come useful when we'll migrate to Google Pay and Apple Pay as individual payment methods at checkout.

$this->maybe_add_customer_notification_note( $order, $processing );

// ensuring the payment method title is set before any early return paths to avoid incomplete order data.
if ( empty( $_POST['payment_request_type'] ) && empty( $_POST['express_payment_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
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 deprecated the payment_request_type.
I moved this check below:

if ( empty( $_POST['express_payment_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
	$this->set_payment_method_title_for_order( $order, $payment_method_type, $payment_method_details );
}

It turns out that we want to keep the $order->add_meta_data( 'last4', ...) and the $order->add_meta_data( '_card_brand', ...) instructions, to ensure we can display the last 4 digits of the payment method on the "Order received" page.

Image

Otherwise the "order received" page would look like this:

Image

Comment on lines +191 to +195
// Check if this is an Express Checkout payment (Google Pay, Apple Pay, etc.).
$express_checkout_payment_method = $order->get_meta( '_wcpay_express_checkout_payment_method' );
if ( ! empty( $express_checkout_payment_method ) ) {
return $this->show_express_checkout_payment_method_name( $order, $express_checkout_payment_method );
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alters the "Order received" page.

Before these changes, it showed just "Card":

Image

Now it shows if the payment was done with one of the wallets:
Image

*
* @return string
*/
public function show_express_checkout_payment_method_name( $order, $express_checkout_payment_method ) {
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

Comment on lines +188 to +189
google_pay: buildMockDefinition( 'google_pay', 'Google Pay' ),
apple_pay: buildMockDefinition( 'apple_pay', 'Apple Pay' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed for testing - because the wooPaymentsPaymentMethodDefinitions global is not populated from the server-side.

</div>
<div className="express-checkout__label express-checkout__label-mobile">
{ __( 'Apple Pay', 'woocommerce-payments' ) }
{ methodsConfiguration.apple_pay.label }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing hardcoded values and using the server-side labels and descriptions.


return (
<span className="payment-method-details">
<WalletIcon payment={ payment } />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shows the wallet icon next to the payment

Image

Unfortunately, it's not possible to show the wallet icon on the transactions list, because it's missing the wallet information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants