#talmor_code

1 messages ¡ Page 1 of 1 (latest)

midnight iglooBOT
eternal vesselBOT
#

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.

midnight iglooBOT
#

👋 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/1259813786404126845

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

bright flower
#

I need to find out why I am unable to get the data to pass and make the subscription update.
What issue you are facing exactly ?

undone saddle
#

So I created a manual meterEvent.create function that should send new data to the subscription each time it is called, to save me the time of waiting. It does not seem to update as expected. Would you like to see the code?

bright flower
#

What makes you say that it doesn update ?

#

And what is the expected behavior you are missing ?

undone saddle
#

Alright, I just checked the API logs in Stripe (did not know that existed, thank you) and there is not log for it, so makes me think the data is not even hitting the endpoint.

exports.reportUsageManually = functions.https.onRequest((req, res) => {
return cors(req, res, async () => {
try {
const organisationsSnapshot = await admin.firestore().collection('organisations').get();

  for (const orgDoc of organisationsSnapshot.docs) {
    const organisationId = orgDoc.id;

    const activeUsersCount = await getActiveUsersCount(organisationId);
    console.log(`Active users count for organisation ID ${organisationId}: ${activeUsersCount}`);

    const userDocs = await admin.firestore().collection('users').where('organisationId', '==', organisationId).get();

    for (const userDoc of userDocs.docs) {
      const userData = userDoc.data();
      if (userData.stripeCustomerId) {
        const customerId = userData.stripeCustomerId;

        // Create a meter event for the active users count
        const meterEvent = await stripe.billing.meterEvents.create({
          event_name: 'active_user_update',
          payload: {
            stripe_customer_id: customerId,
            value: activeUsersCount,
          },
        });

        console.log(`Created meter event: ${meterEvent.id}`);
      }
    }
  }
  console.log('Manual usage reporting function completed.');
  res.status(200).send('Usage reported successfully');
} catch (error) {
  console.error('Error in manual usage reporting:', error);
  res.status(500).send(`Error: ${error.message}`);
}

});
});

bright flower
#

there is not log for it, so makes me think the data is not even hitting the endpoint.
That means the code for creating the record isn't reached. You need to debug your integration and follow its execution step by step.

#

or you can add some log lines to inspect why the block code of making the APi calls isn't called.

undone saddle
#

gonna try and debug now, thank you for point that out!