#lucas-soares_webhooks

1 messages ยท Page 1 of 1 (latest)

safe flintBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1287772295485718681

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

vapid sand
#

this is my code in webhook:

#
case 'checkout.session.completed': // quando o pagamento no checkout รฉ feito
            const checkoutSession = event.data.object;
            
            let schedule = await stripe.subscriptionSchedules.create({
                from_subscription: checkoutSession.subscription,
            })
            console.log(`Schedule created: ${schedule.id}`);

            const phases = schedule.phases.map(phase => ({
                start_date: phase.start_date,
                end_date: phase.end_date,
                items: phase.items
            }))

            schedule = await stripe.subscriptionSchedules.update(
                schedule.id,
                {
                    end_behavior: "cancel",
                    phases: [
                        ...phases,
                        {
                            items: [{
                                price: 'price_1Q2BLYRx522Tv10myvWnstsX',
                                quantity: 1,
                            }],
                            iterations: 3
                        }
                    ]
                }
            )

            break;
trail acornBOT
glossy tendon
#

Hi there ๐Ÿ‘‹ do you have the ID of the request throwing that error?
https://support.stripe.com/questions/finding-the-id-for-an-api-request

Offhand it sounds like you're trying to attach a Subscription Schedule to a Subscription that is already being controlled by an existing Subscription Schedule. If so you'd either want to update the existing Subscription Schedule, or remove the existing schedule before attaching a new one.

vapid sand
#

Sorry, I have the request ID here, I didn't know where to find it.

#

req_FCwGSbuknUKJzI

#

I tried to update the Scheduled that already exists or delete it, but I couldn't check id

glossy tendon
#

Yeah, that request is failing for the reason indicated in the returned error message, the Subscription is already being controlled by another Subscription Schedule. You previously created a Subscription Schedule from that Subscription in this request:
https://dashboard.stripe.com/test/logs/req_wiBqowCMlsewpK

vapid sand
#

ok, I see, but I didn't find where it was being added before

#

I just created the link at checkout and then I try to attach it to the webhook

#

at some point it is calling subscription Schedules

glossy tendon
#

Yeah, I'm not sure what in your code is calling that endpoint, I just see that you are. Do you have logic in your code to make sure you aren't processing an Event that has already been processed? It looks like you're sending that Event to you endpoint multiple times. My suspicion is that the Subscription Schedule creation request ran the first time the Event was received, so it errors when you try to reprocess the same Event.

vapid sand
#

yeah, I had made a request but it gave an error at the end and it still created the Schedules

#

he had created it even though it gave me an error and I didn't notice

#

I made a new payment at checkout and now it works!

glossy tendon
#

๐Ÿฅณ glad to hear!

vapid sand
#

thank you very much for the help! ๐Ÿ™