vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
6.08k stars 1.23k forks source link

Update supabase-admin.ts createorretrievecustomer #200

Closed kschmelter13 closed 6 months ago

kschmelter13 commented 1 year ago

Not sure if this is helpful, but i used it in my personal project to validate existing customers so it wont create duplicates, after an account is deleted

vercel[bot] commented 1 year ago

@kschmelter13 is attempting to deploy a commit to the Vercel Solutions Team on Vercel.

A member of the Team first needs to authorize it.

chriscarrollsmith commented 9 months ago

Interesting, thanks. So just to be clear, you encountered a scenario where the customer had been deleted from Supabase but not from Stripe, and this was resulting in a duplicate customer record being created in Stripe. To prevent this, you added a check for a matching record in Stripe before creating a new Stripe customer. Correct?

chriscarrollsmith commented 9 months ago

It looks like your code fails if the customer already exists in both supabase and stripe, because it finds a stripe record and then tries to upsert a duplicate record to supabase without checking if a supabase record exists first, which causes a primary key conflict.

I opened a new PR here: https://github.com/vercel/nextjs-subscription-payments/pull/274

leerob commented 6 months ago

https://github.com/vercel/nextjs-subscription-payments/pull/278