From 89bef91ad96cdb2af6f84f080fc9d0b3ce9f8f70 Mon Sep 17 00:00:00 2001 From: Jonathan Steele <83410553+jsteele-stripe@users.noreply.github.com> Date: Thu, 16 Mar 2023 15:52:54 +0000 Subject: [PATCH] fix: Address issue where `insertInvoiceRecord` function fails (#511) In case where the Invoice has no associated Payment Intent, the Firestore collection write would fail. Fixes #505 --- firestore-stripe-payments/functions/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firestore-stripe-payments/functions/src/index.ts b/firestore-stripe-payments/functions/src/index.ts index 15816d4c..b09b8578 100644 --- a/firestore-stripe-payments/functions/src/index.ts +++ b/firestore-stripe-payments/functions/src/index.ts @@ -620,10 +620,13 @@ const insertInvoiceRecord = async (invoice: Stripe.Invoice) => { ); } + // An Invoice object does not always have an associated Payment Intent + const recordId: string = (invoice.payment_intent as string) ?? invoice.id; + // Update subscription payment with price data await customersSnap.docs[0].ref .collection('payments') - .doc(invoice.payment_intent as string) + .doc(recordId) .set({ prices }, { merge: true }); logs.firestoreDocCreated('invoices', invoice.id); };