File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
firestore-stripe-payments/functions/src Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -361,13 +361,26 @@ export const createPortalLink = functions.https.onCall(
361
361
try {
362
362
const { returnUrl : return_url , locale = 'auto' , configuration } = data ;
363
363
// Get stripe customer id
364
- const customer = (
365
- await admin
364
+ let customerRecord = ( await admin
366
365
. firestore ( )
367
366
. collection ( config . customersCollectionPath )
368
367
. doc ( uid )
369
368
. 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
+
371
384
const params : Stripe . BillingPortal . SessionCreateParams = {
372
385
customer,
373
386
return_url,
You can’t perform that action at this time.
0 commit comments