Skip to content

Commit

Permalink
get data from wcSettings on block checkout if 'wc_stripe_upe_params' …
Browse files Browse the repository at this point in the history
…is not loaded yet
  • Loading branch information
Mayisha committed Sep 6, 2024
1 parent 94200c7 commit 9c16864
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions client/stripe-utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global wc_stripe_upe_params */
/* global wc_stripe_upe_params, wc */
import { dispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { getAppearance } from '../styles/upe';
Expand All @@ -21,13 +21,24 @@ import {
* @return {StripeServerData} Stripe server data.
*/
const getStripeServerData = () => {
// Classic checkout.
let data = null;

// eslint-disable-next-line camelcase
if ( typeof wc_stripe_upe_params === 'undefined' ) {
return {};
if ( typeof wc_stripe_upe_params !== 'undefined' ) {
data = wc_stripe_upe_params; // eslint-disable-line camelcase
} else if (
typeof wc === 'object' &&
typeof wc.wcSettings !== 'undefined'
) {
// 'getSetting' has this data value on block checkout only.
data = wc.wcSettings?.getSetting( 'getSetting' ) || null;
}
// eslint-disable-next-line camelcase
return wc_stripe_upe_params;

if ( ! data ) {
throw new Error( 'Stripe initialization data is not available' );
}

return data;
};

const isNonFriendlyError = ( type ) =>
Expand Down

0 comments on commit 9c16864

Please sign in to comment.