#Handling 500 Error: Customer Absence in Stripe When Using $stripeCustomer->createSetupIntent()

50 messages · Page 1 of 1 (latest)

short harbor
#

Cashier's findBillable($stripeId) method throws a 500 error.

if the customer does not exist on Stripe, I want to set the corresponding user stripe_id in the database to null.

How can I check strip_id against Stripe before doing below?

$stripeCustomer = Cashier::findBillable($stripeId);
$intent->createSetupIntent();
viral monolith
short harbor
short harbor
viral monolith
short harbor
#

I know, but it could be nice, to check Stripe and if customer is deleted there, I will create a new stripe_id for the customer

#

$stripeCustomer = $user->createAsStripeCustomer();

short harbor
viral monolith
#

So the problem you’ll have now is, you’ll be trying to create setup intents for a customer that doesn’t exist, and Stripe will be like, “I have no idea who that customer is”. Because you deleted them 🙃

short harbor
#

no

viral monolith
#

Why did you delete the customer in the first place? 🤷‍♂️

short harbor
viral monolith
#

Yes. An error caused by you deleting the customer in Stripe. So why did you delete them?

short harbor
#

But just so be agree, it is working fine with payment methods

viral monolith
#

Eh?

#

What do you mean, “error handling”?

short harbor
#

Like, what I already told you, check customer against Stripe

viral monolith
#

What error led you to go, “I’m going to delete the customer from Stripe now, but leave a reference to that deleted customer’s ID in my database.”

#

That’s just going to cause more errors.

#

Not “handle” any.

short harbor
#

no

#

How is that?

#

It is just a check from my db against Stripe

viral monolith
#

short harbor
#

If stripe_id do not match any customer id in Stripe, then I will create a new Stripe customer

viral monolith
#

You still haven’t answered why you deleted the customer in Stripe in the first place.

short harbor
#

I am testing

#

So you are saying, that I should not touch Stripe and manage everything from my backend?

viral monolith
#

Well I’m saying, if you have customer IDs in your database, you shouldn’t then delete those customers in Stripe. Otherwise then things are going to break.

short harbor
viral monolith
#

I’d just be cautious about deleting customers at all. They’ve obviously been created for some reason (i.e. a payment has been made or something).

#

Customers don’t create themselves in Stripe.

short harbor
short harbor
viral monolith
#

I’d still leave the customer in Stripe, for reporting.

viral monolith
#

But definitely don’t delete customers in Stripe and leave their user account in your database.

short harbor
short harbor
viral monolith
#

I don’t think Cashier will do anything (except break) if you delete a row from the users table when that user has subscriptions, because Cashier doesn’t expect you to go deleting users with active subscriptions.

short harbor
viral monolith
short harbor
#

got it

short harbor
short harbor
viral monolith
#

You’re literally coming up with solutions for problems you’ve created yourself.

#

Don’t delete customers in Stripe, and then you don’t need to check if they’re deleted or not 🙃