@@ -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.
@@ -387,12 +390,12 @@ export class CartService {
387390
388391 const accountCustomer = oldCart . uid
389392 ? await this . accountCustomerManager
390- . getAccountCustomerByUid ( oldCart . uid )
391- . catch ( ( error ) => {
392- if ( ! ( error instanceof AccountCustomerNotFoundError ) ) {
393- throw error ;
394- }
395- } )
393+ . getAccountCustomerByUid ( oldCart . uid )
394+ . catch ( ( error ) => {
395+ if ( ! ( error instanceof AccountCustomerNotFoundError ) ) {
396+ throw error ;
397+ }
398+ } )
396399 : undefined ;
397400
398401 if ( ! ( oldCart . taxAddress && oldCart . currency ) ) {
@@ -766,12 +769,18 @@ export class CartService {
766769 let fromPrice : FromPrice | undefined ;
767770 if ( cartEligibilityStatus === CartEligibilityStatus . UPGRADE ) {
768771 assert ( 'fromPrice' in eligibility , 'fromPrice not present for upgrade' ) ;
769- assertNotNull ( eligibility . fromPrice . unit_amount ) ;
770- assertNotNull ( eligibility . fromPrice . recurring ) ;
772+
773+ const { price : priceForCurrency , unitAmountForCurrency } = await this . priceManager . retrievePricingForCurrency ( eligibility . fromPrice . id , cart . currency ) ;
774+ assertNotNull ( unitAmountForCurrency ) ;
775+ assertNotNull ( priceForCurrency . recurring ) ;
776+
777+ const interval = getSubplatInterval ( priceForCurrency . recurring . interval , priceForCurrency . recurring . interval_count ) ;
778+ assert ( interval , 'Interval not found but is required' ) ;
779+
771780 fromPrice = {
772- currency : eligibility . fromPrice . currency ,
773- interval : eligibility . fromPrice . recurring . interval ,
774- listAmount : eligibility . fromPrice . unit_amount ,
781+ currency : cart . currency ,
782+ interval,
783+ unitAmount : unitAmountForCurrency ,
775784 } ;
776785 }
777786
0 commit comments