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
stripe_customer_id?: string;
20
payment_intent_id: string;
24
"stripe_customer_id (from Customers)": string;
28
id: "stripe-new-sale-update-airtable",
29
name: "On new Stripe sale update Airtable",
35
trigger: stripe.onPaymentIntentSucceeded(),
36
run: async (payload, io, ctx) => {
37
const customersTable = io.airtable
38
.base("<your base id>")
39
.table<Customers>("<your table name>");
41
const salesTable = io.airtable
42
.base("<your base id>")
43
.table<Sales>("<your table name>");
46
id: payment_intent_id,
47
customer: stripe_customer_id,
53
const records = await customersTable.getRecords(
54
"Filter records by stripe_customer_id",
56
filterByFormula: `{stripe_customer_id} = "${stripe_customer_id}"`,
57
fields: ["stripe_customer_id"],
62
if (records && records.length > 0) {
64
customerRecordId = records[0].id;
66
const newCustomerRecord = await customersTable.createRecords(
67
"create new customer record",
70
fields: { stripe_customer_id: stripe_customer_id as string },
74
customerRecordId = newCustomerRecord[0].id;
78
const newSaleRecord = await salesTable.createRecords(
79
"create new sale record",
86
Customers: [customerRecordId],