Skip to content

Commit

Permalink
Revert "feat: add UPE appearance filter (#7578)" (#7722)
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso committed Nov 15, 2023
1 parent 11c0686 commit 781c83c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 40 deletions.
3 changes: 2 additions & 1 deletion client/checkout/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
7 changes: 2 additions & 5 deletions client/checkout/blocks/upe-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
7 changes: 2 additions & 5 deletions client/checkout/blocks/upe-split-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ describe( 'Stripe Payment Element mounting', () => {
} );

getUPEConfig.mockImplementation( ( argument ) => {
if (
argument === 'wcBlocksUPEAppearance' ||
argument === 'upeAppearance'
) {
return {};
}

if ( argument === 'currency' ) {
return 'eur';
}
Expand Down
3 changes: 2 additions & 1 deletion client/checkout/classic/upe-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
3 changes: 2 additions & 1 deletion client/checkout/classic/upe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
10 changes: 1 addition & 9 deletions includes/payment-methods/class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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' => [
Expand Down

0 comments on commit 781c83c

Please sign in to comment.