Skip to content

Commit bd3d214

Browse files
add config to get discount rate plans
1 parent e1b4892 commit bd3d214

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

client/components/mma/cancel/cancellationSaves/digipack/DigiSubThankYouOffer.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import {
1919
LoadingState,
2020
useAsyncLoader,
2121
} from '@/client/utilities/hooks/useAsyncLoader';
22-
import { getDiscountMonthsForDigisub } from '@/client/utilities/pricingConfig/digisubDiscountPricing';
22+
import {
23+
getDiscountMonthsForDigisub,
24+
getDiscountRatePlanId,
25+
} from '@/client/utilities/pricingConfig/digisubDiscountPricing';
2326
import { formatAmount } from '@/client/utilities/utils';
2427
import type { PaidSubscriptionPlan } from '@/shared/productResponse';
2528
import { getMainPlan } from '@/shared/productResponse';
@@ -145,6 +148,7 @@ export const DigiSubThankYouOffer = () => {
145148
CancellationContext,
146149
) as CancellationContextInterface;
147150
const productDetail = cancellationContext.productDetail;
151+
const discountMonths = getDiscountMonthsForDigisub(productDetail);
148152

149153
const {
150154
data,
@@ -159,9 +163,8 @@ export const DigiSubThankYouOffer = () => {
159163
body: JSON.stringify({
160164
subscriptionNumber:
161165
productDetail.subscription.subscriptionId,
162-
// Todo: make this fetch rate plan from config
163166
discountProductRatePlanId:
164-
'2c92c0f962cec7990162d3882afc52dd',
167+
getDiscountRatePlanId(discountMonths),
165168
}),
166169
}),
167170
JsonResponseHandler,
@@ -196,7 +199,6 @@ export const DigiSubThankYouOffer = () => {
196199
productDetail.subscription,
197200
) as PaidSubscriptionPlan;
198201

199-
const discountMonths = getDiscountMonthsForDigisub(productDetail);
200202
const newPrice =
201203
(productDetail.subscription.nextPaymentPrice ?? mainPlan.price) / 100;
202204

@@ -216,7 +218,7 @@ export const DigiSubThankYouOffer = () => {
216218
subscriptionNumber:
217219
productDetail.subscription.subscriptionId,
218220
discountProductRatePlanId:
219-
'2c92c0f962cec7990162d3882afc52dd',
221+
getDiscountRatePlanId(discountMonths),
220222
}),
221223
},
222224
);

client/utilities/pricingConfig/digisubDiscountPricing.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isOneOf } from '@guardian/libs';
2+
import { conf } from '@/server/config';
23
import {
34
getMainPlan,
45
isPaidSubscriptionPlan,
@@ -29,3 +30,25 @@ export function getDiscountMonthsForDigisub(
2930
return 12;
3031
}
3132
}
33+
34+
export function getDiscountRatePlanId(months: number): string {
35+
return MonthsToDiscountRatePlanIdMapping[conf.STAGE][months];
36+
}
37+
38+
const MonthsToDiscountRatePlanIdMapping: Record<
39+
string,
40+
Record<number, string>
41+
> = {
42+
DEV: {
43+
3: '2c92c0f962cec7990162d3882afc52dd',
44+
12: '8ad08f068b5b9ca2018b5cadf0897ed3',
45+
},
46+
CODE: {
47+
3: '2c92c0f962cec7990162d3882afc52dd',
48+
12: '8ad08f068b5b9ca2018b5cadf0897ed3',
49+
},
50+
PROD: {
51+
3: '2c92a0ff64176cd40164232c8ec97661',
52+
12: '8a128adf8b64bcfd018b6b6fdc7674f5',
53+
},
54+
};

0 commit comments

Comments
 (0)