Skip to content

Commit

Permalink
tmp subscription item
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelecerati committed Jun 29, 2023
1 parent ed869ef commit 3056fe5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/api/src/controllers/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ app.post("/webhook", async (req, res) => {
);
let overUsage = await calculateOverUsage(user.stripeProductId, usage);

const subscriptionItems = await req.stripe.subscriptionItems.list({
subscription: user.stripeCustomerSubscriptionId,
});

// Invoice items based on overusage
await Promise.all(
products[user.stripeProductId].usage.map(async (product) => {
if (product.name === "Transcoding") {
await req.stripe.subscriptionItems.createUsageRecord(
"si_I3oUKEe6JSoTkO",
subscriptionItems[0],
{
quantity: overUsage.TotalUsageMins,
timestamp: new Date().getTime() / 1000,
Expand All @@ -130,7 +134,7 @@ app.post("/webhook", async (req, res) => {
);
} else if (product.name === "Streaming") {
await req.stripe.subscriptionItems.createUsageRecord(
"si_I3oUKEe6JSoTkO",
subscriptionItems[0],
{
quantity: overUsage.DeliveryUsageMins,
timestamp: new Date().getTime() / 1000,
Expand All @@ -139,7 +143,7 @@ app.post("/webhook", async (req, res) => {
);
} else if (product.name === "Storage") {
await req.stripe.subscriptionItems.createUsageRecord(
"si_I3oUKEe6JSoTkO",
subscriptionItems[0],
{
quantity: overUsage.StorageUsageMins,
timestamp: new Date().getTime() / 1000,
Expand Down

0 comments on commit 3056fe5

Please sign in to comment.