Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change how billing are calculated #336

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
}