From 781c83ced0a0509d1dea5bd78f65989cfa0aae43 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 15 Nov 2023 04:20:43 -0800 Subject: [PATCH] Revert "feat: add UPE appearance filter (#7578)" (#7722) --- client/checkout/api/index.js | 3 ++- .../upe-deferred-intent-creation/payment-elements.js | 7 ++----- client/checkout/blocks/upe-fields.js | 7 ++----- client/checkout/blocks/upe-split-fields.js | 7 ++----- .../payment-processing.js | 12 ++++++------ .../test/payment-processing.test.js | 7 ------- client/checkout/classic/upe-split.js | 3 ++- client/checkout/classic/upe.js | 3 ++- .../payment-methods/class-upe-payment-gateway.php | 10 +--------- 9 files changed, 19 insertions(+), 40 deletions(-) diff --git a/client/checkout/api/index.js b/client/checkout/api/index.js index bab84c6790e..b7deafca8af 100644 --- a/client/checkout/api/index.js +++ b/client/checkout/api/index.js @@ -553,7 +553,8 @@ export default class WCPayAPI { _ajax_nonce: getConfig( 'saveUPEAppearanceNonce' ), } ) .then( ( response ) => { - return response.data; + // There is not any action to take or harm caused by a failed update, so just returning success status. + return response.success; } ) .catch( ( error ) => { if ( error.message ) { diff --git a/client/checkout/blocks/upe-deferred-intent-creation/payment-elements.js b/client/checkout/blocks/upe-deferred-intent-creation/payment-elements.js index 7e43346486a..36abca3728f 100644 --- a/client/checkout/blocks/upe-deferred-intent-creation/payment-elements.js +++ b/client/checkout/blocks/upe-deferred-intent-creation/payment-elements.js @@ -24,11 +24,8 @@ const PaymentElements = ( { api, ...props } ) => { useEffect( () => { async function generateUPEAppearance() { // Generate UPE input styles. - let upeAppearance = getAppearance( true ); - upeAppearance = await api.saveUPEAppearance( - upeAppearance, - 'true' - ); + const upeAppearance = getAppearance( true ); + await api.saveUPEAppearance( upeAppearance, 'true' ); setAppearance( upeAppearance ); } diff --git a/client/checkout/blocks/upe-fields.js b/client/checkout/blocks/upe-fields.js index c248d7b949b..9f1ea7d67ee 100644 --- a/client/checkout/blocks/upe-fields.js +++ b/client/checkout/blocks/upe-fields.js @@ -295,11 +295,8 @@ const ConsumableWCPayFields = ( { api, ...props } ) => { useEffect( () => { async function generateUPEAppearance() { // Generate UPE input styles. - let upeAppearance = getAppearance( true ); - upeAppearance = await api.saveUPEAppearance( - upeAppearance, - 'true' - ); + const upeAppearance = getAppearance( true ); + await api.saveUPEAppearance( upeAppearance, 'true' ); // Update appearance state setAppearance( upeAppearance ); diff --git a/client/checkout/blocks/upe-split-fields.js b/client/checkout/blocks/upe-split-fields.js index 5961ae7607e..07b9f720da1 100644 --- a/client/checkout/blocks/upe-split-fields.js +++ b/client/checkout/blocks/upe-split-fields.js @@ -301,11 +301,8 @@ const ConsumableWCPayFields = ( { api, ...props } ) => { useEffect( () => { async function generateUPEAppearance() { // Generate UPE input styles. - let upeAppearance = getAppearance( true ); - upeAppearance = await api.saveUPEAppearance( - upeAppearance, - 'true' - ); + const upeAppearance = getAppearance( true ); + await api.saveUPEAppearance( upeAppearance, 'true' ); // Update appearance state setAppearance( upeAppearance ); diff --git a/client/checkout/classic/upe-deferred-intent-creation/payment-processing.js b/client/checkout/classic/upe-deferred-intent-creation/payment-processing.js index 82937a1e194..513a0b87a5e 100644 --- a/client/checkout/classic/upe-deferred-intent-creation/payment-processing.js +++ b/client/checkout/classic/upe-deferred-intent-creation/payment-processing.js @@ -41,13 +41,13 @@ for ( const paymentMethodType in getUPEConfig( 'paymentMethodsConfig' ) ) { * @param {Object} api The API object used to save the UPE configuration. * @return {Object} The appearance object for the UPE. */ -async function initializeAppearance( api ) { - const appearance = getUPEConfig( 'upeAppearance' ); - if ( appearance ) { - return appearance; +function initializeAppearance( api ) { + let appearance = getUPEConfig( 'upeAppearance' ); + if ( ! appearance ) { + appearance = getAppearance(); + api.saveUPEAppearance( appearance ); } - - return await api.saveUPEAppearance( getAppearance() ); + return appearance; } /** diff --git a/client/checkout/classic/upe-deferred-intent-creation/test/payment-processing.test.js b/client/checkout/classic/upe-deferred-intent-creation/test/payment-processing.test.js index 44bb0efba7e..05970174879 100644 --- a/client/checkout/classic/upe-deferred-intent-creation/test/payment-processing.test.js +++ b/client/checkout/classic/upe-deferred-intent-creation/test/payment-processing.test.js @@ -266,13 +266,6 @@ describe( 'Stripe Payment Element mounting', () => { } ); getUPEConfig.mockImplementation( ( argument ) => { - if ( - argument === 'wcBlocksUPEAppearance' || - argument === 'upeAppearance' - ) { - return {}; - } - if ( argument === 'currency' ) { return 'eur'; } diff --git a/client/checkout/classic/upe-split.js b/client/checkout/classic/upe-split.js index 09018bd73f9..05ad9f1de49 100644 --- a/client/checkout/classic/upe-split.js +++ b/client/checkout/classic/upe-split.js @@ -210,7 +210,8 @@ jQuery( function ( $ ) { let appearance = getUPEConfig( 'upeAppearance' ); if ( ! appearance ) { - appearance = await api.saveUPEAppearance( getAppearance() ); + appearance = getAppearance(); + api.saveUPEAppearance( appearance ); } const elements = api.getStripe().elements( { diff --git a/client/checkout/classic/upe.js b/client/checkout/classic/upe.js index eb684a9e10d..519a6f39b80 100644 --- a/client/checkout/classic/upe.js +++ b/client/checkout/classic/upe.js @@ -244,7 +244,8 @@ jQuery( function ( $ ) { let appearance = getConfig( 'upeAppearance' ); if ( ! appearance ) { - appearance = await api.saveUPEAppearance( getAppearance() ); + appearance = getAppearance(); + api.saveUPEAppearance( appearance ); } elements = api.getStripe().elements( { diff --git a/includes/payment-methods/class-upe-payment-gateway.php b/includes/payment-methods/class-upe-payment-gateway.php index 59c1beccfaa..7023ba0ca2d 100644 --- a/includes/payment-methods/class-upe-payment-gateway.php +++ b/includes/payment-methods/class-upe-payment-gateway.php @@ -1104,14 +1104,6 @@ public function save_upe_appearance_ajax() { $is_blocks_checkout = isset( $_POST['is_blocks_checkout'] ) ? rest_sanitize_boolean( wc_clean( wp_unslash( $_POST['is_blocks_checkout'] ) ) ) : false; $appearance = isset( $_POST['appearance'] ) ? json_decode( wc_clean( wp_unslash( $_POST['appearance'] ) ) ) : null; - /** - * This filter is only called on "save" of the appearance, to avoid calling it on every page load. - * If you apply changes through this filter, you'll need to clear the transient data to see them at checkout. - * - * @since 6.8.0 - */ - $appearance = apply_filters( 'wcpay_upe_appearance', $appearance, $is_blocks_checkout ); - $appearance_transient = $is_blocks_checkout ? self::WC_BLOCKS_UPE_APPEARANCE_TRANSIENT : self::UPE_APPEARANCE_TRANSIENT; if ( null !== $appearance ) { @@ -1120,7 +1112,7 @@ public function save_upe_appearance_ajax() { wp_send_json_success( $appearance, 200 ); } catch ( Exception $e ) { - // Send back error, so it can be displayed to the customer. + // Send back error so it can be displayed to the customer. wp_send_json_error( [ 'error' => [