@@ -26,6 +26,8 @@ import {
2626 retrieveSubscriptionItem ,
2727 PromotionCodeCouldNotBeAttachedError ,
2828 TaxAddress ,
29+ PriceManager ,
30+ getSubplatInterval ,
2931} from '@fxa/payments/customer' ;
3032import {
3133 EligibilityService ,
@@ -95,16 +97,17 @@ export class CartService {
9597 private currencyManager : CurrencyManager ,
9698 private customerManager : CustomerManager ,
9799 private customerSessionManager : CustomerSessionManager ,
98- private promotionCodeManager : PromotionCodeManager ,
99100 private eligibilityService : EligibilityService ,
100101 private invoiceManager : InvoiceManager ,
101102 @Inject ( LOGGER_PROVIDER ) private log : LoggerService ,
102- private productConfigurationManager : ProductConfigurationManager ,
103- private subscriptionManager : SubscriptionManager ,
104103 private paymentMethodManager : PaymentMethodManager ,
105104 private paymentIntentManager : PaymentIntentManager ,
106- @Inject ( StatsDService ) private statsd : StatsD
107- ) { }
105+ private priceManager : PriceManager ,
106+ private productConfigurationManager : ProductConfigurationManager ,
107+ private promotionCodeManager : PromotionCodeManager ,
108+ private subscriptionManager : SubscriptionManager ,
109+ @Inject ( StatsDService ) private statsd : StatsD ,
110+ ) { }
108111
109112 /**
110113 * Should be used to wrap any method that mutates an existing cart.
@@ -383,12 +386,12 @@ export class CartService {
383386
384387 const accountCustomer = oldCart . uid
385388 ? await this . accountCustomerManager
386- . getAccountCustomerByUid ( oldCart . uid )
387- . catch ( ( error ) => {
388- if ( ! ( error instanceof AccountCustomerNotFoundError ) ) {
389- throw error ;
390- }
391- } )
389+ . getAccountCustomerByUid ( oldCart . uid )
390+ . catch ( ( error ) => {
391+ if ( ! ( error instanceof AccountCustomerNotFoundError ) ) {
392+ throw error ;
393+ }
394+ } )
392395 : undefined ;
393396
394397 if ( ! ( oldCart . taxAddress && oldCart . currency ) ) {
@@ -762,12 +765,18 @@ export class CartService {
762765 let fromPrice : FromPrice | undefined ;
763766 if ( cartEligibilityStatus === CartEligibilityStatus . UPGRADE ) {
764767 assert ( 'fromPrice' in eligibility , 'fromPrice not present for upgrade' ) ;
765- assertNotNull ( eligibility . fromPrice . unit_amount ) ;
766- assertNotNull ( eligibility . fromPrice . recurring ) ;
768+
769+ const { price : priceForCurrency , unitAmountForCurrency } = await this . priceManager . retrievePricingForCurrency ( eligibility . fromPrice . id , cart . currency ) ;
770+ assertNotNull ( unitAmountForCurrency ) ;
771+ assertNotNull ( priceForCurrency . recurring ) ;
772+
773+ const interval = getSubplatInterval ( priceForCurrency . recurring . interval , priceForCurrency . recurring . interval_count ) ;
774+ assert ( interval , 'Interval not found but is required' ) ;
775+
767776 fromPrice = {
768- currency : eligibility . fromPrice . currency ,
769- interval : eligibility . fromPrice . recurring . interval ,
770- listAmount : eligibility . fromPrice . unit_amount ,
777+ currency : cart . currency ,
778+ interval,
779+ unitAmount : unitAmountForCurrency ,
771780 } ;
772781 }
773782
0 commit comments