Skip to content

Commit

Permalink
fix: change how billing are calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
jog1t committed Sep 21, 2024
1 parent 70c123a commit e9a3cc8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface GameBillingContextValue {
used: number;
overage: number;
remaining: number;
total: number;
};
subscription: RivetEe.ee.billing.Subscription | undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
faShield,
faUpRightAndDownLeftFromCenter,
} from "@rivet-gg/icons";
import { PRICE_MAP } from "../../data/billing-calculate-usage";
import {
LobbyRegionIcon,
LobbyRegionName,
Expand Down Expand Up @@ -46,7 +47,7 @@ export function GameBillingPlans({ gameId }: GameBillingPlansProps) {
<GameBillingPlanCard
title="Indie"
lead="Fixed price suitable for indies & hobbyists"
price="$9"
price={`$${PRICE_MAP[RivetEe.ee.billing.Plan.Indie]}`}
onSubscribe={() =>
open({
plan: RivetEe.ee.billing.Plan.Indie,
Expand Down Expand Up @@ -118,7 +119,7 @@ export function GameBillingPlans({ gameId }: GameBillingPlansProps) {
plan: RivetEe.ee.billing.Plan.Trial,
})
}
price="$29"
price={`$${PRICE_MAP[RivetEe.ee.billing.Plan.Studio]}`}
type={plan === RivetEe.ee.billing.Plan.Studio ? "active" : undefined}
priceLead="+ Resource Usage"
features={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useGameBilling } from "./game-billing-context";

export function GameBillingSummary() {
const {
credits: { overage, remaining },
credits: { total, remaining },
} = useGameBilling();

return (
<Grid columns={{ initial: "1", md: "3" }} gap="4">
<ValueCard
title="Current bill total"
value={<AnimatedCurrency value={overage} />}
value={<AnimatedCurrency value={total} />}
/>
<ValueCard
title="Credits remaining"
Expand Down
10 changes: 9 additions & 1 deletion apps/hub/src/domains/game/data/billing-calculate-usage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Rivet as RivetEe } from "@rivet-gg/api-ee";
import { millisecondsToMonths } from "@rivet-gg/components";

export const PRICE_MAP = {
[RivetEe.ee.billing.Plan.Trial]: 0,
[RivetEe.ee.billing.Plan.Indie]: 9.0,
[RivetEe.ee.billing.Plan.Studio]: 29.0,
};
const CREIDTS_MAP = {
[RivetEe.ee.billing.Plan.Trial]: 5.0,
[RivetEe.ee.billing.Plan.Indie]: 48.21,
Expand All @@ -25,10 +30,13 @@ export function calculateUsedCredits({
const monthsOfUptime = millisecondsToMonths(totalUptime);
const usedCredits = monthsOfUptime * FACTOR;

const overage = Math.max(0, usedCredits - CREIDTS_MAP[plan]);

return {
max: CREIDTS_MAP[plan],
used: usedCredits,
remaining: CREIDTS_MAP[plan] - usedCredits,
overage: Math.max(0, usedCredits - CREIDTS_MAP[plan]),
overage,
total: PRICE_MAP[plan] + overage,
};
}

0 comments on commit e9a3cc8

Please sign in to comment.