#brookflok_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1250090256884039843
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Can you share an event ID where this happened?
yes I think I can
Just a secound to find it
"evt_1PQUr4JQTk4jQVYGQqqEv2Ik",
This event is when the user paid
Can you share the failed one I mean
Thanks
because they are 1 minute apart
The paid one came 2024-06-11 13:35:17 UTC
Whether or not your webhook endpoint received them in that order is different
Yeah we don't guarantee order of events received
oh okay, but why did the payment_faild happen ?
It is because the payment needed 3ds auth
So we send that event because the customer needs to auth the transaction first
Then when customer completes 3ds auth, we send invoice.paid
oh, how can I differentiate the payment_faild from the 3ds and if the user fails the payment
because when i get the payment_faild for the subscription I put the users to inactive
in the app
And now it does it to the customers, because the system thinks they didn't pay
Yeah you'll need to retrieve the payment_intent associated with the invoice when you receive invoice.payment_failed
If the payment intent has a status of requires_action it's just due to 3ds
(or if you see status is succeeded that means customer already auth'd the transaction)
hmmm, i could do that. I didn't know that the events are not in order
I was thinking that that I don't have to deal with that
Yeah network issues can cause you to receive them out of order too
Also one event might succeed and the other might fail and we need to retry delivering
Any number of issues could happen
oh okay I understand
Btw. are you able to check my entire webhook and see did this happen subscription_schedule.canceled
Because the only time I have seting the status to inactive is when this happens
I just checked my code
What do you mean?
I will send you the code now then explain it
case 'invoice.payment_failed':
$invoice = $event->data->object; // contains a \Stripe\Invoice
Log::info('Invoice payment failed', ['invoice' => $invoice]);
case 'subscription_schedule.canceled':
$subscriptionSchedule = $event->data->object; // contains a \Stripe\SubscriptionSchedule
Log::info('Subscription schedule canceled', ['subscriptionSchedule' => $subscriptionSchedule]);
// Get the payment details from the stripe customer id
$paymentDetail = PaymentDetail::where('stripe_user_id', $subscriptionSchedule->customer)->first();
if (!$paymentDetail) {
Log::error('Payment details not found', ['stripe_user_id' => $subscriptionSchedule->customer]);
return response()->json(['message' => 'Payment details not found'], 404);
}
$user_id = $paymentDetail->user_id;
$user = User::find($user_id);
if (!$user) {
Log::error('User not found', ['user_id' => $user_id]);
return response()->json(['message' => 'User not found'], 404);
}
$subscription = Subscription::where('user_id', $user_id)->first();
if (!$subscription) {
Log::error('Subscription not found', ['user_id' => $user_id]);
return response()->json(['message' => 'User does not have an active subscription.'], 404);
}
$subscription->status = 'inactive';
$subscription->save();
Log::info('Subscription status updated to inactive', ['user_id' => $user_id, 'subscription_id' => $subscription->id]);
break;
So these are just two cases
the invoice.payment_failed and subscription_schedule.canceled
and the only time I switch the user to inactive is when subscription_schedule.canceled happens
and when the payment failed I just log it
And for some reason, sometimes when I check my DB i can see that the users are set to inactive
and I'm trying to find the reason
so I'm asking can you check or filter somehow my webhooks on the account and see did this webhook hapened
if it happened I will know the reason, but if it didn't happen I will hav eto try to find the reason why this inactive part is happening to me
I'm so sorry I just found the problem
There was never a problem with the webhooks
I forgot to break the case for the payment faild, and always when it faild it continue to this subscription_schedule.canceled
because there was no break
so sorry for contacting and wasted your time
you were awesome help
and explaind me a lot
Without you I would still think it is because of some false webhook xD
Happy to help!
Is there some place I can leave a postivie review for you?
ahahhahahaha
I know it is not a lot, but if there is some I would love to do it
Don't do it usually
Unfortunately not haha, but I'll pass this along!
Than that is it, thx a lot ๐