first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import {Price} from '../price';
export type UpsellBillingCycle = 'monthly' | 'yearly';
export function findBestPrice(
token: UpsellBillingCycle,
prices: Price[]
): Price | undefined {
if (token === 'monthly') {
const match = findMonthlyPrice(prices);
if (match) return match;
}
if (token === 'yearly') {
const match = findYearlyPrice(prices);
if (match) return match;
}
return prices[0];
}
function findYearlyPrice(prices: Price[]) {
return prices.find(price => {
if (price.interval === 'month' && price.interval_count >= 12) {
return price;
}
if (price.interval === 'year' && price.interval_count >= 1) {
return price;
}
});
}
function findMonthlyPrice(prices: Price[]) {
return prices.find(price => {
if (price.interval === 'day' && price.interval_count >= 30) {
return price;
}
if (price.interval === 'month' && price.interval_count >= 1) {
return price;
}
});
}