Skip to content

Commit

Permalink
Merge branch 'develop' into 5951-send-payment-method-update-data
Browse files Browse the repository at this point in the history
  • Loading branch information
gpressutto5 authored Feb 22, 2024
2 parents c2ea1a2 + db01f50 commit 448849b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changelog/fix-check-wc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Checking if wc.wcSettings is correctly set in checkou.js. This will not change anything as other extensions and even WC itself depends on it being correctly set, so it's just a minor enhancement.


28 changes: 15 additions & 13 deletions client/utils/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
*/
export const getConfig = ( name ) => {
// Classic checkout or blocks-based one.
let config = null;
if ( typeof wcpayConfig !== 'undefined' ) {
config = wcpayConfig;
} else if ( typeof wcpay_upe_config !== 'undefined' ) {
config = wcpay_upe_config;
} else if ( typeof wc !== 'undefined' ) {
config = wc.wcSettings.getSetting( 'woocommerce_payments_data' );
} else {
return null;
return wcpayConfig[ name ];
}

return config[ name ] || null;
// eslint-disable-next-line no-use-before-define
return getUPEConfig( name );
};

/**
Expand All @@ -30,10 +24,18 @@ export const getConfig = ( name ) => {
*/
export const getUPEConfig = ( name ) => {
// Classic checkout or blocks-based one.
const config =
typeof wcpay_upe_config !== 'undefined'
? wcpay_upe_config
: wc.wcSettings.getSetting( 'woocommerce_payments_data' );
let config = null;
if ( typeof wcpay_upe_config !== 'undefined' ) {
config = wcpay_upe_config;
} else if (
typeof wc === 'object' &&
typeof wc.wcSettings !== 'undefined'
) {
// If getSettings or woocommerce_payments_data is not available, default to an empty object so we return null bellow.
config = wc.wcSettings.getSetting( 'woocommerce_payments_data' ) || {};
} else {
return null;
}

return config[ name ] || null;
};

0 comments on commit 448849b

Please sign in to comment.