Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timestamps must be after the subscription's last invoice period (or current period start time #2

Open
benjaminmbrown opened this issue Jun 6, 2019 · 0 comments

Comments

@benjaminmbrown
Copy link

benjaminmbrown commented Jun 6, 2019

Getting this error in my firebase function log for updateUsage.

The flow is:

  • User creates a new metered billing subscription
  • User adds a record/document
  • Error shows

Is this because the subscription is created so recently?

Error: Cannot create the usage record with this timestamp because timestamps must be after the subscription's last invoice period (or current period start time).

Screen Shot 2019-06-06 at 4 15 13 PM

export const updateUsage = functions.firestore
  .document('charts/{chartId}')
  .onCreate(async snap => {
    const userRef = db.doc(`users/${snap.data().uid}`);

    const userDoc = await userRef.get();
    const user = userDoc.data();
    const createdTime: any = snap.createTime;
    await stripe.usageRecords.create(
      user.itemId,
      {
        quantity: 1,
        timestamp: (Date.parse(createdTime) / 1000) | 0,
        action: 'increment'
      },
      {
        idempotency_key: snap.id
      }
    );

    return userRef.update({ currentUsage: user.currentUsage + 1 });
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant