Skip to content

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

@benjaminmbrown

Description

@benjaminmbrown

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 });
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions