#Handling 500 Error: Customer Absence in Stripe When Using $stripeCustomer->createSetupIntent()
50 messages · Page 1 of 1 (latest)
Well what’s the exception being thrown? Because findBillable returns either the user or null if there’s no user with the given customer ID.
I have stripe_id in my database, but i deleted the user in Stripe
So when I do:
$intent = $stripeCustomer->createSetupIntent();
dd("intent er:", $intent);
I get 500
Well yeah, if you delete customers from Stripe then you’re going to have a bad time trying to do stuff with that customer.
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();
It is working with payment methods, if a payment method is deleted at Stripe, payment methods are getting updated
but it could be nice, to check Stripe and if customer is deleted there
This is what webhooks are for.
Or just don’t delete customers that are actually customers.
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 🙃
no
Why did you delete the customer in the first place? 🤷♂️
I am trying to take care of error handling
Yes. An error caused by you deleting the customer in Stripe. So why did you delete them?
But just so be agree, it is working fine with payment methods
I told you, error handling
Like, what I already told you, check customer against Stripe
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.
…
If stripe_id do not match any customer id in Stripe, then I will create a new Stripe customer
You still haven’t answered why you deleted the customer in Stripe in the first place.
I am testing
So you are saying, that I should not touch Stripe and manage everything from my backend?
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.
Ahh, So if or necessary or needed I should delete the stripe customer from my backend?
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.
Make sense. But what if a customer deletes thier user account from my site, will cashier atumatically delete thier stripe account?
Not sure if my question make sense
I’d still leave the customer in Stripe, for reporting.
Ahh
But definitely don’t delete customers in Stripe and leave their user account in your database.
Do you know, what cashier will do to a active subscription if user deletes thier account and forget to delete thier subscription first?
It's my first integration, and I just want to find out how everything is fitted together
You shouldn’t be deleting user accounts that have an active subscription in the first place.
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.
But what if user deletes their own account - and not canceling or deleting thier subscription first?
You shouldn’t be letting users delete their account if they have an active subscription.
got it
Below is what I was originally looking for:
$stripeCustomer = $user->asStripeCustomer();
dd("True or false", $stripeCustomer->isDeleted());
And then I will just do:
if ($stripeCustomer->isDeleted()) {
$user
->forceFill([
"stripe_id" => null,
])
->save();
$user->createAsStripeCustomer();
}