Skip to content

Commit

Permalink
Merge pull request #784 from Financial-Times/trial-as-non-trial-hack
Browse files Browse the repository at this point in the history
ACQ-2592: add an isTrialOfferAsNonTrialOverride property to display a trial off…
  • Loading branch information
ludrob committed Feb 7, 2024
2 parents b79816d + 74efc47 commit 321a6a0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
17 changes: 15 additions & 2 deletions components/payment-term.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export function PaymentTerm({
billingCountry = '',
is7DayPassExperiment = false,
isTermedSubscriptionTermType = false,
isTrialOfferAsNonTrialOverride = false,
labelOverride = '', // this is a temporary hack for the February 2024 campaign
}) {
/**
* Compute monthly price for given term name
Expand All @@ -25,7 +27,7 @@ export function PaymentTerm({
* @param {string} period (expressed in IS0 8601 duration format): e.g. PxY (yearly) or PxM (montly) where x is the amount of years/months
* @returns {string}
*/
const getMontlyPriceFromPeriod = (amount, currency, period) => {
const getMonthlyPriceFromPeriod = (amount, currency, period) => {
const periodObj = new Period(period);
const monthlyPrice = periodObj.calculatePrice('P1M', amount);
return new Monthly({ value: monthlyPrice, currency }).getAmount('monthly');
Expand Down Expand Up @@ -268,7 +270,7 @@ export function PaymentTerm({
{nameMap['custom'].monthlyPrice(
option.monthlyPrice && option.monthlyPrice !== '0'
? Number(option.monthlyPrice)
: getMontlyPriceFromPeriod(
: getMonthlyPriceFromPeriod(
option.amount,
option.currency,
option.value
Expand Down Expand Up @@ -298,6 +300,16 @@ export function PaymentTerm({
const showTrialCopyInTitle =
option.isTrial && !isPrintOrBundle && !isEpaper;

// https://financialtimes.atlassian.net/browse/ACQ-2592
// We need to have one specific trial offer to have terms displayed as non-trial.
// The offer is a trial offer and should use trial mechanics but should show as non-trial.
// There is nothing in the offer payload to identify when this should happen, we need to rely on the offer id.
// This is a TEMPORARY hack and will be removed once the campaign is over.
// A ticket as been raised already to deal with the clean up: https://financialtimes.atlassian.net/browse/ACQ-2593.
if (isTrialOfferAsNonTrialOverride && labelOverride) {
return labelOverride;
}

const defaultTitle = (() => {
if (is7DayPassExperiment) {
return '';
Expand Down Expand Up @@ -461,4 +473,5 @@ PaymentTerm.propTypes = {
largePrice: PropTypes.bool,
optionsInARow: PropTypes.bool,
billingCountry: PropTypes.string,
isTrialOfferAsNonTrialOverride: PropTypes.bool,
};
15 changes: 14 additions & 1 deletion components/payment-term.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('PaymentTerm', () => {
);
});
});
describe('getDisplayName', () => {
describe('getDisplayName trial', () => {
const trialOptions = {
...baseOptions,
isTrial: true,
Expand All @@ -273,6 +273,19 @@ describe('PaymentTerm', () => {
/^Trial: Premium Digital - Monthly .*$/
);
});
it('handles trial to non-trial payment term display name', () => {
const options = [trialOptions];
const wrapper = shallow(
<PaymentTerm
options={options}
labelOverride={'some term label'}
isTrialOfferAsNonTrialOverride={true}
/>
);
expect(wrapper.find('.ncf__payment-term__label').text()).toMatch(
/^some term label.*$/
);
});
it('renders using displayName if available', () => {
const options = [
{
Expand Down
35 changes: 35 additions & 0 deletions components/payment-term.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,38 @@ RenewOffers.args = {
],
optionsInARow: true,
};

// https://financialtimes.atlassian.net/browse/ACQ-2592
// We need to have one specific trial offer to have terms displayed as non-trial.
// The offer is a trial offer and should use trial mechanics but should show as non-trial.
// There is nothing in the offer payload to identify when this should happen, we need to rely on the offer id.
// This is a TEMPORARY hack and will be removed once the campaign is over.
// A ticket as been raised already to deal with the clean up: https://financialtimes.atlassian.net/browse/ACQ-2593.
export const PaymentTermLabelOverride = (args) => (
<div className="ncf">
<Fieldset>
<PaymentTerm {...args} />
</Fieldset>
</div>
);

PaymentTermLabelOverride.args = {
isTrialOfferAsNonTrialOverride: true,
labelOverride: 'some fancy payment term',
options: [
{
name: '6 monthly',
isTrial: false,
discount: '',
selected: false,
price: '$229.00',
trialPrice: '$0.00',
trialDuration: '',
monthlyPrice: '0',
amount: '229.00',
trialAmount: null,
value: 'P6M',
currency: 'USD',
},
],
};

0 comments on commit 321a6a0

Please sign in to comment.