Back to jobs

Stripe to Supabase account update

Trigger: Webhook

Every time a Stripe account is updated, a corresponding Supabase table is updated.

Integrations:

/src/supabaseStripeUpdateDatabase

Payments

Databases

1
import { SupabaseManagement, Supabase } from "@trigger.dev/supabase";
2
import { Stripe } from "@trigger.dev/stripe";
3
import { TriggerClient } from "@trigger.dev/sdk";
4
5
const client = new TriggerClient({ id: "jobs-showcase" });
6
7
export const stripe = new Stripe({
8
id: "stripe",
9
apiKey: process.env.STRIPE_API_KEY!,
10
});
11
12
const supabase = new Supabase({
13
id: "supabase",
14
supabaseUrl: process.env.SUPABASE_PUBLIC_URL!,
15
supabaseKey: process.env.SUPABASE_SERVICE_ROLE_KEY!,
16
});
17
18
// Use OAuth to authenticate with Supabase Management API
19
const supabaseManagement = new SupabaseManagement({
20
id: "supabase-management",
21
});
22
23
// Update a Supabase table when a Stripe account is updated
24
client.defineJob({
25
id: "supabase-stripe-update-database",
26
name: "Supabase: update database when Stripe account is updated",
27
version: "1.0.0",
28
integrations: {
29
stripe,
30
supabase,
31
},
32
trigger: stripe.onAccountUpdated({ connect: true }),
33
run: async (payload, io, ctx) => {
34
const stripeAccountId = payload.id;
35
const { payouts_enabled, charges_enabled, details_submitted } = payload;
36
37
const updatedAt = new Date().toISOString();
38
39
await io.supabase.runTask("update-stripe-account", async (database) => {
40
const { data, error } = await database
41
.from("accounts")
42
.update({
43
payouts_enabled,
44
charges_enabled,
45
details_submitted,
46
updated_at: updatedAt,
47
})
48
.eq("stripe_account_id", stripeAccountId);
49
50
if (error) throw error;
51
52
return data;
53
});
54
},
55
});
56
57
// These lines can be removed if you don't want to use express
58
import { createExpressServer } from "@trigger.dev/express";
59
createExpressServer(client);