Skip to content

Commit

Permalink
fix: Address issue where insertInvoiceRecord function fails (#511)
Browse files Browse the repository at this point in the history
In case where the Invoice has no associated Payment Intent, the Firestore collection write would fail. Fixes #505
  • Loading branch information
jsteele-stripe committed Mar 20, 2023
1 parent 62f711a commit 89bef91
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion firestore-stripe-payments/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 89bef91

Please sign in to comment.