#brookflok_webhooks

1 messages ยท Page 1 of 1 (latest)

deft folioBOT
#

๐Ÿ‘‹ 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.

regal skyBOT
agile harbor
#

Can you share an event ID where this happened?

vague vine
#

yes I think I can

#

Just a secound to find it

#

"evt_1PQUr4JQTk4jQVYGQqqEv2Ik",

#

This event is when the user paid

agile harbor
#

Can you share the failed one I mean

vague vine
#

"id": "evt_1PQUqbJQTk4jQVYGMFikVDOq",

#

the faild one

#

I wanted to share both

agile harbor
#

Thanks

vague vine
#

because they are 1 minute apart

agile harbor
#

Oh the payment failed one came first

#

2024-06-11 13:34:49 UTC

vague vine
#

no

#

As I can see

agile harbor
#

The paid one came 2024-06-11 13:35:17 UTC

#

Whether or not your webhook endpoint received them in that order is different

vague vine
#

this is how it says in stripe for me xD

agile harbor
#

Yeah we don't guarantee order of events received

vague vine
#

oh okay, but why did the payment_faild happen ?

agile harbor
#

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

vague vine
#

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

agile harbor
#

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)

vague vine
#

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

agile harbor
#

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

vague vine
#

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

agile harbor
#

What do you mean?

vague vine
#

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

agile harbor
#

Ah

#

Glad you got it

vague vine
#

Without you I would still think it is because of some false webhook xD

agile harbor
#

Happy to help!

vague vine
#

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

agile harbor
#

Unfortunately not haha, but I'll pass this along!

vague vine
#

Than that is it, thx a lot ๐Ÿ˜„