mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
✨ Introduce price-matrix and currency-formatting
This commit is contained in:
parent
bdb53dfced
commit
478002dc32
3 changed files with 74 additions and 22 deletions
|
@ -1,8 +1,19 @@
|
||||||
import { __, sprintf } from '@wordpress/i18n';
|
import { __, sprintf } from '@wordpress/i18n';
|
||||||
|
|
||||||
import { countryPriceInfo } from '../../utils/countryPriceInfo';
|
|
||||||
import TitleBadge, { TITLE_BADGE_INFO } from './TitleBadge';
|
|
||||||
import { CommonHooks } from '../../data';
|
import { CommonHooks } from '../../data';
|
||||||
|
import { countryPriceInfo } from '../../utils/countryPriceInfo';
|
||||||
|
import { formatPrice } from '../../utils/formatPrice';
|
||||||
|
import TitleBadge, { TITLE_BADGE_INFO } from './TitleBadge';
|
||||||
|
|
||||||
|
const getFixedAmount = ( currency, priceList ) => {
|
||||||
|
if ( priceList[ currency ] ) {
|
||||||
|
return formatPrice( priceList[ currency ], currency );
|
||||||
|
}
|
||||||
|
|
||||||
|
const [ defaultCurrency, defaultPrice ] = Object.entries( priceList )[ 0 ];
|
||||||
|
|
||||||
|
return formatPrice( defaultPrice, defaultCurrency );
|
||||||
|
};
|
||||||
|
|
||||||
const PricingTitleBadge = ( { item } ) => {
|
const PricingTitleBadge = ( { item } ) => {
|
||||||
const { storeCountry } = CommonHooks.useWooSettings();
|
const { storeCountry } = CommonHooks.useWooSettings();
|
||||||
|
@ -13,13 +24,12 @@ const PricingTitleBadge = ( { item } ) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const percentage = infos[ item ].toFixed( 2 );
|
const percentage = infos[ item ].toFixed( 2 );
|
||||||
const fixedFee = `${ infos.currencySymbol }${ infos.fixedFee }`;
|
const fixedAmount = getFixedAmount( storeCountry, infos.fixedFee );
|
||||||
|
|
||||||
const label = sprintf(
|
const label = sprintf(
|
||||||
__( 'from %1$s%% + %2$s %3$s', 'woocommerce-paypal-payments' ),
|
__( 'from %1$s%% + %2$s', 'woocommerce-paypal-payments' ),
|
||||||
percentage,
|
percentage,
|
||||||
fixedFee,
|
fixedAmount
|
||||||
infos.currencySymbol
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
export const countryPriceInfo = {
|
export const countryPriceInfo = {
|
||||||
US: {
|
US: {
|
||||||
currencySymbol: '$',
|
fixedFee: {
|
||||||
fixedFee: 0.49,
|
USD: 0.49,
|
||||||
|
},
|
||||||
checkout: 3.49,
|
checkout: 3.49,
|
||||||
ccf: 2.59,
|
ccf: 2.59,
|
||||||
dw: 2.59,
|
dw: 2.59,
|
||||||
|
@ -10,8 +11,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 2.99,
|
standardCardFields: 2.99,
|
||||||
},
|
},
|
||||||
UK: {
|
UK: {
|
||||||
currencySymbol: '£',
|
fixedFee: {
|
||||||
fixedFee: 0.3,
|
GPB: 0.3,
|
||||||
|
},
|
||||||
checkout: 2.9,
|
checkout: 2.9,
|
||||||
ccf: 1.2,
|
ccf: 1.2,
|
||||||
dw: 1.2,
|
dw: 1.2,
|
||||||
|
@ -19,8 +21,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 1.2,
|
standardCardFields: 1.2,
|
||||||
},
|
},
|
||||||
CA: {
|
CA: {
|
||||||
currencySymbol: '$',
|
fixedFee: {
|
||||||
fixedFee: 0.3,
|
CAD: 0.3,
|
||||||
|
},
|
||||||
checkout: 2.9,
|
checkout: 2.9,
|
||||||
ccf: 2.7,
|
ccf: 2.7,
|
||||||
dw: 2.7,
|
dw: 2.7,
|
||||||
|
@ -28,8 +31,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 2.9,
|
standardCardFields: 2.9,
|
||||||
},
|
},
|
||||||
AU: {
|
AU: {
|
||||||
currencySymbol: '$',
|
fixedFee: {
|
||||||
fixedFee: 0.3,
|
AUD: 0.3,
|
||||||
|
},
|
||||||
checkout: 2.6,
|
checkout: 2.6,
|
||||||
ccf: 1.75,
|
ccf: 1.75,
|
||||||
dw: 1.75,
|
dw: 1.75,
|
||||||
|
@ -37,8 +41,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 2.6,
|
standardCardFields: 2.6,
|
||||||
},
|
},
|
||||||
FR: {
|
FR: {
|
||||||
currencySymbol: '€',
|
fixedFee: {
|
||||||
fixedFee: 0.35,
|
EUR: 0.35,
|
||||||
|
},
|
||||||
checkout: 2.9,
|
checkout: 2.9,
|
||||||
ccf: 1.2,
|
ccf: 1.2,
|
||||||
dw: 1.2,
|
dw: 1.2,
|
||||||
|
@ -46,8 +51,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 1.2,
|
standardCardFields: 1.2,
|
||||||
},
|
},
|
||||||
IT: {
|
IT: {
|
||||||
currencySymbol: '€',
|
fixedFee: {
|
||||||
fixedFee: 0.35,
|
EUR: 0.35,
|
||||||
|
},
|
||||||
checkout: 3.4,
|
checkout: 3.4,
|
||||||
ccf: 1.2,
|
ccf: 1.2,
|
||||||
dw: 1.2,
|
dw: 1.2,
|
||||||
|
@ -55,8 +61,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 1.2,
|
standardCardFields: 1.2,
|
||||||
},
|
},
|
||||||
DE: {
|
DE: {
|
||||||
currencySymbol: '€',
|
fixedFee: {
|
||||||
fixedFee: 0.39,
|
EUR: 0.39,
|
||||||
|
},
|
||||||
checkout: 2.99,
|
checkout: 2.99,
|
||||||
ccf: 2.99,
|
ccf: 2.99,
|
||||||
dw: 2.99,
|
dw: 2.99,
|
||||||
|
@ -64,8 +71,9 @@ export const countryPriceInfo = {
|
||||||
standardCardFields: 2.99,
|
standardCardFields: 2.99,
|
||||||
},
|
},
|
||||||
ES: {
|
ES: {
|
||||||
currencySymbol: '€',
|
fixedFee: {
|
||||||
fixedFee: 0.35,
|
EUR: 0.35,
|
||||||
|
},
|
||||||
checkout: 2.9,
|
checkout: 2.9,
|
||||||
ccf: 1.2,
|
ccf: 1.2,
|
||||||
dw: 1.2,
|
dw: 1.2,
|
||||||
|
|
34
modules/ppcp-settings/resources/js/utils/formatPrice.js
Normal file
34
modules/ppcp-settings/resources/js/utils/formatPrice.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const priceFormatInfo = {
|
||||||
|
USD: {
|
||||||
|
prefix: '$',
|
||||||
|
suffix: 'USD',
|
||||||
|
},
|
||||||
|
CAD: {
|
||||||
|
prefix: '$',
|
||||||
|
suffix: 'CAD',
|
||||||
|
},
|
||||||
|
AUD: {
|
||||||
|
prefix: '$',
|
||||||
|
suffix: 'AUD',
|
||||||
|
},
|
||||||
|
EUR: {
|
||||||
|
prefix: '€',
|
||||||
|
suffix: '',
|
||||||
|
},
|
||||||
|
GPB: {
|
||||||
|
prefix: '£',
|
||||||
|
suffix: '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const formatPrice = ( value, currency ) => {
|
||||||
|
const currencyInfo = priceFormatInfo[ currency ];
|
||||||
|
const amount = value.toFixed( 2 );
|
||||||
|
|
||||||
|
if ( ! currencyInfo ) {
|
||||||
|
console.error( `Unsupported currency: ${ currency }` );
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${ currencyInfo.prefix }${ amount } ${ currencyInfo.suffix }`;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue