1
Create Usage Record
One script reply has been approved by the moderators Verified

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

Created by rossmccrann 850 days ago Viewed 9416 times
0
Submitted by rossmccrann Deno
Verified 850 days ago
1
import stripe from "npm:stripe@^11";
2

3
type Stripe = {
4
  token: string;
5
};
6
export async function main(
7
  sk: Stripe,
8
  subscriptionId: string,
9
  quantity: number
10
) {
11
  const client = new stripe.Stripe(sk.token, {
12
    apiVersion: "2022-11-15",
13
    httpClient: stripe.createFetchHttpClient(),
14
  });
15

16
  return await client.subscriptionItems.createUsageRecord(subscriptionId, {
17
    quantity,
18
  });
19
}
20