billing - consider status_transitions.finalized_at as the invoice date
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -301,7 +301,9 @@ export default class StripeBillingIntegration extends BillingIntegration {
const { id: invoiceID, customer, number, livemode: liveMode, amount_due: amount, amount_paid: amountPaid, status, currency: invoiceCurrency, invoice_pdf: downloadUrl, metadata, hosted_invoice_url: payInvoiceUrl } = stripeInvoice;
const customerID = customer as string;
const currency = invoiceCurrency?.toUpperCase();
- const createdOn = moment.unix(stripeInvoice.created).toDate(); // epoch to Date!
+ // The invoice date may change when finalizing a DRAFT invoice
+ const epoch = stripeInvoice.status_transitions?.finalized_at || stripeInvoice.created;
+ const createdOn = moment.unix(epoch).toDate(); // epoch to Date!
// Check metadata consistency - userID is mandatory!
const userID = metadata?.userID;
if (!userID) {

billing - consider status_transitions.finalized_at as the invoice date