Skip to content

Commit 9b1b011

Browse files
christiangencojsteele-stripedackers86
authored
feat(firestore-stripe-payments): create Stripe customer on-the-fly in createPortalLink
* chore(firestore-stripe-payments): 0.3.2 release * create Stripe customer on-the-fly to fix #479 --------- Co-authored-by: Jonathan Steele <[email protected]> Co-authored-by: Darren Ackers <[email protected]>
1 parent e2b030d commit 9b1b011

File tree

1 file changed

+16
-3
lines changed
  • firestore-stripe-payments/functions/src

1 file changed

+16
-3
lines changed

firestore-stripe-payments/functions/src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,26 @@ export const createPortalLink = functions.https.onCall(
361361
try {
362362
const { returnUrl: return_url, locale = 'auto', configuration } = data;
363363
// Get stripe customer id
364-
const customer = (
365-
await admin
364+
let customerRecord = (await admin
366365
.firestore()
367366
.collection(config.customersCollectionPath)
368367
.doc(uid)
369368
.get()
370-
).data().stripeId;
369+
).data();
370+
371+
if (!customerRecord?.stripeId) {
372+
// Create Stripe customer on-the-fly
373+
const { email, phoneNumber } = await admin
374+
.auth()
375+
.getUser(uid);
376+
customerRecord = await createCustomerRecord({
377+
uid,
378+
email,
379+
phone: phoneNumber,
380+
});
381+
}
382+
const customer = customerRecord.stripeId;
383+
371384
const params: Stripe.BillingPortal.SessionCreateParams = {
372385
customer,
373386
return_url,

0 commit comments

Comments
 (0)