Tweak subscriptions some more
This commit is contained in:
@@ -208,6 +208,20 @@ export const subscription_periods: SubscriptionPeriod[] = [
|
||||
// same value the server divides the monthly fee by
|
||||
export const days_per_month = 365.25 / 12
|
||||
|
||||
// The price of the subscription period the user is in. This is also how far
|
||||
// the balance can go below zero before usage above the plan is refused
|
||||
export const period_price = (u: User) => {
|
||||
const period = subscription_periods.find(p => p.months === u.subscription_months)
|
||||
return period === undefined ? 0 :
|
||||
u.subscription.monthly_fee * period.months * period.discount
|
||||
}
|
||||
|
||||
// Whether usage above a limit of the plan is billed instead of refused. price
|
||||
// is what the plan charges for that usage. The server does the same check in
|
||||
// billsExtra
|
||||
export const bills_extra = (u: User, price: number) =>
|
||||
u.usage_based_billing && price > 0 && u.balance_micro_eur >= -period_price(u)
|
||||
|
||||
export const get_misc_subscriptions = async () => {
|
||||
return await check_response(
|
||||
await fetch(get_endpoint() + "/misc/subscriptions")
|
||||
|
||||
Reference in New Issue
Block a user