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).

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