1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Stripe } from "@trigger.dev/stripe";
3
import { Airtable } from "@trigger.dev/airtable";
5
const stripe = new Stripe({
7
apiKey: process.env.STRIPE_API_KEY!,
10
const airtable = new Airtable({
12
token: process.env.AIRTABLE_TOKEN!,
16
stripe_customer_id?: string;
21
payment_intent_id: string;
25
"stripe_customer_id (from Customers)": string;
29
id: "stripe-new-sale-update-airtable",
30
name: "On new Stripe sale update Airtable",
36
trigger: stripe.onPaymentIntentSucceeded(),
37
run: async (payload, io, ctx) => {
38
const customersTable = io.airtable
39
.base("<your base id>")
40
.table<Customers>("<your table name>");
42
const salesTable = io.airtable
43
.base("<your base id>")
44
.table<Sales>("<your table name>");
47
id: payment_intent_id,
48
customer: stripe_customer_id,
54
const records = await customersTable.getRecords(
55
"Filter records by stripe_customer_id",
57
filterByFormula: `{stripe_customer_id} = "${stripe_customer_id}"`,
58
fields: ["stripe_customer_id"],
63
if (records && records.length > 0) {
65
customerRecordId = records[0].id;
67
const newCustomerRecord = await customersTable.createRecords(
68
"create new customer record",
71
fields: { stripe_customer_id: stripe_customer_id as string },
75
customerRecordId = newCustomerRecord[0].id;
79
const newSaleRecord = await salesTable.createRecords(
80
"create new sale record",
87
Customers: [customerRecordId],