1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Stripe } from "@trigger.dev/stripe";
3
import { Airtable } from "@trigger.dev/airtable";
4
const stripe = new Stripe({
6
apiKey: process.env.STRIPE_API_KEY!,
9
const airtable = new Airtable({
11
token: process.env.AIRTABLE_TOKEN!,
15
type SubscribedUsers = {
24
id: "stripe-new-subscription-update-airtable",
25
name: "On new Stripe subscription update Airtable",
31
trigger: stripe.onCustomerSubscription(),
32
run: async (payload, io, ctx) => {
36
const table = io.airtable
37
.base("<your base id>")
38
.table<SubscribedUsers>("<your table name>");
41
const newRecords = await table.createRecords("create records", [
46
interval: payload.items.data[0].price.recurring?.interval,
47
currency: payload.items.data[0].price.currency,
49
unitAmount: payload.items.data[0].price.unit_amount ?? undefined,
54
await io.logger.info("A new subscription was created.");