Skip to content

Commit

Permalink
Update supabase-admin.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kschmelter13 authored Jun 4, 2023
1 parent f1c2246 commit 9a981ba
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions utils/supabase-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ const createOrRetrieveCustomer = async ({
email: string;
uuid: string;
}) => {

const existingCustomer = await stripe.customers.list({ email: email });
if (existingCustomer.data.length > 0) {
const stripeCustomerId = existingCustomer.data[0].id;
console.log(
`Customer already exists in Stripe with ID: ${stripeCustomerId}`
);

// Insert the customer ID into the Supabase customers table
const { error } = await supabaseAdmin
.from("customers")
.insert([{ id: uuid, stripe_customer_id: stripeCustomerId }]);

if (error) {
throw error;
}

console.log(`Customer ID inserted into the Supabase customers table.`);
return stripeCustomerId;
}

const { data, error } = await supabaseAdmin
.from('customers')
.select('stripe_customer_id')
Expand Down

0 comments on commit 9a981ba

Please sign in to comment.