Skip to content

Commit

Permalink
billing: calculate overusage into upcoming invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelecerati committed Jun 29, 2023
1 parent 5705aa6 commit 489a0db
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/www/components/UsageSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const UsageSummary = () => {
const [overUsageBill, setOverUsageBill] = useState<OverUsageBill | null>(
null
);
const [upcomingInvoiceTotal, setUpcomingInvoiceTotal] = useState(0);
const product = getUserProduct(user);
const prices = product.usage;
const transcodingPrice = prices[0].price;
Expand Down Expand Up @@ -142,6 +143,16 @@ const UsageSummary = () => {
setOverUsage(overusage);
const overusageBill = await calculateOverUsageBill(overusage);
setOverUsageBill(overusageBill);
let planPrice =
products[user.newStripeProductId]?.monthlyPrice.toLocaleString() ||
products[user.stripeProductId]?.monthlyPrice.toLocaleString() ||
0;
setUpcomingInvoiceTotal(
overUsageBill.transcodingBill.total +
overUsageBill.deliveryBill.total +
overUsageBill.storageBill.total +
planPrice
);
}
};

Expand Down Expand Up @@ -301,14 +312,7 @@ const UsageSummary = () => {
<StyledUpcomingIcon />
Upcoming invoice:{" "}
<Box css={{ ml: "$1", fontWeight: 600 }}>
{usage &&
`$${
products[
user.newStripeProductId
]?.monthlyPrice.toLocaleString() ||
products[user.stripeProductId]?.monthlyPrice.toLocaleString() ||
0
}`}
{usage && `$${upcomingInvoiceTotal}`}
</Box>
</Text>
<Text>
Expand Down

0 comments on commit 489a0db

Please sign in to comment.