mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Doc: Handle archived prices
This commit is contained in:
parent
33c64f98ef
commit
b1461d699f
@ -65,6 +65,7 @@ export interface StripePublicConfigPrice {
|
|||||||
export interface StripePublicConfig {
|
export interface StripePublicConfig {
|
||||||
publishableKey: string;
|
publishableKey: string;
|
||||||
prices: StripePublicConfigPrice[];
|
prices: StripePublicConfigPrice[];
|
||||||
|
archivedPrices: StripePublicConfigPrice[];
|
||||||
webhookBaseUrl: string;
|
webhookBaseUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,20 +87,24 @@ export function loadStripeConfig(env: string, filePath: string): StripePublicCon
|
|||||||
const config: StripePublicConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))[env];
|
const config: StripePublicConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))[env];
|
||||||
if (!config) throw new Error(`Invalid env: ${env}`);
|
if (!config) throw new Error(`Invalid env: ${env}`);
|
||||||
|
|
||||||
config.prices = config.prices.map(p => {
|
const decoratePrices = (p: StripePublicConfigPrice) => {
|
||||||
return {
|
return {
|
||||||
...p,
|
...p,
|
||||||
formattedAmount: formatPrice(p.amount, p.currency),
|
formattedAmount: formatPrice(p.amount, p.currency),
|
||||||
formattedMonthlyAmount: p.period === PricePeriod.Monthly ? formatPrice(p.amount, p.currency) : formatPrice(Number(p.amount) / 12, p.currency),
|
formattedMonthlyAmount: p.period === PricePeriod.Monthly ? formatPrice(p.amount, p.currency) : formatPrice(Number(p.amount) / 12, p.currency),
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
|
config.prices = config.prices.map(decoratePrices);
|
||||||
|
config.archivedPrices = config.archivedPrices.map(decoratePrices);
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findPrice(prices: StripePublicConfigPrice[], query: FindPriceQuery): StripePublicConfigPrice {
|
export function findPrice(config: StripePublicConfig, query: FindPriceQuery): StripePublicConfigPrice {
|
||||||
let output: StripePublicConfigPrice = null;
|
let output: StripePublicConfigPrice = null;
|
||||||
|
|
||||||
|
for (const prices of [config.prices, config.archivedPrices]) {
|
||||||
if (query.accountType && query.period) {
|
if (query.accountType && query.period) {
|
||||||
output = prices.filter(p => p.accountType === query.accountType).find(p => p.period === query.period);
|
output = prices.filter(p => p.accountType === query.accountType).find(p => p.period === query.period);
|
||||||
} else if (query.priceId) {
|
} else if (query.priceId) {
|
||||||
@ -108,6 +113,9 @@ export function findPrice(prices: StripePublicConfigPrice[], query: FindPriceQue
|
|||||||
throw new Error(`Invalid query: ${JSON.stringify(query)}`);
|
throw new Error(`Invalid query: ${JSON.stringify(query)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (output) break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!output) throw new Error(`Not found: ${JSON.stringify(query)}`);
|
if (!output) throw new Error(`Not found: ${JSON.stringify(query)}`);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -332,11 +340,11 @@ export function getPlans(stripeConfig: StripePublicConfig): Record<PlanName, Pla
|
|||||||
basic: {
|
basic: {
|
||||||
name: 'basic',
|
name: 'basic',
|
||||||
title: _('Basic'),
|
title: _('Basic'),
|
||||||
priceMonthly: findPrice(stripeConfig.prices, {
|
priceMonthly: findPrice(stripeConfig, {
|
||||||
accountType: 1,
|
accountType: 1,
|
||||||
period: PricePeriod.Monthly,
|
period: PricePeriod.Monthly,
|
||||||
}),
|
}),
|
||||||
priceYearly: findPrice(stripeConfig.prices, {
|
priceYearly: findPrice(stripeConfig, {
|
||||||
accountType: 1,
|
accountType: 1,
|
||||||
period: PricePeriod.Yearly,
|
period: PricePeriod.Yearly,
|
||||||
}),
|
}),
|
||||||
@ -354,11 +362,11 @@ export function getPlans(stripeConfig: StripePublicConfig): Record<PlanName, Pla
|
|||||||
pro: {
|
pro: {
|
||||||
name: 'pro',
|
name: 'pro',
|
||||||
title: _('Pro'),
|
title: _('Pro'),
|
||||||
priceMonthly: findPrice(stripeConfig.prices, {
|
priceMonthly: findPrice(stripeConfig, {
|
||||||
accountType: 2,
|
accountType: 2,
|
||||||
period: PricePeriod.Monthly,
|
period: PricePeriod.Monthly,
|
||||||
}),
|
}),
|
||||||
priceYearly: findPrice(stripeConfig.prices, {
|
priceYearly: findPrice(stripeConfig, {
|
||||||
accountType: 2,
|
accountType: 2,
|
||||||
period: PricePeriod.Yearly,
|
period: PricePeriod.Yearly,
|
||||||
}),
|
}),
|
||||||
@ -376,11 +384,11 @@ export function getPlans(stripeConfig: StripePublicConfig): Record<PlanName, Pla
|
|||||||
teams: {
|
teams: {
|
||||||
name: 'teams',
|
name: 'teams',
|
||||||
title: _('Teams'),
|
title: _('Teams'),
|
||||||
priceMonthly: findPrice(stripeConfig.prices, {
|
priceMonthly: findPrice(stripeConfig, {
|
||||||
accountType: 3,
|
accountType: 3,
|
||||||
period: PricePeriod.Monthly,
|
period: PricePeriod.Monthly,
|
||||||
}),
|
}),
|
||||||
priceYearly: findPrice(stripeConfig.prices, {
|
priceYearly: findPrice(stripeConfig, {
|
||||||
accountType: 3,
|
accountType: 3,
|
||||||
period: PricePeriod.Yearly,
|
period: PricePeriod.Yearly,
|
||||||
}),
|
}),
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
"amount": "80.28",
|
"amount": "80.28",
|
||||||
"currency": "EUR"
|
"currency": "EUR"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"archivedPrices": []
|
||||||
},
|
},
|
||||||
"prod": {
|
"prod": {
|
||||||
"publishableKey": "pk_live_51IvkOPLx4fybOTqJow8RFsWs0eDznPeBlXMw6s8SIDQeCM8bAFNYlBdDsyonAwRcJgBCoSlvFzAbhJgLFxzzTu4r0006aw846C",
|
"publishableKey": "pk_live_51IvkOPLx4fybOTqJow8RFsWs0eDznPeBlXMw6s8SIDQeCM8bAFNYlBdDsyonAwRcJgBCoSlvFzAbhJgLFxzzTu4r0006aw846C",
|
||||||
@ -93,6 +94,22 @@
|
|||||||
"amount": "80.28",
|
"amount": "80.28",
|
||||||
"currency": "EUR"
|
"currency": "EUR"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"archivedPrices": [
|
||||||
|
{
|
||||||
|
"accountType": 1,
|
||||||
|
"id": "price_1JAzWBLx4fybOTqJw64zxJRJ",
|
||||||
|
"period": "monthly",
|
||||||
|
"amount": "1.99",
|
||||||
|
"currency": "EUR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"accountType": 1,
|
||||||
|
"id": "price_1JJIPZLx4fybOTqJHvxiQ7bV",
|
||||||
|
"period": "yearly",
|
||||||
|
"amount": "17.88",
|
||||||
|
"currency": "EUR"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user