#raghav-node-error

1 messages · Page 1 of 1 (latest)

wintry veldt
#

hey there, where are you seeing this? can you share a snippet of code?

stone meadow
#

I am running a cloud function where I update the user's plan according to the database

export async function updateStripeSubscription(
  user_data: UserDocument,
  to_plan: subscriptionNameTypes
): Promise<void> {
  try {
    let stripe = InitializeStripe(user_data.email);
    const current_sub_id = user_data.subscriptions.id;
    const subscription = await stripe.subscriptions.retrieve(current_sub_id);
    let sub_id: priceIDsTypes = subscriptionsIDs.filter(
      (v) => v.name === to_plan
    )[0].id;

    stripe.subscriptions.update(current_sub_id, {
      cancel_at_period_end: false,
      proration_behavior: "create_prorations",
      items: [
        {
          id: subscription.items.data[0].id,
          price: sub_id,
        },
      ],
    });
    updateUserDatabaseSubscription(user_data, current_sub_id, sub_id);
  } catch (error) {
    throw error;
  }
}
wintry veldt
#

Have you debugged to confirm const current_sub_id = user_data.subscriptions.id actually has a value?

#

the error seems to suggest this is undefined

stone meadow
#

Just a moment

#

that correct it was undefined Thanks for your help

wintry veldt
#

NP!