-
Notifications
You must be signed in to change notification settings - Fork 72
refactor: add Apple Pay and Google Pay definitions #11144
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
base: develop
Are you sure you want to change the base?
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. |
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.
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
ApplePayDefinitionandGooglePayDefinitionclasses 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_typefield in favor ofexpress_payment_typethroughout 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.
includes/payment-methods/Configs/Definitions/ApplePayDefinition.php
Outdated
Show resolved
Hide resolved
includes/payment-methods/Configs/Definitions/GooglePayDefinition.php
Outdated
Show resolved
Hide resolved
|
Size Change: +796 B (0%) Total Size: 876 kB
ℹ️ View Unchanged
|
| // methods displayed in the Express Checkout section | ||
| PAYMENT_METHOD_IDS.LINK !== id && | ||
| PAYMENT_METHOD_IDS.APPLE_PAY !== id && | ||
| PAYMENT_METHOD_IDS.GOOGLE_PAY !== id |
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.
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,', |
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.
Just tweaking a little comma that I found by chance
| * | ||
| * @return void | ||
| */ | ||
| public function add_order_payment_method_title( $order_id ) { |
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 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 ); |
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 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. |
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.
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 |
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 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.
Otherwise the "order received" page would look like this:
| // 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 ); | ||
| } |
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.
| * | ||
| * @return string | ||
| */ | ||
| public function show_express_checkout_payment_method_name( $order, $express_checkout_payment_method ) { |
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.
See above
| google_pay: buildMockDefinition( 'google_pay', 'Google Pay' ), | ||
| apple_pay: buildMockDefinition( 'apple_pay', 'Apple Pay' ), |
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.
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 } |
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.
Removing hardcoded values and using the server-side labels and descriptions.
|
|
||
| return ( | ||
| <span className="payment-method-details"> | ||
| <WalletIcon payment={ payment } /> |
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.



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_idsreturned in the settings also returnsapple_payandgoogle_pay, paving the path for unified settings storage.RIght now, the Google Pay and Apple Pay enablement is controlled by the
payment_requestsetting.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
wooPaymentsPaymentMethodDefinitionsglobal.Within these changes, I also reviewed the payment flow.
I noticed we have both
payment_request_typeandexpress_payment_typeas part of the$_POSTdata.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_typemoving forward, and I removedpayment_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
Google Pay ending in 4242(the icon size is similar to other payment methods)

Payment via Google Pay (WooPayments)Repeat the purchase process from the product page
(extra, but not required) confirm the behavior described in WooPayments Refund Option Missing for Orders added Manually and Paid via Apple Pay using the Customer Payment Link #10310
npm run changelogto add a changelog file, choosepatchto 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