Create Usage Record  (stripe)
One script reply has been approved by the moderators

1 points by rossmccrann 39 days ago | 20 uses

With metered billing, you charge your customers based on their consumption of your service during the billing cycle, instead of explicitly setting quantities. Use this action to create a usage record for metered billing. See the docs for more information

One script reply has been approved by the moderators
This version of script #127 was approved by the moderators as the one that fits the best the script ask: 'Create Usage Record'. It is safe to use in your flows in production.
0 points
by rossmccrann 39 days ago
edit by rossmccrann 39 days ago
import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
import Stripe from "https://esm.sh/stripe?target=deno";

export async function main(
  stripe_con: wmill.Resource<"stripe">,
  subscription_item_id: string,
  quantity: number,
  timestamp: number
) {
  const token = stripe_con["token"];
  const stripe = Stripe(
    `${token}`,
    {
      httpClient: Stripe.createFetchHttpClient(),
    },
  );

  const usageRecord = await stripe.subscriptionItems.createUsageRecord(
    `${subscription_item_id}`,
    { quantity: quantity, timestamp: timestamp },
  );

  return await usageRecord.json();
}
edit/run in windmill raw embed