♻️ Move branded-only detection to server side

This commit is contained in:
Philipp Stracker 2025-03-25 14:21:43 +01:00
parent 9d16b19bd4
commit 807fd96183
No known key found for this signature in database
4 changed files with 19 additions and 8 deletions

View file

@ -32,7 +32,16 @@ const defaultTransient = Object.freeze( {
wooSettings: Object.freeze( {
storeCountry: '',
storeCurrency: '',
installationPath: '',
/**
* The "branded-only" experience is determined on server-side, based on the installation path.
*
* When true, the plugin must only display "PayPal's own brand" payment options
* i.e. no card payments or Apple Pay/Google Pay.
*
* @type {boolean}
*/
ownBrandOnly: false,
} ),
features: Object.freeze( {

View file

@ -43,10 +43,11 @@ export const features = ( state ) => {
export const wooSettings = ( state ) => {
const settings = getState( state ).wooSettings || EMPTY_OBJ;
// For development and testing. Remove this eventually!
const simulateBrandedOnly = localStorage.getItem( 'simulate-branded-only' );
/**
* The "branded only experience" is determined based on the installation path.
* The "own-brand-only" experience is determined on server-side, based on the installation path.
*
* When true, the plugin must only display "PayPal's own brand" payment options
* i.e. no card payments or Apple Pay/Google Pay.
@ -54,9 +55,7 @@ export const wooSettings = ( state ) => {
* @type {boolean}
*/
const ownBrandOnly =
'true' === simulateBrandedOnly || // For development and testing. Remove this eventually!
settings.installationPath === 'core-profile' ||
settings.installationPath === 'payment-settings';
'true' === simulateBrandedOnly || settings.ownBrandOnly;
return { ...settings, ownBrandOnly };
};

View file

@ -131,7 +131,7 @@ class GeneralSettings extends AbstractDataModel {
public function get_woo_settings() : array {
$settings = $this->woo_settings;
$settings['installation_path'] = $this->get_installation_path();
$settings['own_brand_only'] = $this->own_brand_only();
return $settings;
}

View file

@ -108,12 +108,15 @@ class CommonRestEndpoint extends RestEndpoint {
* @var array
*/
private array $woo_settings_map = array(
'country' => array(
'country' => array(
'js_name' => 'storeCountry',
),
'currency' => array(
'currency' => array(
'js_name' => 'storeCurrency',
),
'own_brand_only' => array(
'js_name' => 'ownBrandOnly',
),
);
/**