From 7627f38b583096dd7853973cc88c5c161994503e Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:36:25 +1100 Subject: [PATCH] Send wc_ prefixed fields for express payments. --- .../use-express-checkout-product-handler.js | 12 +++++++++++- client/payment-request/index.js | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/client/checkout/woopay/express-button/use-express-checkout-product-handler.js b/client/checkout/woopay/express-button/use-express-checkout-product-handler.js index 5567cb4a1ae..3df0c452888 100644 --- a/client/checkout/woopay/express-button/use-express-checkout-product-handler.js +++ b/client/checkout/woopay/express-button/use-express-checkout-product-handler.js @@ -2,6 +2,7 @@ * External dependencies */ import validator from 'validator'; +import { applyFilters } from '@wordpress/hooks'; const useExpressCheckoutProductHandler = ( api ) => { const getAttributes = () => { @@ -104,6 +105,14 @@ const useExpressCheckoutProductHandler = ( api ) => { } const addOnForm = document.querySelector( 'form.cart' ); + let allowedFieldNames = applyFilters( + 'wcpayPaymentRequestAllowedFieldNames', + [] + ); + // Ensure allowedFieldNames is an array. + if ( ! Array.isArray( allowedFieldNames ) ) { + allowedFieldNames = [ allowedFieldNames ]; + } if ( addOnForm ) { const formData = new FormData( addOnForm ); @@ -111,7 +120,8 @@ const useExpressCheckoutProductHandler = ( api ) => { formData.forEach( ( value, name ) => { if ( /^addon-/.test( name ) || - /^wc_gc_giftcard_/.test( name ) + /^wc_/.test( name ) || + allowedFieldNames.includes( name ) ) { if ( /\[\]$/.test( name ) ) { const fieldName = name.substring( 0, name.length - 2 ); diff --git a/client/payment-request/index.js b/client/payment-request/index.js index 9578b42517c..2933cac2088 100644 --- a/client/payment-request/index.js +++ b/client/payment-request/index.js @@ -3,7 +3,7 @@ * External dependencies */ import { __ } from '@wordpress/i18n'; -import { doAction } from '@wordpress/hooks'; +import { applyFilters, doAction } from '@wordpress/hooks'; /** * Internal dependencies */ @@ -175,8 +175,19 @@ jQuery( ( $ ) => { // Add addons data to the POST body const formData = $( 'form.cart' ).serializeArray(); + let allowedFieldNames = applyFilters( + 'wcpayPaymentRequestAllowedFieldNames', + [] + ); + // Ensure allowedFieldNames is an array. + if ( ! Array.isArray( allowedFieldNames ) ) { + allowedFieldNames = [ allowedFieldNames ]; + } $.each( formData, ( i, field ) => { - if ( /^addon-/.test( field.name ) ) { + if ( + allowedFieldNames.includes( field.name ) || + /^(addon-|wc_)/.test( field.name ) + ) { if ( /\[\]$/.test( field.name ) ) { const fieldName = field.name.substring( 0,