@@ -36,8 +36,6 @@ import {
3636import {
3737 AccountCustomerManager ,
3838 AccountCustomerNotFoundError ,
39- StripeCustomer ,
40- StripeSubscription ,
4139} from '@fxa/payments/stripe' ;
4240import {
4341 ProductConfigError ,
@@ -656,31 +654,35 @@ export class CartService {
656654
657655 assert ( cart . taxAddress !== null , 'Cart must have a tax address' ) ;
658656 assert ( cart . currency !== null , 'Cart must have a currency' ) ;
659-
660- const [ price , metricsOptedOut ] = await Promise . all ( [
657+ const [
658+ price ,
659+ metricsOptedOut ,
660+ eligibility ,
661+ customer ,
662+ subscriptions ,
663+ customerSession ,
664+ ] = await Promise . all ( [
661665 this . productConfigurationManager . retrieveStripePrice (
662666 cart . offeringConfigId ,
663667 cart . interval as SubplatInterval
664668 ) ,
665669 this . metricsOptedOut ( cart . uid ) ,
666- ] ) ;
667-
668- let customer : StripeCustomer | undefined ;
669- let subscriptions : StripeSubscription [ ] = [ ] ;
670- if ( cart . stripeCustomerId ) {
671- [ customer , subscriptions ] = await Promise . all ( [
672- this . customerManager . retrieve ( cart . stripeCustomerId ) ,
673- this . subscriptionManager . listForCustomer ( cart . stripeCustomerId ) ,
674- ] ) ;
675- }
676-
677- const eligibility = await this . eligibilityService . checkEligibility (
678- cart . interval as SubplatInterval ,
679- cart . offeringConfigId ,
680- cart . uid ,
670+ this . eligibilityService . checkEligibility (
671+ cart . interval as SubplatInterval ,
672+ cart . offeringConfigId ,
673+ cart . uid ,
674+ cart . stripeCustomerId
675+ ) ,
681676 cart . stripeCustomerId
682- ) ;
683-
677+ ? this . customerManager . retrieve ( cart . stripeCustomerId )
678+ : undefined ,
679+ cart . stripeCustomerId
680+ ? this . subscriptionManager . listForCustomer ( cart . stripeCustomerId )
681+ : undefined ,
682+ cart . stripeCustomerId
683+ ? this . customerSessionManager . create ( cart . stripeCustomerId )
684+ : undefined ,
685+ ] ) ;
684686 const cartEligibilityStatus =
685687 handleEligibilityStatusMap [ eligibility . subscriptionEligibilityResult ] ;
686688
@@ -723,16 +725,9 @@ export class CartService {
723725 subscriptions
724726 ) ;
725727 if ( paymentMethodType ?. type === 'stripe' ) {
726- const paymentMethodPromise = this . paymentMethodManager . retrieve (
728+ const paymentMethod = await this . paymentMethodManager . retrieve (
727729 paymentMethodType . paymentMethodId
728730 ) ;
729- const customerSessionPromise = cart . stripeCustomerId
730- ? this . customerSessionManager . create ( cart . stripeCustomerId )
731- : undefined ;
732- const [ paymentMethod , customerSession ] = await Promise . all ( [
733- paymentMethodPromise ,
734- customerSessionPromise ,
735- ] ) ;
736731 paymentInfo = {
737732 type : paymentMethod . type ,
738733 last4 : paymentMethod . card ?. last4 ,
@@ -750,6 +745,7 @@ export class CartService {
750745 if (
751746 customer &&
752747 cart . stripeSubscriptionId &&
748+ subscriptions &&
753749 cart . state !== CartState . FAIL
754750 ) {
755751 const subscription = subscriptions . find (
@@ -816,7 +812,7 @@ export class CartService {
816812 ? eligibility . fromOfferingConfigId
817813 : undefined ,
818814 fromPrice : 'fromPrice' in eligibility ? fromPrice : undefined ,
819- hasActiveSubscriptions : ! ! subscriptions . length ,
815+ hasActiveSubscriptions : ! ! subscriptions ? .length ,
820816 } ;
821817 }
822818
0 commit comments