@@ -15,6 +15,7 @@ import {
1515 StripePromotionCodeFactory ,
1616 StripeResponseFactory ,
1717 StripeUpcomingInvoiceFactory ,
18+ StripeAddressFactory ,
1819} from '@fxa/payments/stripe' ;
1920import { TaxAddressFactory } from './factories/tax-address.factory' ;
2021import { InvoicePreviewFactory } from './invoice.factories' ;
@@ -26,6 +27,10 @@ import {
2627 PayPalClient ,
2728 PaypalClientConfig ,
2829} from '@fxa/payments/paypal' ;
30+ import {
31+ CurrencyManager ,
32+ MockCurrencyConfigProvider ,
33+ } from '@fxa/payments/currency' ;
2934import { STRIPE_CUSTOMER_METADATA , STRIPE_INVOICE_METADATA } from './types' ;
3035
3136jest . mock ( '../lib/util/stripeInvoiceToFirstInvoicePreviewDTO' ) ;
@@ -49,6 +54,8 @@ describe('InvoiceManager', () => {
4954 StripeClient ,
5055 PayPalClient ,
5156 PaypalClientConfig ,
57+ CurrencyManager ,
58+ MockCurrencyConfigProvider ,
5259 MockStripeConfigProvider ,
5360 InvoiceManager ,
5461 ] ,
@@ -99,6 +106,7 @@ describe('InvoiceManager', () => {
99106
100107 const result = await invoiceManager . previewUpcoming ( {
101108 priceId : mockPrice . id ,
109+ currency : mockPrice . currency ,
102110 customer : mockCustomer ,
103111 taxAddress : mockTaxAddress ,
104112 } ) ;
@@ -135,6 +143,7 @@ describe('InvoiceManager', () => {
135143
136144 const result = await invoiceManager . previewUpcoming ( {
137145 priceId : mockPrice . id ,
146+ currency : mockPrice . currency ,
138147 customer : mockCustomer ,
139148 taxAddress : mockTaxAddress ,
140149 couponCode : mockPromotionCode . code ,
@@ -188,6 +197,7 @@ describe('InvoiceManager', () => {
188197 const mockInvoice = StripeInvoiceFactory ( {
189198 amount_due : 50 ,
190199 currency : 'usd' ,
200+ customer_shipping : { address : StripeAddressFactory ( ) } ,
191201 } ) ;
192202
193203 mockedGetMinimumChargeAmountForCurrency . mockReturnValue ( 10 ) ;
@@ -249,6 +259,7 @@ describe('InvoiceManager', () => {
249259 mockPaymentAttemptCount
250260 ) ,
251261 } ,
262+ customer_shipping : { address : StripeAddressFactory ( ) } ,
252263 } )
253264 ) ;
254265 const mockPayPalCharge = ChargeResponseFactory ( {
@@ -280,6 +291,7 @@ describe('InvoiceManager', () => {
280291 mockCustomer . metadata [ STRIPE_CUSTOMER_METADATA . PaypalAgreement ] ,
281292 invoiceNumber : mockInvoice . id ,
282293 currencyCode : mockInvoice . currency ,
294+ countryCode : mockInvoice . customer_shipping ?. address ?. country ,
283295 idempotencyKey : `${ mockInvoice . id } -${ mockPaymentAttemptCount } ` ,
284296 taxAmountInCents : mockInvoice . tax ,
285297 } ) ;
@@ -312,7 +324,11 @@ describe('InvoiceManager', () => {
312324 const mockCustomer = StripeResponseFactory (
313325 StripeCustomerFactory ( { metadata : { } } )
314326 ) ;
315- const mockInvoice = StripeResponseFactory ( StripeInvoiceFactory ( ) ) ;
327+ const mockInvoice = StripeResponseFactory (
328+ StripeInvoiceFactory ( {
329+ customer_shipping : { address : StripeAddressFactory ( ) } ,
330+ } )
331+ ) ;
316332
317333 await expect (
318334 invoiceManager . processPayPalNonZeroInvoice ( mockCustomer , mockInvoice )
@@ -321,7 +337,10 @@ describe('InvoiceManager', () => {
321337 it ( 'throws an error for an already-paid invoice' , async ( ) => {
322338 const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
323339 const mockInvoice = StripeResponseFactory (
324- StripeInvoiceFactory ( { status : 'paid' } )
340+ StripeInvoiceFactory ( {
341+ status : 'paid' ,
342+ customer_shipping : { address : StripeAddressFactory ( ) } ,
343+ } )
325344 ) ;
326345
327346 await expect (
@@ -331,7 +350,10 @@ describe('InvoiceManager', () => {
331350 it ( 'throws an error for an uncollectible invoice' , async ( ) => {
332351 const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
333352 const mockInvoice = StripeResponseFactory (
334- StripeInvoiceFactory ( { status : 'uncollectible' } )
353+ StripeInvoiceFactory ( {
354+ status : 'uncollectible' ,
355+ customer_shipping : { address : StripeAddressFactory ( ) } ,
356+ } )
335357 ) ;
336358
337359 await expect (
@@ -356,6 +378,7 @@ describe('InvoiceManager', () => {
356378 mockPaymentAttemptCount
357379 ) ,
358380 } ,
381+ customer_shipping : { address : StripeAddressFactory ( ) } ,
359382 } )
360383 ) ;
361384 const mockPayPalCharge = ChargeResponseFactory ( {
@@ -384,6 +407,7 @@ describe('InvoiceManager', () => {
384407 mockCustomer . metadata [ STRIPE_CUSTOMER_METADATA . PaypalAgreement ] ,
385408 invoiceNumber : mockInvoice . id ,
386409 currencyCode : mockInvoice . currency ,
410+ countryCode : mockInvoice . customer_shipping ?. address ?. country ,
387411 idempotencyKey : `${ mockInvoice . id } -${ mockPaymentAttemptCount } ` ,
388412 taxAmountInCents : mockInvoice . tax ,
389413 } ) ;
@@ -421,6 +445,7 @@ describe('InvoiceManager', () => {
421445 mockPaymentAttemptCount
422446 ) ,
423447 } ,
448+ customer_shipping : { address : StripeAddressFactory ( ) } ,
424449 } )
425450 ) ;
426451 const mockPayPalCharge = ChargeResponseFactory ( {
@@ -446,6 +471,7 @@ describe('InvoiceManager', () => {
446471 mockCustomer . metadata [ STRIPE_CUSTOMER_METADATA . PaypalAgreement ] ,
447472 invoiceNumber : mockInvoice . id ,
448473 currencyCode : mockInvoice . currency ,
474+ countryCode : mockInvoice . customer_shipping ?. address ?. country ,
449475 idempotencyKey : `${ mockInvoice . id } -${ mockPaymentAttemptCount } ` ,
450476 taxAmountInCents : mockInvoice . tax ,
451477 } ) ;
@@ -484,6 +510,7 @@ describe('InvoiceManager', () => {
484510 ) ,
485511 } ,
486512 tax : 0 ,
513+ customer_shipping : { address : StripeAddressFactory ( ) } ,
487514 } )
488515 ) ;
489516 const mockPayPalCharge = ChargeResponseFactory ( {
@@ -515,6 +542,7 @@ describe('InvoiceManager', () => {
515542 mockCustomer . metadata [ STRIPE_CUSTOMER_METADATA . PaypalAgreement ] ,
516543 invoiceNumber : mockInvoice . id ,
517544 currencyCode : mockInvoice . currency ,
545+ countryCode : mockInvoice . customer_shipping ?. address ?. country ,
518546 idempotencyKey : `${ mockInvoice . id } -${ mockPaymentAttemptCount } ` ,
519547 taxAmountInCents : mockInvoice . tax ,
520548 } ) ;
0 commit comments