#pterodavtyl

1 messages · Page 1 of 1 (latest)

marsh frostBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

late hearth
#

What do you mena by "not executed" exactly?

#

Do you mean the expected event is not emitted, or your endpoint doesnt do what you expect?

#

Do you have an example invoice ID for which you observe this that you can share?

jagged fox
#

Hi synth! Thanks for being here

#

yeah, so a few extra details: I'm listening for invoice.created to setup the current billing cycles on my database. I chose this event because if it's not paid, I don't want my database to update for a billing cycle that might not even happen.
So, when invoice.paid is received, I execute the following code:

        try {
          const invoice = data.object;

          // Retrieve the subscription ID from the invoice
          const subscriptionId = invoice.subscription;

          if (!subscriptionId) {
            console.warn('⚠️ No subscription associated with the invoice.');
            return;
          }

          // Fetch subscription details from Stripe
          const subscription = await stripe.subscriptions.retrieve(
            subscriptionId
          );

          // Get the period start and end from the subscription
          const periodStart = subscription.current_period_start;
          const periodEnd = subscription.current_period_end;

          // Update user's billing dates in MongoDB
          const paidUser = await User.findOneAndUpdate(
            { stripe_id: invoice.customer },
            {
              billing_start_date: new Date(periodStart * 1000).toISOString(),
              billing_end_date: new Date(periodEnd * 1000).toISOString(),
            },
            { new: true }
          );

          if (paidUser) {
            console.log(`🔔 Billing dates updated for user ${paidUser.email}`);
          } else {
            console.warn('⚠️  No user found with the given stripe_id.');
          }
        } catch (error) {
          console.error(
            `Error processing the invoice.paid event. Error: ${error.message}`
          );
        }
        break;```

I'm going to find one of the cases where this behavior didn't happen
#

Just one second, going through records

#

Ok I found one, what is the best way to share details about a customer in here?

#

Is there a preferred way?

late hearth
#

The invoice ID would be best, like in_1234

jagged fox
#

Ok

#

"in_1NwwnLI2zXV3qlvkb6fCgX82"

late hearth
#

ok, thanks. and what happened different than you expect with this invoice?

jagged fox
#

She didn't have the billing_start_date (nor the end one) on the database

#

All of the instances where this behavior happens, are people who have an invoice.payment_failed event as well on their logs

#

I wouldn't think it's related

#

However, I did have one case where she didn't have a payment_failed event, and she didn't update on database

late hearth
#

Are you referring to something in the stripe api/object data, or something in your own system?

jagged fox
#

Something in my system

#

So, my code looks for current billing dates

#

from the Stripe subscription

#

And sends them to my database

#

It works, except for those 6 cases where it hasn't

#

So, when those 6 cases happened, I would see those properties as blank

#

no info whatsoever

#

Like I said, I wouldn't think it's something related to having a payment_failed event. But I have only had 5 people with that event, and none of them got their info on my database after

late hearth
#

Hm well, I can't really say much about your business logic here, but if you can narrow the question down to something about the relevant stripe objects I can try to help

#

For example, if this is an issue with date string matching in your User.findOneAndUpdate I'm afraid I can't be of much help

jagged fox
#

Well my question was in the vein of "when an invoice.paid event happened, my database didn't update as they normally do", but maybe it was related to my database connection or something internal?

late hearth
#

Possible, yes

#

It looksm like this was a failed payment for the first invoice on the subscription

#

so maybe this has to do with when you create the user/subscription record in that case

jagged fox
#

Oh, so Stripe might not have the timestamps and I'm trying to retrieve them?

late hearth
#

I'm not sure, you'd need to do some tests to narrow down where the failure/gap is

#

At which point we can probably offer some clarification or context on how/why something is the way it is

#

I'd suggest doing test mode subscription creation & payment failure to try to reproduce this

jagged fox
#

Yes I'm going to pay attention to the subscription I'm fetching and analyze further

#

Thank you for clarifying

late hearth
#

NP!