Merge branch 'INDA-330-pii-update' into 'main'
[ProtonMail-WebClient.git] / packages / payments / core / methods.test.ts
blob1b329310d34865f90f88d6018e79e9739e4d38aa
1 import { MIN_BITCOIN_AMOUNT, MIN_PAYPAL_AMOUNT_CHARGEBEE, UNPAID_STATE } from '@proton/payments';
2 import { queryPaymentMethods } from '@proton/shared/lib/api/payments';
3 import { BillingPlatform, ChargebeeEnabled } from '@proton/shared/lib/interfaces';
4 import { buildSubscription, buildUser } from '@proton/testing/builders';
6 import { Autopay, FREE_SUBSCRIPTION, MethodStorage, PAYMENT_METHOD_TYPES, PLANS, signupFlows } from './constants';
7 import {
8     type PaymentMethodFlows,
9     type PaymentMethodStatus,
10     type PaymentsApi,
11     type SavedPaymentMethod,
12 } from './interface';
13 import { PaymentMethods, initializePaymentMethods } from './methods';
15 const TEST_CURRENCY = 'USD' as const;
17 let status: PaymentMethodStatus;
19 beforeEach(() => {
20     status = {
21         Card: true,
22         Paypal: true,
23         Apple: true,
24         Cash: true,
25         Bitcoin: true,
26     };
27 });
29 const undefinedBillingAddress = undefined;
30 const enableSepaTrue = true;
32 describe('getNewMethods()', () => {
33     it('should include card when card is available', () => {
34         const methods = new PaymentMethods({
35             paymentMethodStatus: status,
36             paymentMethods: [],
37             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
38             amount: 500,
39             currency: TEST_CURRENCY,
40             coupon: '',
41             flow: 'subscription',
42             selectedPlanName: undefined,
43             billingPlatform: undefined,
44             chargebeeUserExists: undefined,
45             disableNewPaymentMethods: false,
46             billingAddress: undefinedBillingAddress,
47             enableSepa: enableSepaTrue,
48         });
50         expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
51     });
53     it('should not include card when card is not available', () => {
54         status.Card = false;
56         const methods = new PaymentMethods({
57             paymentMethodStatus: status,
58             paymentMethods: [],
59             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
60             amount: 500,
61             currency: TEST_CURRENCY,
62             coupon: '',
63             flow: 'subscription',
64             selectedPlanName: undefined,
65             billingPlatform: undefined,
66             chargebeeUserExists: undefined,
67             disableNewPaymentMethods: false,
68             billingAddress: undefinedBillingAddress,
69             enableSepa: enableSepaTrue,
70         });
72         expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(false);
73     });
75     // tests for PayPal
76     it('should include PayPal when PayPal is available', () => {
77         const methods = new PaymentMethods({
78             paymentMethodStatus: status,
79             paymentMethods: [],
80             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
81             amount: 500,
82             currency: TEST_CURRENCY,
83             coupon: '',
84             flow: 'subscription',
85             selectedPlanName: undefined,
86             billingPlatform: undefined,
87             chargebeeUserExists: undefined,
88             disableNewPaymentMethods: false,
89             billingAddress: undefinedBillingAddress,
90             enableSepa: enableSepaTrue,
91         });
93         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
94     });
96     it('should not include PayPal when PayPal is not available due to amount less than minimum', () => {
97         const methods = new PaymentMethods({
98             paymentMethodStatus: status,
99             paymentMethods: [],
100             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
101             amount: 50,
102             currency: TEST_CURRENCY,
103             coupon: '',
104             flow: 'subscription',
105             selectedPlanName: undefined,
106             billingPlatform: undefined,
107             chargebeeUserExists: undefined,
108             disableNewPaymentMethods: false,
109             billingAddress: undefinedBillingAddress,
110             enableSepa: enableSepaTrue,
111         });
113         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
114     });
116     it('should not include PayPal when already used as payment method', () => {
117         const methods = new PaymentMethods({
118             paymentMethodStatus: status,
119             paymentMethods: [
120                 {
121                     ID: '1',
122                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
123                     Order: 500,
124                     Details: {
125                         BillingAgreementID: 'BA-123',
126                         PayerID: '123',
127                         Payer: '123',
128                     },
129                     External: MethodStorage.INTERNAL,
130                 },
131             ],
132             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
133             amount: 500,
134             currency: TEST_CURRENCY,
135             coupon: '',
136             flow: 'subscription',
137             selectedPlanName: undefined,
138             billingPlatform: undefined,
139             chargebeeUserExists: undefined,
140             disableNewPaymentMethods: false,
141             billingAddress: undefinedBillingAddress,
142             enableSepa: enableSepaTrue,
143         });
145         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
146     });
148     it('should include Bitcoin when Bitcoin is available', () => {
149         const methods = new PaymentMethods({
150             paymentMethodStatus: status,
151             paymentMethods: [],
152             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
153             amount: 500,
154             currency: TEST_CURRENCY,
155             coupon: '',
156             flow: 'subscription',
157             selectedPlanName: undefined,
158             billingPlatform: undefined,
159             chargebeeUserExists: undefined,
160             disableNewPaymentMethods: false,
161             billingAddress: undefinedBillingAddress,
162             enableSepa: enableSepaTrue,
163         });
165         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
166     });
168     it.each(['signup'] as PaymentMethodFlows[])(
169         'should not include Bitcoin when Bitcoin is not available due to flow %s',
170         (flow) => {
171             const methods = new PaymentMethods({
172                 paymentMethodStatus: status,
173                 paymentMethods: [],
174                 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
175                 amount: 500,
176                 currency: TEST_CURRENCY,
177                 coupon: '',
178                 flow: flow,
179                 selectedPlanName: undefined,
180                 billingPlatform: undefined,
181                 chargebeeUserExists: undefined,
182                 disableNewPaymentMethods: false,
183                 billingAddress: undefinedBillingAddress,
184                 enableSepa: enableSepaTrue,
185             });
187             expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
188         }
189     );
191     it('should not include bitcoin due to amount less than minimum', () => {
192         const methods = new PaymentMethods({
193             paymentMethodStatus: status,
194             paymentMethods: [],
195             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
196             amount: 50,
197             currency: TEST_CURRENCY,
198             coupon: '',
199             flow: 'subscription',
200             selectedPlanName: undefined,
201             billingPlatform: undefined,
202             chargebeeUserExists: undefined,
203             disableNewPaymentMethods: false,
204             billingAddress: undefinedBillingAddress,
205             enableSepa: enableSepaTrue,
206         });
208         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
209     });
211     it('should include Cash when Cash is available', () => {
212         const methods = new PaymentMethods({
213             paymentMethodStatus: status,
214             paymentMethods: [],
215             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
216             amount: 500,
217             currency: TEST_CURRENCY,
218             coupon: '',
219             flow: 'subscription',
220             selectedPlanName: undefined,
221             billingPlatform: undefined,
222             chargebeeUserExists: undefined,
223             disableNewPaymentMethods: false,
224             billingAddress: undefinedBillingAddress,
225             enableSepa: enableSepaTrue,
226         });
228         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
229     });
231     it.each(['signup', 'signup-pass', 'signup-pass-upgrade'] as PaymentMethodFlows[])(
232         'should not include Cash when Cash is not available due to flow %s',
233         (flow) => {
234             const methods = new PaymentMethods({
235                 paymentMethodStatus: status,
236                 paymentMethods: [],
237                 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
238                 amount: 500,
239                 currency: TEST_CURRENCY,
240                 coupon: '',
241                 flow: flow,
242                 selectedPlanName: undefined,
243                 billingPlatform: undefined,
244                 chargebeeUserExists: undefined,
245                 disableNewPaymentMethods: false,
246                 billingAddress: undefinedBillingAddress,
247                 enableSepa: enableSepaTrue,
248             });
250             expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
251         }
252     );
254     it('should return chargebee methods when they are enabled', () => {
255         const methods = new PaymentMethods({
256             paymentMethodStatus: status,
257             paymentMethods: [],
258             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
259             amount: 500,
260             currency: TEST_CURRENCY,
261             coupon: '',
262             flow: 'subscription',
263             selectedPlanName: undefined,
264             billingPlatform: undefined,
265             chargebeeUserExists: undefined,
266             disableNewPaymentMethods: false,
267             billingAddress: undefinedBillingAddress,
268             enableSepa: enableSepaTrue,
269         });
271         expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_CARD)).toBe(
272             true
273         );
274         expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_PAYPAL)).toBe(
275             true
276         );
277     });
279     it('should not return chargebee methods when they are disabled', () => {
280         const methods = new PaymentMethods({
281             paymentMethodStatus: status,
282             paymentMethods: [],
283             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
284             amount: 500,
285             currency: TEST_CURRENCY,
286             coupon: '',
287             flow: 'subscription',
288             selectedPlanName: undefined,
289             billingPlatform: undefined,
290             chargebeeUserExists: undefined,
291             disableNewPaymentMethods: false,
292             billingAddress: undefinedBillingAddress,
293             enableSepa: enableSepaTrue,
294         });
296         expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_CARD)).toBe(
297             false
298         );
299         expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_PAYPAL)).toBe(
300             false
301         );
302     });
305 describe('getUsedMethods()', () => {
306     it('should return used methods: paypal and cards', () => {
307         const methods = new PaymentMethods({
308             paymentMethodStatus: status,
309             paymentMethods: [
310                 {
311                     ID: '1',
312                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
313                     Order: 500,
314                     Details: {
315                         BillingAgreementID: 'BA-123',
316                         PayerID: '123',
317                         Payer: '123',
318                     },
319                     External: MethodStorage.INTERNAL,
320                 },
321                 {
322                     ID: '2',
323                     Type: PAYMENT_METHOD_TYPES.CARD,
324                     Order: 501,
325                     Autopay: Autopay.ENABLE,
326                     Details: {
327                         Name: 'Arthur Morgan',
328                         ExpMonth: '12',
329                         ExpYear: '2030',
330                         ZIP: '12345',
331                         Country: 'US',
332                         Last4: '1234',
333                         Brand: 'Visa',
334                     },
335                     External: MethodStorage.INTERNAL,
336                 },
337                 // one more card
338                 {
339                     ID: '3',
340                     Type: PAYMENT_METHOD_TYPES.CARD,
341                     Order: 502,
342                     Autopay: Autopay.ENABLE,
343                     Details: {
344                         Name: 'Arthur Morgan',
345                         ExpMonth: '11',
346                         ExpYear: '2031',
347                         ZIP: '12345',
348                         Country: 'US',
349                         Last4: '4242',
350                         Brand: 'Visa',
351                     },
352                     External: MethodStorage.INTERNAL,
353                 },
354             ],
355             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
356             amount: 500,
357             currency: TEST_CURRENCY,
358             coupon: '',
359             flow: 'subscription',
360             selectedPlanName: undefined,
361             billingPlatform: undefined,
362             chargebeeUserExists: undefined,
363             disableNewPaymentMethods: false,
364             billingAddress: undefinedBillingAddress,
365             enableSepa: enableSepaTrue,
366         });
368         expect(methods.getUsedMethods().some((method) => method.type === 'paypal')).toBe(true);
369         expect(methods.getUsedMethods().some((method) => method.value === '1')).toBe(true);
370         expect(methods.getUsedMethods().filter((method) => method.type === 'card').length).toBe(2);
371         expect(methods.getUsedMethods().some((method) => method.value === '2')).toBe(true);
372         expect(methods.getUsedMethods().some((method) => method.value === '3')).toBe(true);
373     });
376 describe('getAvailablePaymentMethods()', () => {
377     it('should return combination of new and used methods', () => {
378         const methods = new PaymentMethods({
379             paymentMethodStatus: status,
380             paymentMethods: [
381                 {
382                     ID: '1',
383                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
384                     Order: 500,
385                     Details: {
386                         BillingAgreementID: 'BA-123',
387                         PayerID: '123',
388                         Payer: '123',
389                     },
390                     External: MethodStorage.INTERNAL,
391                 },
392                 {
393                     ID: '2',
394                     Type: PAYMENT_METHOD_TYPES.CARD,
395                     Order: 501,
396                     Autopay: Autopay.ENABLE,
397                     Details: {
398                         Name: 'Arthur Morgan',
399                         ExpMonth: '12',
400                         ExpYear: '2030',
401                         ZIP: '12345',
402                         Country: 'US',
403                         Last4: '1234',
404                         Brand: 'Visa',
405                     },
406                     External: MethodStorage.INTERNAL,
407                 },
408                 // one more card
409                 {
410                     ID: '3',
411                     Type: PAYMENT_METHOD_TYPES.CARD,
412                     Order: 502,
413                     Autopay: Autopay.ENABLE,
414                     Details: {
415                         Name: 'Arthur Morgan',
416                         ExpMonth: '11',
417                         ExpYear: '2031',
418                         ZIP: '12345',
419                         Country: 'US',
420                         Last4: '4242',
421                         Brand: 'Visa',
422                     },
423                     External: MethodStorage.INTERNAL,
424                 },
425             ],
426             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
427             amount: 500,
428             currency: TEST_CURRENCY,
429             coupon: '',
430             flow: 'subscription',
431             selectedPlanName: undefined,
432             billingPlatform: undefined,
433             chargebeeUserExists: undefined,
434             disableNewPaymentMethods: false,
435             billingAddress: undefinedBillingAddress,
436             enableSepa: enableSepaTrue,
437         });
439         const availableMethods = methods.getAvailablePaymentMethods();
441         expect(availableMethods.usedMethods.some((method) => method.type === 'paypal')).toBe(true);
442         expect(availableMethods.usedMethods.some((method) => method.value === '1')).toBe(true);
443         expect(availableMethods.usedMethods.filter((method) => method.type === 'card').length).toBe(2);
444         expect(availableMethods.usedMethods.some((method) => method.value === '2')).toBe(true);
445         expect(availableMethods.usedMethods.some((method) => method.value === '3')).toBe(true);
447         // if paypal already saved, it can't be a new method too
448         expect(availableMethods.methods.some((method) => method.type === 'paypal')).toBe(false);
449         expect(availableMethods.methods.some((method) => method.type === 'card')).toBe(true);
450     });
453 describe('getLastUsedMethod()', () => {
454     it('should return last used method', () => {
455         const methods = new PaymentMethods({
456             paymentMethodStatus: status,
457             paymentMethods: [
458                 {
459                     ID: '1',
460                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
461                     Order: 500,
462                     Details: {
463                         BillingAgreementID: 'BA-123',
464                         PayerID: '123',
465                         Payer: '123',
466                     },
467                     External: MethodStorage.INTERNAL,
468                 },
469                 {
470                     ID: '2',
471                     Type: PAYMENT_METHOD_TYPES.CARD,
472                     Order: 501,
473                     Autopay: Autopay.ENABLE,
474                     Details: {
475                         Name: 'Arthur Morgan',
476                         ExpMonth: '12',
477                         ExpYear: '2030',
478                         ZIP: '12345',
479                         Country: 'US',
480                         Last4: '1234',
481                         Brand: 'Visa',
482                     },
483                     External: MethodStorage.INTERNAL,
484                 },
485                 // one more card
486                 {
487                     ID: '3',
488                     Type: PAYMENT_METHOD_TYPES.CARD,
489                     Order: 502,
490                     Autopay: Autopay.ENABLE,
491                     Details: {
492                         Name: 'Arthur Morgan',
493                         ExpMonth: '11',
494                         ExpYear: '2031',
495                         ZIP: '12345',
496                         Country: 'US',
497                         Last4: '4242',
498                         Brand: 'Visa',
499                     },
500                     External: MethodStorage.INTERNAL,
501                 },
502             ],
503             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
504             amount: 500,
505             currency: TEST_CURRENCY,
506             coupon: '',
507             flow: 'subscription',
508             selectedPlanName: undefined,
509             billingPlatform: undefined,
510             chargebeeUserExists: undefined,
511             disableNewPaymentMethods: false,
512             billingAddress: undefinedBillingAddress,
513             enableSepa: enableSepaTrue,
514         });
516         const lastUsedMethod = methods.getLastUsedMethod();
518         expect(lastUsedMethod).toEqual({
519             type: PAYMENT_METHOD_TYPES.PAYPAL,
520             paymentMethodId: '1',
521             value: '1',
522             isSaved: true,
523             isExpired: false,
524         });
525     });
528 describe('getSavedMethodById()', () => {
529     it('should return the correct saved method by id', () => {
530         const methods = new PaymentMethods({
531             paymentMethodStatus: status,
532             paymentMethods: [
533                 {
534                     ID: '1',
535                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
536                     Order: 500,
537                     Details: {
538                         BillingAgreementID: 'BA-123',
539                         PayerID: '123',
540                         Payer: '123',
541                     },
542                     External: MethodStorage.INTERNAL,
543                 },
544                 {
545                     ID: '2',
546                     Type: PAYMENT_METHOD_TYPES.CARD,
547                     Order: 501,
548                     Autopay: Autopay.ENABLE,
549                     Details: {
550                         Name: 'Arthur Morgan',
551                         ExpMonth: '12',
552                         ExpYear: '2030',
553                         ZIP: '12345',
554                         Country: 'US',
555                         Last4: '1234',
556                         Brand: 'Visa',
557                     },
558                     External: MethodStorage.INTERNAL,
559                 },
560                 // one more card
561                 {
562                     ID: '3',
563                     Type: PAYMENT_METHOD_TYPES.CARD,
564                     Order: 502,
565                     Autopay: Autopay.ENABLE,
566                     Details: {
567                         Name: 'Arthur Morgan',
568                         ExpMonth: '11',
569                         ExpYear: '2031',
570                         ZIP: '12345',
571                         Country: 'US',
572                         Last4: '4242',
573                         Brand: 'Visa',
574                     },
575                     External: MethodStorage.INTERNAL,
576                 },
577                 // external card
578                 {
579                     ID: '4',
580                     Type: PAYMENT_METHOD_TYPES.CARD,
581                     Order: 503,
582                     Autopay: Autopay.ENABLE,
583                     Details: {
584                         Name: 'Arthur Morgan',
585                         ExpMonth: '10',
586                         ExpYear: '2029',
587                         ZIP: '54321',
588                         Country: 'US',
589                         Last4: '4242',
590                         Brand: 'Visa',
591                     },
592                     External: MethodStorage.EXTERNAL,
593                 },
594             ],
595             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
596             amount: 500,
597             currency: TEST_CURRENCY,
598             coupon: '',
599             flow: 'subscription',
600             selectedPlanName: undefined,
601             billingPlatform: undefined,
602             chargebeeUserExists: undefined,
603             disableNewPaymentMethods: false,
604             billingAddress: undefinedBillingAddress,
605             enableSepa: enableSepaTrue,
606         });
608         const savedMethod = methods.getSavedMethodById('2');
610         expect(savedMethod).toEqual({
611             ID: '2',
612             Type: PAYMENT_METHOD_TYPES.CARD,
613             Order: 501,
614             Autopay: Autopay.ENABLE,
615             Details: {
616                 Name: 'Arthur Morgan',
617                 ExpMonth: '12',
618                 ExpYear: '2030',
619                 ZIP: '12345',
620                 Country: 'US',
621                 Last4: '1234',
622                 Brand: 'Visa',
623             },
624             External: MethodStorage.INTERNAL,
625         });
627         const externalMethod = methods.getSavedMethodById('4');
629         expect(externalMethod).toEqual({
630             ID: '4',
631             Type: PAYMENT_METHOD_TYPES.CARD,
632             Order: 503,
633             Autopay: Autopay.ENABLE,
634             Details: {
635                 Name: 'Arthur Morgan',
636                 ExpMonth: '10',
637                 ExpYear: '2029',
638                 ZIP: '54321',
639                 Country: 'US',
640                 Last4: '4242',
641                 Brand: 'Visa',
642             },
643             External: MethodStorage.EXTERNAL,
644         });
645     });
648 describe('initializePaymentMethods()', () => {
649     it('should correctly initialize payment methods', async () => {
650         const apiMock = jest.fn();
651         const paymentMethodStatus: PaymentMethodStatus = {
652             Card: true,
653             Paypal: true,
654             Apple: true,
655             Cash: true,
656             Bitcoin: true,
657         };
659         const paymentMethods: SavedPaymentMethod[] = [
660             {
661                 ID: '1',
662                 Type: PAYMENT_METHOD_TYPES.CARD,
663                 Order: 500,
664                 Autopay: Autopay.ENABLE,
665                 Details: {
666                     Name: 'Arthur Morgan',
667                     ExpMonth: '12',
668                     ExpYear: '2030',
669                     ZIP: '12345',
670                     Country: 'US',
671                     Last4: '1234',
672                     Brand: 'Visa',
673                 },
674                 External: MethodStorage.INTERNAL,
675             },
676         ];
678         apiMock.mockImplementation(({ url }) => {
679             if (url === queryPaymentMethods().url) {
680                 return {
681                     PaymentMethods: paymentMethods,
682                 };
683             }
685             if (url === 'payments/v4/status') {
686                 return {
687                     VendorStatus: paymentMethodStatus,
688                 };
689             }
690             if (url === 'payments/v5/status') {
691                 return {
692                     VendorStatus: paymentMethodStatus,
693                 };
694             }
695         });
697         const methods = await initializePaymentMethods({
698             api: apiMock,
699             maybePaymentMethodStatus: undefined,
700             maybePaymentMethods: undefined,
701             isAuthenticated: true,
702             amount: 500,
703             currency: TEST_CURRENCY,
704             coupon: 'coupon',
705             flow: 'subscription' as PaymentMethodFlows,
706             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
707             paymentsApi: {
708                 statusExtendedAutomatic: () => paymentMethodStatus,
709             } as any as PaymentsApi,
710             selectedPlanName: undefined,
711             billingPlatform: undefined,
712             chargebeeUserExists: undefined,
713             disableNewPaymentMethods: false,
714             billingAddress: undefined,
715             enableSepa: false,
716         });
718         expect(methods).toBeDefined();
719         expect(methods.flow).toEqual('subscription');
720         expect(methods.amount).toEqual(500);
721         expect(methods.coupon).toEqual('coupon');
722         expect(methods.getAvailablePaymentMethods().methods.length).toBeGreaterThan(0);
723     });
725     it('should correctly initialize payment methods when user is not authenticated', async () => {
726         const apiMock = jest.fn();
728         const paymentMethodStatus: PaymentMethodStatus = {
729             Card: true,
730             Paypal: true,
731             Apple: true,
732             Cash: true,
733             Bitcoin: true,
734         };
736         apiMock.mockImplementation(({ url }) => {
737             if (url === 'payments/v4/status') {
738                 return paymentMethodStatus;
739             }
740             if (url === 'payments/v5/status') {
741                 return paymentMethodStatus;
742             }
743         });
745         const methods = await initializePaymentMethods({
746             api: apiMock,
747             maybePaymentMethodStatus: undefined,
748             maybePaymentMethods: undefined,
749             isAuthenticated: false,
750             amount: 500,
751             currency: TEST_CURRENCY,
752             coupon: 'coupon',
753             flow: 'subscription' as PaymentMethodFlows,
754             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
755             paymentsApi: {
756                 statusExtendedAutomatic: () => paymentMethodStatus,
757             } as any as PaymentsApi,
758             selectedPlanName: undefined,
759             billingPlatform: undefined,
760             chargebeeUserExists: undefined,
761             disableNewPaymentMethods: false,
762             billingAddress: undefined,
763             enableSepa: false,
764         });
766         expect(methods).toBeDefined();
767         expect(methods.flow).toEqual('subscription');
768         expect(methods.amount).toEqual(500);
769         expect(methods.coupon).toEqual('coupon');
770         expect(methods.getAvailablePaymentMethods().methods.length).toBeGreaterThan(0);
771     });
774 describe('Cash', () => {
775     it('should display cash', () => {
776         const flow: PaymentMethodFlows = 'subscription';
778         const methods = new PaymentMethods({
779             paymentMethodStatus: status,
780             paymentMethods: [],
781             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
782             amount: 500,
783             currency: TEST_CURRENCY,
784             coupon: '',
785             flow: flow,
786             selectedPlanName: undefined,
787             billingPlatform: undefined,
788             chargebeeUserExists: undefined,
789             disableNewPaymentMethods: false,
790             billingAddress: undefinedBillingAddress,
791             enableSepa: enableSepaTrue,
792         });
794         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
795     });
797     it('should not display cash if status is false', () => {
798         const st = { ...status, Cash: false };
799         const flow: PaymentMethodFlows = 'subscription';
801         const methods = new PaymentMethods({
802             paymentMethodStatus: st,
803             paymentMethods: [],
804             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
805             amount: 500,
806             currency: TEST_CURRENCY,
807             coupon: '',
808             flow: flow,
809             selectedPlanName: undefined,
810             billingPlatform: undefined,
811             chargebeeUserExists: undefined,
812             disableNewPaymentMethods: false,
813             billingAddress: undefinedBillingAddress,
814             enableSepa: enableSepaTrue,
815         });
817         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
818     });
820     it.each(signupFlows)('should not display cash in signup flows', (flow) => {
821         const methods = new PaymentMethods({
822             paymentMethodStatus: status,
823             paymentMethods: [],
824             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
825             amount: 500,
826             currency: TEST_CURRENCY,
827             coupon: '',
828             flow: flow,
829             selectedPlanName: undefined,
830             billingPlatform: undefined,
831             chargebeeUserExists: undefined,
832             disableNewPaymentMethods: false,
833             billingAddress: undefinedBillingAddress,
834             enableSepa: enableSepaTrue,
835         });
837         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
838     });
840     it('should not display cash if user buys Pass Lifetime', () => {
841         const flow: PaymentMethodFlows = 'subscription';
843         const methods = new PaymentMethods({
844             paymentMethodStatus: status,
845             paymentMethods: [],
846             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
847             amount: 500,
848             currency: TEST_CURRENCY,
849             coupon: '',
850             flow: flow,
851             selectedPlanName: undefined,
852             billingPlatform: undefined,
853             chargebeeUserExists: undefined,
854             disableNewPaymentMethods: false,
855             billingAddress: undefinedBillingAddress,
856             enableSepa: enableSepaTrue,
857             planIDs: {
858                 [PLANS.PASS_LIFETIME]: 1,
859             },
860         });
862         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
863     });
865     it('should display cash if user does not buy Pass Lifetime', () => {
866         const flow: PaymentMethodFlows = 'subscription';
868         const methods = new PaymentMethods({
869             paymentMethodStatus: status,
870             paymentMethods: [],
871             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
872             amount: 500,
873             currency: TEST_CURRENCY,
874             coupon: '',
875             flow: flow,
876             selectedPlanName: undefined,
877             billingPlatform: undefined,
878             chargebeeUserExists: undefined,
879             disableNewPaymentMethods: false,
880             billingAddress: undefinedBillingAddress,
881             enableSepa: enableSepaTrue,
882             planIDs: {
883                 [PLANS.MAIL]: 1, // Using a different plan
884             },
885         });
887         expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
888     });
891 describe('Chargebee Bitcoin', () => {
892     it('should display bitcoin', () => {
893         const flow: PaymentMethodFlows = 'subscription';
895         const methods = new PaymentMethods({
896             paymentMethodStatus: status,
897             paymentMethods: [],
898             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
899             amount: 500,
900             currency: TEST_CURRENCY,
901             coupon: '',
902             flow: flow,
903             selectedPlanName: undefined,
904             billingPlatform: undefined,
905             chargebeeUserExists: undefined,
906             disableNewPaymentMethods: false,
907             billingAddress: undefinedBillingAddress,
908             enableSepa: enableSepaTrue,
909         });
911         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
912     });
914     it('should not display bitcoin if status is false', () => {
915         const st = { ...status, Bitcoin: false };
916         const flow: PaymentMethodFlows = 'subscription';
918         const methods = new PaymentMethods({
919             paymentMethodStatus: st,
920             paymentMethods: [],
921             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
922             amount: 500,
923             currency: TEST_CURRENCY,
924             coupon: '',
925             flow: flow,
926             selectedPlanName: undefined,
927             billingPlatform: undefined,
928             chargebeeUserExists: undefined,
929             disableNewPaymentMethods: false,
930             billingAddress: undefinedBillingAddress,
931             enableSepa: enableSepaTrue,
932         });
934         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
935     });
937     it.each([
938         'invoice',
939         'signup',
940         'signup-v2',
941         'signup-v2-upgrade',
942         'signup-vpn',
943         'add-card',
944         'add-paypal',
945     ] as PaymentMethodFlows[])('should not display bitcoin in %s flow', (flow) => {
946         const methods = new PaymentMethods({
947             paymentMethodStatus: status,
948             paymentMethods: [],
949             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
950             amount: 500,
951             currency: TEST_CURRENCY,
952             coupon: '',
953             flow: flow,
954             selectedPlanName: undefined,
955             billingPlatform: undefined,
956             chargebeeUserExists: undefined,
957             disableNewPaymentMethods: false,
958             billingAddress: undefinedBillingAddress,
959             enableSepa: enableSepaTrue,
960         });
962         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
963     });
965     it('should not display bitcoin if amount is less than minimum', () => {
966         const flow: PaymentMethodFlows = 'subscription';
968         const methods = new PaymentMethods({
969             paymentMethodStatus: status,
970             paymentMethods: [],
971             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
972             amount: MIN_BITCOIN_AMOUNT - 1,
973             currency: TEST_CURRENCY,
974             coupon: '',
975             flow: flow,
976             selectedPlanName: undefined,
977             billingPlatform: undefined,
978             chargebeeUserExists: undefined,
979             disableNewPaymentMethods: false,
980             billingAddress: undefinedBillingAddress,
981             enableSepa: enableSepaTrue,
982         });
984         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
985     });
987     it.each([PLANS.MAIL_PRO, PLANS.DRIVE_PRO, PLANS.BUNDLE_PRO, PLANS.BUNDLE_PRO_2024])(
988         'should not display bitcoin for b2b plans',
989         (plan) => {
990             const flow: PaymentMethodFlows = 'subscription';
992             const methods = new PaymentMethods({
993                 paymentMethodStatus: status,
994                 paymentMethods: [],
995                 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
996                 amount: 500,
997                 currency: TEST_CURRENCY,
998                 coupon: '',
999                 flow: flow,
1000                 selectedPlanName: plan,
1001                 billingPlatform: undefined,
1002                 chargebeeUserExists: undefined,
1003                 disableNewPaymentMethods: false,
1004                 billingAddress: undefinedBillingAddress,
1005                 enableSepa: enableSepaTrue,
1006             });
1008             expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1009         }
1010     );
1012     it('should return false if INHOUSE_FORCED', () => {
1013         const flow: PaymentMethodFlows = 'subscription';
1015         const methods = new PaymentMethods({
1016             paymentMethodStatus: status,
1017             paymentMethods: [],
1018             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1019             amount: 500,
1020             currency: TEST_CURRENCY,
1021             coupon: '',
1022             flow: flow,
1023             selectedPlanName: undefined,
1024             billingPlatform: undefined,
1025             chargebeeUserExists: undefined,
1026             disableNewPaymentMethods: false,
1027             billingAddress: undefinedBillingAddress,
1028             enableSepa: enableSepaTrue,
1029         });
1031         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1032     });
1034     it('should return false in the migration condition', () => {
1035         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === false
1036         const flow: PaymentMethodFlows = 'credit';
1038         const chargebeeUserExists = 0;
1040         const methods = new PaymentMethods({
1041             paymentMethodStatus: status,
1042             paymentMethods: [],
1043             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1044             amount: 500,
1045             currency: TEST_CURRENCY,
1046             coupon: '',
1047             flow: flow,
1048             selectedPlanName: undefined,
1049             billingPlatform: BillingPlatform.Proton,
1050             chargebeeUserExists: chargebeeUserExists,
1051             disableNewPaymentMethods: false,
1052             billingAddress: undefinedBillingAddress,
1053             enableSepa: enableSepaTrue,
1054         });
1056         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1057     });
1059     it('should return true for splitted users', () => {
1060         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === true
1061         const flow: PaymentMethodFlows = 'credit';
1063         const chargebeeUserExists = 1;
1065         const methods = new PaymentMethods({
1066             paymentMethodStatus: status,
1067             paymentMethods: [],
1068             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1069             amount: 500,
1070             currency: TEST_CURRENCY,
1071             coupon: '',
1072             flow: flow,
1073             selectedPlanName: undefined,
1074             billingPlatform: BillingPlatform.Proton,
1075             chargebeeUserExists: chargebeeUserExists,
1076             disableNewPaymentMethods: false,
1077             billingAddress: undefinedBillingAddress,
1078             enableSepa: enableSepaTrue,
1079         });
1081         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1082     });
1084     it('should disable bitcoin if user buys Pass Lifetime and has positive credit balance', () => {
1085         const flow: PaymentMethodFlows = 'subscription';
1087         const methods = new PaymentMethods({
1088             paymentMethodStatus: status,
1089             paymentMethods: [],
1090             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1091             amount: 500,
1092             currency: TEST_CURRENCY,
1093             coupon: '',
1094             flow: flow,
1095             selectedPlanName: undefined,
1096             billingPlatform: undefined,
1097             chargebeeUserExists: undefined,
1098             disableNewPaymentMethods: false,
1099             billingAddress: undefinedBillingAddress,
1100             enableSepa: enableSepaTrue,
1101             user: buildUser({
1102                 Credit: 100,
1103             }),
1104             planIDs: {
1105                 [PLANS.PASS_LIFETIME]: 1,
1106             },
1107         });
1109         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1110     });
1112     it('should allow using bitcoin if user buys Pass Lifetime and has no credit balance', () => {
1113         const flow: PaymentMethodFlows = 'subscription';
1115         const methods = new PaymentMethods({
1116             paymentMethodStatus: status,
1117             paymentMethods: [],
1118             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1119             amount: 500,
1120             currency: TEST_CURRENCY,
1121             coupon: '',
1122             flow: flow,
1123             selectedPlanName: undefined,
1124             billingPlatform: undefined,
1125             chargebeeUserExists: undefined,
1126             disableNewPaymentMethods: false,
1127             billingAddress: undefinedBillingAddress,
1128             enableSepa: enableSepaTrue,
1129             user: buildUser(),
1130             planIDs: {
1131                 [PLANS.PASS_LIFETIME]: 1,
1132             },
1133         });
1135         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1136     });
1138     it('should disable bitcoin if user buys pass lifetime in one currency but subscription has another currency', () => {
1139         const flow: PaymentMethodFlows = 'subscription';
1141         const methods = new PaymentMethods({
1142             paymentMethodStatus: status,
1143             paymentMethods: [],
1144             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1145             amount: 500,
1146             currency: 'EUR',
1147             coupon: '',
1148             flow: flow,
1149             selectedPlanName: undefined,
1150             billingPlatform: undefined,
1151             chargebeeUserExists: undefined,
1152             disableNewPaymentMethods: false,
1153             billingAddress: undefinedBillingAddress,
1154             enableSepa: enableSepaTrue,
1155             user: buildUser(),
1156             planIDs: {
1157                 [PLANS.PASS_LIFETIME]: 1,
1158             },
1159             subscription: buildSubscription({
1160                 Currency: 'USD',
1161             }),
1162         });
1164         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1165     });
1167     it('should allow using bitcoin if user buys pass lifetime in one currency and subscription has the same currency', () => {
1168         const flow: PaymentMethodFlows = 'subscription';
1170         const methods = new PaymentMethods({
1171             paymentMethodStatus: status,
1172             paymentMethods: [],
1173             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1174             amount: 500,
1175             currency: TEST_CURRENCY,
1176             coupon: '',
1177             flow: flow,
1178             selectedPlanName: undefined,
1179             billingPlatform: undefined,
1180             chargebeeUserExists: undefined,
1181             disableNewPaymentMethods: false,
1182             billingAddress: undefinedBillingAddress,
1183             enableSepa: enableSepaTrue,
1184             user: buildUser(),
1185             planIDs: {
1186                 [PLANS.PASS_LIFETIME]: 1,
1187             },
1188             subscription: buildSubscription({
1189                 Currency: TEST_CURRENCY,
1190             }),
1191         });
1193         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1194     });
1196     it('should allow bitcoin if user has free subscription and buys pass lifetime', () => {
1197         const flow: PaymentMethodFlows = 'subscription';
1199         const methods = new PaymentMethods({
1200             paymentMethodStatus: status,
1201             paymentMethods: [],
1202             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1203             amount: 500,
1204             currency: TEST_CURRENCY,
1205             coupon: '',
1206             flow: flow,
1207             selectedPlanName: undefined,
1208             billingPlatform: undefined,
1209             chargebeeUserExists: undefined,
1210             disableNewPaymentMethods: false,
1211             billingAddress: undefinedBillingAddress,
1212             enableSepa: enableSepaTrue,
1213             user: buildUser(),
1214             planIDs: {
1215                 [PLANS.PASS_LIFETIME]: 1,
1216             },
1217             subscription: FREE_SUBSCRIPTION,
1218         });
1220         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1221     });
1223     it('should allow bitcoin if user has free subscription and buys regular plan', () => {
1224         const flow: PaymentMethodFlows = 'subscription';
1226         const methods = new PaymentMethods({
1227             paymentMethodStatus: status,
1228             paymentMethods: [],
1229             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1230             amount: 500,
1231             currency: TEST_CURRENCY,
1232             coupon: '',
1233             flow: flow,
1234             selectedPlanName: undefined,
1235             billingPlatform: undefined,
1236             chargebeeUserExists: undefined,
1237             disableNewPaymentMethods: false,
1238             billingAddress: undefinedBillingAddress,
1239             enableSepa: enableSepaTrue,
1240             user: buildUser(),
1241             planIDs: {
1242                 [PLANS.MAIL]: 1,
1243             },
1244             subscription: FREE_SUBSCRIPTION,
1245         });
1247         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1248     });
1250     it('should not display bitcoin if user has unpaid invoices', () => {
1251         const user = buildUser({
1252             Delinquent: UNPAID_STATE.AVAILABLE,
1253         });
1255         const methods = new PaymentMethods({
1256             paymentMethodStatus: status,
1257             paymentMethods: [],
1258             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1259             amount: 500,
1260             currency: TEST_CURRENCY,
1261             coupon: '',
1262             flow: 'subscription',
1263             user,
1264             selectedPlanName: undefined,
1265             billingPlatform: undefined,
1266             chargebeeUserExists: undefined,
1267             disableNewPaymentMethods: false,
1268             billingAddress: undefinedBillingAddress,
1269             enableSepa: enableSepaTrue,
1270         });
1272         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1273     });
1275     it('should display bitcoin if user is not delinquent', () => {
1276         const user = buildUser({
1277             Delinquent: UNPAID_STATE.NOT_UNPAID,
1278         });
1280         const methods = new PaymentMethods({
1281             paymentMethodStatus: status,
1282             paymentMethods: [],
1283             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1284             amount: 500,
1285             currency: TEST_CURRENCY,
1286             coupon: '',
1287             flow: 'subscription',
1288             user,
1289             selectedPlanName: undefined,
1290             billingPlatform: undefined,
1291             chargebeeUserExists: undefined,
1292             disableNewPaymentMethods: false,
1293             billingAddress: undefinedBillingAddress,
1294             enableSepa: enableSepaTrue,
1295         });
1297         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1298     });
1301 describe('Bitcoin', () => {
1302     it('should NOT be present when chargebee-bitcoin is available', () => {
1303         const methods = new PaymentMethods({
1304             paymentMethodStatus: status,
1305             paymentMethods: [],
1306             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1307             amount: 500,
1308             currency: TEST_CURRENCY,
1309             coupon: '',
1310             flow: 'subscription',
1311             selectedPlanName: undefined,
1312             billingPlatform: undefined,
1313             chargebeeUserExists: undefined,
1314             disableNewPaymentMethods: false,
1315             billingAddress: undefinedBillingAddress,
1316             enableSepa: enableSepaTrue,
1317         });
1319         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1320         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1321     });
1323     it('should be available when INHOUSE_FORCED', () => {
1324         const methods = new PaymentMethods({
1325             paymentMethodStatus: status,
1326             paymentMethods: [],
1327             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1328             amount: 500,
1329             currency: TEST_CURRENCY,
1330             coupon: '',
1331             flow: 'subscription',
1332             selectedPlanName: undefined,
1333             billingPlatform: undefined,
1334             chargebeeUserExists: undefined,
1335             disableNewPaymentMethods: false,
1336             billingAddress: undefinedBillingAddress,
1337             enableSepa: enableSepaTrue,
1338         });
1340         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1341     });
1343     it('should return true in the migration condition', () => {
1344         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === false
1346         const flow: PaymentMethodFlows = 'credit';
1348         const chargebeeUserExists = 0;
1350         const methods = new PaymentMethods({
1351             paymentMethodStatus: status,
1352             paymentMethods: [],
1353             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1354             amount: 500,
1355             currency: TEST_CURRENCY,
1356             coupon: '',
1357             flow: flow,
1358             selectedPlanName: undefined,
1359             billingPlatform: BillingPlatform.Proton,
1360             chargebeeUserExists: chargebeeUserExists,
1361             disableNewPaymentMethods: false,
1362             billingAddress: undefinedBillingAddress,
1363             enableSepa: enableSepaTrue,
1364         });
1366         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1367     });
1369     it('should not display bitcoin if status is false', () => {
1370         const st = { ...status, Bitcoin: false };
1371         const flow: PaymentMethodFlows = 'subscription';
1373         const methods = new PaymentMethods({
1374             paymentMethodStatus: st,
1375             paymentMethods: [],
1376             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1377             amount: 500,
1378             currency: TEST_CURRENCY,
1379             coupon: '',
1380             flow: flow,
1381             selectedPlanName: undefined,
1382             billingPlatform: undefined,
1383             chargebeeUserExists: undefined,
1384             disableNewPaymentMethods: false,
1385             billingAddress: undefinedBillingAddress,
1386             enableSepa: enableSepaTrue,
1387         });
1389         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1390     });
1392     it.each([
1393         'invoice',
1394         'signup',
1395         'signup-v2',
1396         'signup-v2-upgrade',
1397         'signup-vpn',
1398         'add-card',
1399         'add-paypal',
1400     ] as PaymentMethodFlows[])('should not display bitcoin in %s flow', (flow) => {
1401         const methods = new PaymentMethods({
1402             paymentMethodStatus: status,
1403             paymentMethods: [],
1404             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1405             amount: 500,
1406             currency: TEST_CURRENCY,
1407             coupon: '',
1408             flow: flow,
1409             selectedPlanName: undefined,
1410             billingPlatform: undefined,
1411             chargebeeUserExists: undefined,
1412             disableNewPaymentMethods: false,
1413             billingAddress: undefinedBillingAddress,
1414             enableSepa: enableSepaTrue,
1415         });
1417         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1418     });
1420     it('should not display bitcoin if amount is less than minimum', () => {
1421         const flow: PaymentMethodFlows = 'subscription';
1423         const methods = new PaymentMethods({
1424             paymentMethodStatus: status,
1425             paymentMethods: [],
1426             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1427             amount: MIN_BITCOIN_AMOUNT - 1,
1428             currency: TEST_CURRENCY,
1429             coupon: '',
1430             flow: flow,
1431             selectedPlanName: undefined,
1432             billingPlatform: undefined,
1433             chargebeeUserExists: undefined,
1434             disableNewPaymentMethods: false,
1435             billingAddress: undefinedBillingAddress,
1436             enableSepa: enableSepaTrue,
1437         });
1439         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1440     });
1442     it.each([PLANS.MAIL_PRO, PLANS.DRIVE_PRO, PLANS.BUNDLE_PRO, PLANS.BUNDLE_PRO_2024])(
1443         'should not display bitcoin for b2b plans',
1444         (plan) => {
1445             const flow: PaymentMethodFlows = 'subscription';
1447             const methods = new PaymentMethods({
1448                 paymentMethodStatus: status,
1449                 paymentMethods: [],
1450                 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1451                 amount: 500,
1452                 currency: TEST_CURRENCY,
1453                 coupon: '',
1454                 flow: flow,
1455                 selectedPlanName: plan,
1456                 billingPlatform: undefined,
1457                 chargebeeUserExists: undefined,
1458                 disableNewPaymentMethods: false,
1459                 billingAddress: undefinedBillingAddress,
1460                 enableSepa: enableSepaTrue,
1461             });
1463             expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1464         }
1465     );
1467     it('should not display bitcoin if user has unpaid invoices', () => {
1468         const user = buildUser({
1469             Delinquent: UNPAID_STATE.AVAILABLE,
1470         });
1472         const methods = new PaymentMethods({
1473             paymentMethodStatus: status,
1474             paymentMethods: [],
1475             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1476             amount: 500,
1477             currency: TEST_CURRENCY,
1478             coupon: '',
1479             flow: 'subscription',
1480             user,
1481             selectedPlanName: undefined,
1482             billingPlatform: undefined,
1483             chargebeeUserExists: undefined,
1484             disableNewPaymentMethods: false,
1485             billingAddress: undefinedBillingAddress,
1486             enableSepa: enableSepaTrue,
1487         });
1489         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1490     });
1492     it('should display bitcoin if user is not delinquent', () => {
1493         const user = buildUser({
1494             Delinquent: UNPAID_STATE.NOT_UNPAID,
1495         });
1497         const methods = new PaymentMethods({
1498             paymentMethodStatus: status,
1499             paymentMethods: [],
1500             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1501             amount: 500,
1502             currency: TEST_CURRENCY,
1503             coupon: '',
1504             flow: 'subscription',
1505             user,
1506             selectedPlanName: undefined,
1507             billingPlatform: undefined,
1508             chargebeeUserExists: undefined,
1509             disableNewPaymentMethods: false,
1510             billingAddress: undefinedBillingAddress,
1511             enableSepa: enableSepaTrue,
1512         });
1514         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1515     });
1517     it('should not display bitcoin if user has unpaid invoices', () => {
1518         const user = buildUser({
1519             Delinquent: UNPAID_STATE.AVAILABLE,
1520         });
1522         const methods = new PaymentMethods({
1523             paymentMethodStatus: status,
1524             paymentMethods: [],
1525             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1526             amount: 500,
1527             currency: TEST_CURRENCY,
1528             coupon: '',
1529             flow: 'subscription',
1530             user,
1531             selectedPlanName: undefined,
1532             billingPlatform: undefined,
1533             chargebeeUserExists: undefined,
1534             disableNewPaymentMethods: false,
1535             billingAddress: undefinedBillingAddress,
1536             enableSepa: enableSepaTrue,
1537         });
1539         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1540     });
1542     it('should display bitcoin if user is not delinquent', () => {
1543         const user = buildUser({
1544             Delinquent: UNPAID_STATE.NOT_UNPAID,
1545         });
1547         const methods = new PaymentMethods({
1548             paymentMethodStatus: status,
1549             paymentMethods: [],
1550             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1551             amount: 500,
1552             currency: TEST_CURRENCY,
1553             coupon: '',
1554             flow: 'subscription',
1555             user,
1556             selectedPlanName: undefined,
1557             billingPlatform: undefined,
1558             chargebeeUserExists: undefined,
1559             disableNewPaymentMethods: false,
1560             billingAddress: undefinedBillingAddress,
1561             enableSepa: enableSepaTrue,
1562         });
1564         expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1565     });
1568 describe('Chargebee card', () => {
1569     it('should display chargebee card', () => {
1570         const flow: PaymentMethodFlows = 'subscription';
1572         const methods = new PaymentMethods({
1573             paymentMethodStatus: status,
1574             paymentMethods: [],
1575             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1576             amount: 500,
1577             currency: TEST_CURRENCY,
1578             coupon: '',
1579             flow: flow,
1580             selectedPlanName: undefined,
1581             billingPlatform: undefined,
1582             chargebeeUserExists: undefined,
1583             disableNewPaymentMethods: false,
1584             billingAddress: undefinedBillingAddress,
1585             enableSepa: enableSepaTrue,
1586         });
1588         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1589     });
1591     it('should disable CB card if INHOUSE_FORCED', () => {
1592         const flow: PaymentMethodFlows = 'subscription';
1594         const methods = new PaymentMethods({
1595             paymentMethodStatus: status,
1596             paymentMethods: [],
1597             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1598             amount: 500,
1599             currency: TEST_CURRENCY,
1600             coupon: '',
1601             flow: flow,
1602             selectedPlanName: undefined,
1603             billingPlatform: undefined,
1604             chargebeeUserExists: undefined,
1605             disableNewPaymentMethods: false,
1606             billingAddress: undefinedBillingAddress,
1607             enableSepa: enableSepaTrue,
1608         });
1610         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
1611         expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
1612     });
1614     it.each(['credit', 'add-card'])('should disable CB card for on-session migration users', (flow) => {
1615         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === false
1617         const chargebeeUserExists = 0;
1619         const methods = new PaymentMethods({
1620             paymentMethodStatus: status,
1621             paymentMethods: [],
1622             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1623             amount: 500,
1624             currency: TEST_CURRENCY,
1625             coupon: '',
1626             flow: flow as PaymentMethodFlows,
1627             selectedPlanName: undefined,
1628             billingPlatform: BillingPlatform.Proton,
1629             chargebeeUserExists: chargebeeUserExists,
1630             disableNewPaymentMethods: false,
1631             billingAddress: undefinedBillingAddress,
1632             enableSepa: enableSepaTrue,
1633         });
1635         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
1636         expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
1637     });
1639     it.each(['credit', 'add-card'])('should enable CB card for splitted users', (flow) => {
1640         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === true
1642         const chargebeeUserExists = 1;
1644         const methods = new PaymentMethods({
1645             paymentMethodStatus: status,
1646             paymentMethods: [],
1647             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1648             amount: 500,
1649             currency: TEST_CURRENCY,
1650             coupon: '',
1651             flow: flow as PaymentMethodFlows,
1652             selectedPlanName: undefined,
1653             billingPlatform: BillingPlatform.Proton,
1654             chargebeeUserExists: chargebeeUserExists,
1655             disableNewPaymentMethods: false,
1656             billingAddress: undefinedBillingAddress,
1657             enableSepa: enableSepaTrue,
1658         });
1660         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1661         expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(false);
1662     });
1664     it('should not display chargebee card if status is false', () => {
1665         const st = { ...status, Card: false };
1666         const flow: PaymentMethodFlows = 'subscription';
1668         const methods = new PaymentMethods({
1669             paymentMethodStatus: st,
1670             paymentMethods: [],
1671             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1672             amount: 500,
1673             currency: TEST_CURRENCY,
1674             coupon: '',
1675             flow: flow,
1676             selectedPlanName: undefined,
1677             billingPlatform: undefined,
1678             chargebeeUserExists: undefined,
1679             disableNewPaymentMethods: false,
1680             billingAddress: undefinedBillingAddress,
1681             enableSepa: enableSepaTrue,
1682         });
1684         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
1685     });
1687     it('should display the chargebee card if CHARGEBEE_FORCED even if flow is not supported', () => {
1688         const flow: PaymentMethodFlows = 'invoice';
1690         const methods = new PaymentMethods({
1691             paymentMethodStatus: status,
1692             paymentMethods: [],
1693             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1694             amount: 500,
1695             currency: TEST_CURRENCY,
1696             coupon: '',
1697             flow: flow,
1698             selectedPlanName: undefined,
1699             billingPlatform: undefined,
1700             chargebeeUserExists: undefined,
1701             disableNewPaymentMethods: false,
1702             billingAddress: undefinedBillingAddress,
1703             enableSepa: enableSepaTrue,
1704         });
1706         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1707     });
1709     it('should display the chargebee card if CHARGEBEE_FORCED even if disabled for B2B', () => {
1710         const flow: PaymentMethodFlows = 'subscription';
1712         const methods = new PaymentMethods({
1713             paymentMethodStatus: status,
1714             paymentMethods: [],
1715             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1716             amount: 500,
1717             currency: TEST_CURRENCY,
1718             coupon: '',
1719             flow: flow,
1720             selectedPlanName: undefined,
1721             billingPlatform: undefined,
1722             chargebeeUserExists: undefined,
1723             disableNewPaymentMethods: false,
1724             billingAddress: undefinedBillingAddress,
1725             enableSepa: enableSepaTrue,
1726         });
1728         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1729     });
1732 describe('Chargebee PayPal', () => {
1733     it('should display chargebee paypal', () => {
1734         const flow: PaymentMethodFlows = 'subscription';
1736         const methods = new PaymentMethods({
1737             paymentMethodStatus: status,
1738             paymentMethods: [],
1739             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1740             amount: 500,
1741             currency: TEST_CURRENCY,
1742             coupon: '',
1743             flow: flow,
1744             selectedPlanName: undefined,
1745             billingPlatform: undefined,
1746             chargebeeUserExists: undefined,
1747             disableNewPaymentMethods: false,
1748             billingAddress: undefinedBillingAddress,
1749             enableSepa: enableSepaTrue,
1750         });
1752         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
1753     });
1755     it('should disable CB paypal if INHOUSE_FORCED', () => {
1756         const flow: PaymentMethodFlows = 'subscription';
1758         const methods = new PaymentMethods({
1759             paymentMethodStatus: status,
1760             paymentMethods: [],
1761             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1762             amount: 500,
1763             currency: TEST_CURRENCY,
1764             coupon: '',
1765             flow: flow,
1766             selectedPlanName: undefined,
1767             billingPlatform: undefined,
1768             chargebeeUserExists: undefined,
1769             disableNewPaymentMethods: false,
1770             billingAddress: undefinedBillingAddress,
1771             enableSepa: enableSepaTrue,
1772         });
1774         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1775         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
1776     });
1778     it('should disable CB paypal for on-session migration users', () => {
1779         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === false
1781         const flow = 'credit';
1783         const chargebeeUserExists = 0;
1785         const methods = new PaymentMethods({
1786             paymentMethodStatus: status,
1787             paymentMethods: [],
1788             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1789             amount: 500,
1790             currency: TEST_CURRENCY,
1791             coupon: '',
1792             flow: flow as PaymentMethodFlows,
1793             selectedPlanName: undefined,
1794             billingPlatform: BillingPlatform.Proton,
1795             chargebeeUserExists: chargebeeUserExists,
1796             disableNewPaymentMethods: false,
1797             billingAddress: undefinedBillingAddress,
1798             enableSepa: enableSepaTrue,
1799         });
1801         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1802         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
1803     });
1805     it.each(['credit', 'add-paypal'])('should enable CB paypal for splitted users', (flow) => {
1806         // chargebeeEnabled === CHARGEBEE_FORCED, BillingPlatform.Proton, chargebeeUserExists === true
1808         const chargebeeUserExists = 1;
1810         const methods = new PaymentMethods({
1811             paymentMethodStatus: status,
1812             paymentMethods: [],
1813             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1814             amount: 500,
1815             currency: TEST_CURRENCY,
1816             coupon: '',
1817             flow: flow as PaymentMethodFlows,
1818             selectedPlanName: undefined,
1819             billingPlatform: BillingPlatform.Proton,
1820             chargebeeUserExists: chargebeeUserExists,
1821             disableNewPaymentMethods: false,
1822             billingAddress: undefinedBillingAddress,
1823             enableSepa: enableSepaTrue,
1824         });
1826         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
1827         expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
1828     });
1830     it('should not render paypal if there is already one saved', () => {
1831         const flow: PaymentMethodFlows = 'subscription';
1833         const methods = new PaymentMethods({
1834             paymentMethodStatus: status,
1835             paymentMethods: [
1836                 {
1837                     ID: '123',
1838                     Type: PAYMENT_METHOD_TYPES.PAYPAL,
1839                     Order: 500,
1840                     Details: {
1841                         BillingAgreementID: 'BA-123',
1842                         PayerID: '123',
1843                         Payer: '123',
1844                     },
1845                 },
1846             ],
1847             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1848             amount: 500,
1849             currency: TEST_CURRENCY,
1850             coupon: '',
1851             flow: flow,
1852             selectedPlanName: undefined,
1853             billingPlatform: BillingPlatform.Chargebee,
1854             chargebeeUserExists: 1,
1855             disableNewPaymentMethods: false,
1856             billingAddress: undefinedBillingAddress,
1857             enableSepa: enableSepaTrue,
1858         });
1860         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1861     });
1863     it('should disable paypal if the amount is too low', () => {
1864         const flow: PaymentMethodFlows = 'subscription';
1866         const methods = new PaymentMethods({
1867             paymentMethodStatus: status,
1868             paymentMethods: [],
1869             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1870             amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1871             currency: TEST_CURRENCY,
1872             coupon: '',
1873             flow: flow,
1874             selectedPlanName: undefined,
1875             billingPlatform: undefined,
1876             chargebeeUserExists: undefined,
1877             disableNewPaymentMethods: false,
1878             billingAddress: undefinedBillingAddress,
1879             enableSepa: enableSepaTrue,
1880         });
1882         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1883     });
1885     it('should enable paypal for unpaid invoice even if the amount is too low', () => {
1886         const flow: PaymentMethodFlows = 'invoice';
1888         const methods = new PaymentMethods({
1889             paymentMethodStatus: status,
1890             paymentMethods: [],
1891             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1892             amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1893             currency: TEST_CURRENCY,
1894             coupon: '',
1895             flow: flow,
1896             selectedPlanName: undefined,
1897             billingPlatform: undefined,
1898             chargebeeUserExists: undefined,
1899             disableNewPaymentMethods: false,
1900             billingAddress: undefinedBillingAddress,
1901             enableSepa: enableSepaTrue,
1902         });
1904         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
1905     });
1907     it('should disable paypal if status is false', () => {
1908         const st = { ...status, Paypal: false };
1909         const flow: PaymentMethodFlows = 'subscription';
1911         const methods = new PaymentMethods({
1912             paymentMethodStatus: st,
1913             paymentMethods: [],
1914             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1915             amount: 500,
1916             currency: TEST_CURRENCY,
1917             coupon: '',
1918             flow: flow,
1919             selectedPlanName: undefined,
1920             billingPlatform: undefined,
1921             chargebeeUserExists: undefined,
1922             disableNewPaymentMethods: false,
1923             billingAddress: undefinedBillingAddress,
1924             enableSepa: enableSepaTrue,
1925         });
1927         expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1928     });
1931 it('should not have new payment methods if they are disabled', () => {
1932     const flow: PaymentMethodFlows = 'invoice';
1934     const disableNewPaymentMethods = true;
1936     const methods = new PaymentMethods({
1937         paymentMethodStatus: status,
1938         paymentMethods: [],
1939         chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1940         amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1941         currency: TEST_CURRENCY,
1942         coupon: '',
1943         flow: flow,
1944         selectedPlanName: undefined,
1945         billingPlatform: undefined,
1946         chargebeeUserExists: undefined,
1947         disableNewPaymentMethods: disableNewPaymentMethods,
1948         billingAddress: undefinedBillingAddress,
1949         enableSepa: enableSepaTrue,
1950     });
1952     expect(methods.getNewMethods().length).toBe(0);
1955 describe('SEPA', () => {
1956     it('should not display SEPA for inhouse forced users', () => {
1957         const flow: PaymentMethodFlows = 'subscription';
1959         const methods = new PaymentMethods({
1960             paymentMethodStatus: status,
1961             paymentMethods: [],
1962             chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1963             amount: 500,
1964             currency: TEST_CURRENCY,
1965             coupon: '',
1966             flow: flow,
1967             selectedPlanName: undefined,
1968             billingPlatform: undefined,
1969             chargebeeUserExists: undefined,
1970             disableNewPaymentMethods: false,
1971             billingAddress: { CountryCode: 'CH' },
1972             enableSepa: enableSepaTrue,
1973         });
1975         expect(
1976             methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
1977         ).toBe(false);
1978     });
1980     it('should display SEPA', () => {
1981         const flow: PaymentMethodFlows = 'subscription';
1983         const methods = new PaymentMethods({
1984             paymentMethodStatus: status,
1985             paymentMethods: [],
1986             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1987             amount: 500,
1988             currency: TEST_CURRENCY,
1989             coupon: '',
1990             flow: flow,
1991             selectedPlanName: undefined,
1992             billingPlatform: undefined,
1993             chargebeeUserExists: undefined,
1994             disableNewPaymentMethods: false,
1995             billingAddress: { CountryCode: 'CH' },
1996             enableSepa: enableSepaTrue,
1997         });
1999         expect(
2000             methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
2001         ).toBe(true);
2002     });
2004     it.each([
2005         'signup-pass',
2006         'signup',
2007         'signup-v2',
2008         'signup-pass-upgrade',
2009         'signup-v2-upgrade',
2010         'signup-vpn',
2011     ] as PaymentMethodFlows[])('should not offer SEPA for %s flow', (flow) => {
2012         const methods = new PaymentMethods({
2013             paymentMethodStatus: status,
2014             paymentMethods: [],
2015             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2016             amount: 500,
2017             currency: TEST_CURRENCY,
2018             coupon: '',
2019             flow: flow,
2020             selectedPlanName: undefined,
2021             billingPlatform: undefined,
2022             chargebeeUserExists: undefined,
2023             disableNewPaymentMethods: false,
2024             billingAddress: { CountryCode: 'CH' },
2025             enableSepa: enableSepaTrue,
2026         });
2028         expect(
2029             methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
2030         ).toBe(false);
2031     });
2033     it('should not offer SEPA if the country is not supported', () => {
2034         const flow: PaymentMethodFlows = 'subscription';
2036         const methods = new PaymentMethods({
2037             paymentMethodStatus: status,
2038             paymentMethods: [],
2039             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2040             amount: 500,
2041             currency: TEST_CURRENCY,
2042             coupon: '',
2043             flow: flow,
2044             selectedPlanName: undefined,
2045             billingPlatform: undefined,
2046             chargebeeUserExists: undefined,
2047             disableNewPaymentMethods: false,
2048             billingAddress: { CountryCode: 'US' },
2049             enableSepa: enableSepaTrue,
2050         });
2052         expect(
2053             methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
2054         ).toBe(false);
2055     });
2057     it('should not display SEPA if feature is disabled', () => {
2058         const flow: PaymentMethodFlows = 'subscription';
2060         const enableSepaFalse = false;
2062         const methods = new PaymentMethods({
2063             paymentMethodStatus: status,
2064             paymentMethods: [],
2065             chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2066             amount: 500,
2067             currency: TEST_CURRENCY,
2068             coupon: '',
2069             flow: flow,
2070             selectedPlanName: undefined,
2071             billingPlatform: undefined,
2072             chargebeeUserExists: undefined,
2073             disableNewPaymentMethods: false,
2074             billingAddress: { CountryCode: 'CH' },
2075             enableSepa: enableSepaFalse,
2076         });
2078         expect(
2079             methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
2080         ).toBe(false);
2081     });