Subscribe to user updates, automate payments, billing and more.

Using our official Stripe integration

  • Easily subscribe to Stripe webhooks to trigger your jobs.

  • Create any tasks possible with the Stripe API.

  • Use io.runTask() and the official SDK or fetch.

  • Example code using Stripe

    Below are some working code examples of how you can use Stripe with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

    import { TriggerClient } from "@trigger.dev/sdk";
    import { Stripe } from "@trigger.dev/stripe";
    import { Airtable } from "@trigger.dev/airtable";
    const stripe = new Stripe({
    id: "stripe",
    apiKey: process.env.STRIPE_API_KEY!,
    });
    const airtable = new Airtable({
    id: "airtable",
    token: process.env.AIRTABLE_TOKEN!,
    });
    type Customers = {
    stripe_customer_id?: string;
    Sales?: string[];
    };
    type Sales = {
    payment_intent_id: string;
    amount: number;
    currency: string;
    Customers?: string[];
    "stripe_customer_id (from Customers)": string;
    };
    client.defineJob({
    id: "stripe-new-sale-update-airtable",
    name: "On new Stripe sale update Airtable",
    version: "1.0.0",
    integrations: {
    stripe,
    airtable,
    },
    trigger: stripe.onPaymentIntentSucceeded(),
    run: async (payload, io, ctx) => {
    const customersTable = io.airtable
    .base("<your base id>")
    .table<Customers>("<your table name>");
    const salesTable = io.airtable
    .base("<your base id>")
    .table<Sales>("<your table name>");
    const {
    id: payment_intent_id,
    customer: stripe_customer_id,
    amount,
    currency,
    } = payload;
    // Use the filter formula to find a customer record with the given stripe_customer_id
    const records = await customersTable.getRecords(
    "Filter records by stripe_customer_id",
    {
    filterByFormula: `{stripe_customer_id} = "${stripe_customer_id}"`,
    fields: ["stripe_customer_id"],
    }
    );
    let customerRecordId;
    if (records && records.length > 0) {
    // There is an existing customer
    customerRecordId = records[0].id;
    } else {
    const newCustomerRecord = await customersTable.createRecords(
    "create new customer record",
    [
    {
    fields: { stripe_customer_id: stripe_customer_id as string },
    },
    ]
    );
    customerRecordId = newCustomerRecord[0].id;
    }
    // Add sale to the Sales table
    const newSaleRecord = await salesTable.createRecords(
    "create new sale record",
    [
    {
    fields: {
    payment_intent_id,
    amount,
    currency,
    Customers: [customerRecordId], // Link to the customer record using its ID
    },
    },
    ]
    );
    },
    });
    ,