diff --git a/ghost/portal/src/components/pages/OfferPage.js b/ghost/portal/src/components/pages/OfferPage.js index 62e148af1d..5934945d32 100644 --- a/ghost/portal/src/components/pages/OfferPage.js +++ b/ghost/portal/src/components/pages/OfferPage.js @@ -3,7 +3,7 @@ import AppContext from '../../AppContext'; import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg'; import CloseButton from '../common/CloseButton'; import InputForm from '../common/InputForm'; -import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature} from '../../utils/helpers'; +import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature, isSameCurrency} from '../../utils/helpers'; import {ValidateInputForm} from '../../utils/form'; const React = require('react'); @@ -445,7 +445,7 @@ export default class OfferPage extends React.Component { const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice; const originalAmount = price.amount; let updatedAmount; - if (offer.type === 'fixed' && offer.currency === price.currency) { + if (offer.type === 'fixed' && isSameCurrency(offer.currency, price.currency)) { updatedAmount = ((originalAmount - offer.amount)) / 100; return updatedAmount > 0 ? updatedAmount : 0; } else if (offer.type === 'percent') { diff --git a/ghost/portal/src/utils/helpers.js b/ghost/portal/src/utils/helpers.js index dd9a325947..db5ef231f2 100644 --- a/ghost/portal/src/utils/helpers.js +++ b/ghost/portal/src/utils/helpers.js @@ -484,6 +484,10 @@ export const createPopupNotification = ({type, status, autoHide, duration, close }; }; +export function isSameCurrency(currency1, currency2) { + return currency1?.toLowerCase() === currency2?.toLowerCase(); +} + export function getPriceIdFromPageQuery({site, pageQuery}) { const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/; const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/; diff --git a/ghost/portal/src/utils/helpers.test.js b/ghost/portal/src/utils/helpers.test.js index 53dadb3dc5..ca555d4b65 100644 --- a/ghost/portal/src/utils/helpers.test.js +++ b/ghost/portal/src/utils/helpers.test.js @@ -1,4 +1,4 @@ -import {getPriceIdFromPageQuery} from './helpers'; +import {getPriceIdFromPageQuery, isSameCurrency} from './helpers'; import * as Fixtures from './fixtures'; describe('Helpers - ', () => { @@ -11,4 +11,21 @@ describe('Helpers - ', () => { const value = mockPriceIdFn({site: siteData, pageQuery}); expect(value).toBe(expectedPriceId); }); + describe('isSameCurrency - ', () => { + test('can match two currencies correctly ', () => { + let currency1 = 'USD'; + let currency2 = 'USD'; + expect(isSameCurrency(currency1, currency2)).toBe(true); + }); + test('can match currencies with case mismatch', () => { + let currency1 = 'USD'; + let currency2 = 'usd'; + expect(isSameCurrency(currency1, currency2)).toBe(true); + }); + test('can match currencies with case mismatch', () => { + let currency1 = 'eur'; + let currency2 = 'usd'; + expect(isSameCurrency(currency1, currency2)).toBe(false); + }); + }); });