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';
8 type PaymentMethodFlows,
9 type PaymentMethodStatus,
11 type SavedPaymentMethod,
13 import { PaymentMethods, initializePaymentMethods } from './methods';
15 const TEST_CURRENCY = 'USD' as const;
17 let status: PaymentMethodStatus;
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,
37 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
39 currency: TEST_CURRENCY,
42 selectedPlanName: undefined,
43 billingPlatform: undefined,
44 chargebeeUserExists: undefined,
45 disableNewPaymentMethods: false,
46 billingAddress: undefinedBillingAddress,
47 enableSepa: enableSepaTrue,
50 expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
53 it('should not include card when card is not available', () => {
56 const methods = new PaymentMethods({
57 paymentMethodStatus: status,
59 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
61 currency: TEST_CURRENCY,
64 selectedPlanName: undefined,
65 billingPlatform: undefined,
66 chargebeeUserExists: undefined,
67 disableNewPaymentMethods: false,
68 billingAddress: undefinedBillingAddress,
69 enableSepa: enableSepaTrue,
72 expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(false);
76 it('should include PayPal when PayPal is available', () => {
77 const methods = new PaymentMethods({
78 paymentMethodStatus: status,
80 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
82 currency: TEST_CURRENCY,
85 selectedPlanName: undefined,
86 billingPlatform: undefined,
87 chargebeeUserExists: undefined,
88 disableNewPaymentMethods: false,
89 billingAddress: undefinedBillingAddress,
90 enableSepa: enableSepaTrue,
93 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
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,
100 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
102 currency: TEST_CURRENCY,
104 flow: 'subscription',
105 selectedPlanName: undefined,
106 billingPlatform: undefined,
107 chargebeeUserExists: undefined,
108 disableNewPaymentMethods: false,
109 billingAddress: undefinedBillingAddress,
110 enableSepa: enableSepaTrue,
113 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
116 it('should not include PayPal when already used as payment method', () => {
117 const methods = new PaymentMethods({
118 paymentMethodStatus: status,
122 Type: PAYMENT_METHOD_TYPES.PAYPAL,
125 BillingAgreementID: 'BA-123',
129 External: MethodStorage.INTERNAL,
132 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
134 currency: TEST_CURRENCY,
136 flow: 'subscription',
137 selectedPlanName: undefined,
138 billingPlatform: undefined,
139 chargebeeUserExists: undefined,
140 disableNewPaymentMethods: false,
141 billingAddress: undefinedBillingAddress,
142 enableSepa: enableSepaTrue,
145 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
148 it('should include Bitcoin when Bitcoin is available', () => {
149 const methods = new PaymentMethods({
150 paymentMethodStatus: status,
152 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
154 currency: TEST_CURRENCY,
156 flow: 'subscription',
157 selectedPlanName: undefined,
158 billingPlatform: undefined,
159 chargebeeUserExists: undefined,
160 disableNewPaymentMethods: false,
161 billingAddress: undefinedBillingAddress,
162 enableSepa: enableSepaTrue,
165 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
168 it.each(['signup'] as PaymentMethodFlows[])(
169 'should not include Bitcoin when Bitcoin is not available due to flow %s',
171 const methods = new PaymentMethods({
172 paymentMethodStatus: status,
174 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
176 currency: TEST_CURRENCY,
179 selectedPlanName: undefined,
180 billingPlatform: undefined,
181 chargebeeUserExists: undefined,
182 disableNewPaymentMethods: false,
183 billingAddress: undefinedBillingAddress,
184 enableSepa: enableSepaTrue,
187 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
191 it('should not include bitcoin due to amount less than minimum', () => {
192 const methods = new PaymentMethods({
193 paymentMethodStatus: status,
195 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
197 currency: TEST_CURRENCY,
199 flow: 'subscription',
200 selectedPlanName: undefined,
201 billingPlatform: undefined,
202 chargebeeUserExists: undefined,
203 disableNewPaymentMethods: false,
204 billingAddress: undefinedBillingAddress,
205 enableSepa: enableSepaTrue,
208 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
211 it('should include Cash when Cash is available', () => {
212 const methods = new PaymentMethods({
213 paymentMethodStatus: status,
215 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
217 currency: TEST_CURRENCY,
219 flow: 'subscription',
220 selectedPlanName: undefined,
221 billingPlatform: undefined,
222 chargebeeUserExists: undefined,
223 disableNewPaymentMethods: false,
224 billingAddress: undefinedBillingAddress,
225 enableSepa: enableSepaTrue,
228 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
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',
234 const methods = new PaymentMethods({
235 paymentMethodStatus: status,
237 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
239 currency: TEST_CURRENCY,
242 selectedPlanName: undefined,
243 billingPlatform: undefined,
244 chargebeeUserExists: undefined,
245 disableNewPaymentMethods: false,
246 billingAddress: undefinedBillingAddress,
247 enableSepa: enableSepaTrue,
250 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
254 it('should return chargebee methods when they are enabled', () => {
255 const methods = new PaymentMethods({
256 paymentMethodStatus: status,
258 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
260 currency: TEST_CURRENCY,
262 flow: 'subscription',
263 selectedPlanName: undefined,
264 billingPlatform: undefined,
265 chargebeeUserExists: undefined,
266 disableNewPaymentMethods: false,
267 billingAddress: undefinedBillingAddress,
268 enableSepa: enableSepaTrue,
271 expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_CARD)).toBe(
274 expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_PAYPAL)).toBe(
279 it('should not return chargebee methods when they are disabled', () => {
280 const methods = new PaymentMethods({
281 paymentMethodStatus: status,
283 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
285 currency: TEST_CURRENCY,
287 flow: 'subscription',
288 selectedPlanName: undefined,
289 billingPlatform: undefined,
290 chargebeeUserExists: undefined,
291 disableNewPaymentMethods: false,
292 billingAddress: undefinedBillingAddress,
293 enableSepa: enableSepaTrue,
296 expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_CARD)).toBe(
299 expect(methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_PAYPAL)).toBe(
305 describe('getUsedMethods()', () => {
306 it('should return used methods: paypal and cards', () => {
307 const methods = new PaymentMethods({
308 paymentMethodStatus: status,
312 Type: PAYMENT_METHOD_TYPES.PAYPAL,
315 BillingAgreementID: 'BA-123',
319 External: MethodStorage.INTERNAL,
323 Type: PAYMENT_METHOD_TYPES.CARD,
325 Autopay: Autopay.ENABLE,
327 Name: 'Arthur Morgan',
335 External: MethodStorage.INTERNAL,
340 Type: PAYMENT_METHOD_TYPES.CARD,
342 Autopay: Autopay.ENABLE,
344 Name: 'Arthur Morgan',
352 External: MethodStorage.INTERNAL,
355 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
357 currency: TEST_CURRENCY,
359 flow: 'subscription',
360 selectedPlanName: undefined,
361 billingPlatform: undefined,
362 chargebeeUserExists: undefined,
363 disableNewPaymentMethods: false,
364 billingAddress: undefinedBillingAddress,
365 enableSepa: enableSepaTrue,
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);
376 describe('getAvailablePaymentMethods()', () => {
377 it('should return combination of new and used methods', () => {
378 const methods = new PaymentMethods({
379 paymentMethodStatus: status,
383 Type: PAYMENT_METHOD_TYPES.PAYPAL,
386 BillingAgreementID: 'BA-123',
390 External: MethodStorage.INTERNAL,
394 Type: PAYMENT_METHOD_TYPES.CARD,
396 Autopay: Autopay.ENABLE,
398 Name: 'Arthur Morgan',
406 External: MethodStorage.INTERNAL,
411 Type: PAYMENT_METHOD_TYPES.CARD,
413 Autopay: Autopay.ENABLE,
415 Name: 'Arthur Morgan',
423 External: MethodStorage.INTERNAL,
426 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
428 currency: TEST_CURRENCY,
430 flow: 'subscription',
431 selectedPlanName: undefined,
432 billingPlatform: undefined,
433 chargebeeUserExists: undefined,
434 disableNewPaymentMethods: false,
435 billingAddress: undefinedBillingAddress,
436 enableSepa: enableSepaTrue,
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);
453 describe('getLastUsedMethod()', () => {
454 it('should return last used method', () => {
455 const methods = new PaymentMethods({
456 paymentMethodStatus: status,
460 Type: PAYMENT_METHOD_TYPES.PAYPAL,
463 BillingAgreementID: 'BA-123',
467 External: MethodStorage.INTERNAL,
471 Type: PAYMENT_METHOD_TYPES.CARD,
473 Autopay: Autopay.ENABLE,
475 Name: 'Arthur Morgan',
483 External: MethodStorage.INTERNAL,
488 Type: PAYMENT_METHOD_TYPES.CARD,
490 Autopay: Autopay.ENABLE,
492 Name: 'Arthur Morgan',
500 External: MethodStorage.INTERNAL,
503 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
505 currency: TEST_CURRENCY,
507 flow: 'subscription',
508 selectedPlanName: undefined,
509 billingPlatform: undefined,
510 chargebeeUserExists: undefined,
511 disableNewPaymentMethods: false,
512 billingAddress: undefinedBillingAddress,
513 enableSepa: enableSepaTrue,
516 const lastUsedMethod = methods.getLastUsedMethod();
518 expect(lastUsedMethod).toEqual({
519 type: PAYMENT_METHOD_TYPES.PAYPAL,
520 paymentMethodId: '1',
528 describe('getSavedMethodById()', () => {
529 it('should return the correct saved method by id', () => {
530 const methods = new PaymentMethods({
531 paymentMethodStatus: status,
535 Type: PAYMENT_METHOD_TYPES.PAYPAL,
538 BillingAgreementID: 'BA-123',
542 External: MethodStorage.INTERNAL,
546 Type: PAYMENT_METHOD_TYPES.CARD,
548 Autopay: Autopay.ENABLE,
550 Name: 'Arthur Morgan',
558 External: MethodStorage.INTERNAL,
563 Type: PAYMENT_METHOD_TYPES.CARD,
565 Autopay: Autopay.ENABLE,
567 Name: 'Arthur Morgan',
575 External: MethodStorage.INTERNAL,
580 Type: PAYMENT_METHOD_TYPES.CARD,
582 Autopay: Autopay.ENABLE,
584 Name: 'Arthur Morgan',
592 External: MethodStorage.EXTERNAL,
595 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
597 currency: TEST_CURRENCY,
599 flow: 'subscription',
600 selectedPlanName: undefined,
601 billingPlatform: undefined,
602 chargebeeUserExists: undefined,
603 disableNewPaymentMethods: false,
604 billingAddress: undefinedBillingAddress,
605 enableSepa: enableSepaTrue,
608 const savedMethod = methods.getSavedMethodById('2');
610 expect(savedMethod).toEqual({
612 Type: PAYMENT_METHOD_TYPES.CARD,
614 Autopay: Autopay.ENABLE,
616 Name: 'Arthur Morgan',
624 External: MethodStorage.INTERNAL,
627 const externalMethod = methods.getSavedMethodById('4');
629 expect(externalMethod).toEqual({
631 Type: PAYMENT_METHOD_TYPES.CARD,
633 Autopay: Autopay.ENABLE,
635 Name: 'Arthur Morgan',
643 External: MethodStorage.EXTERNAL,
648 describe('initializePaymentMethods()', () => {
649 it('should correctly initialize payment methods', async () => {
650 const apiMock = jest.fn();
651 const paymentMethodStatus: PaymentMethodStatus = {
659 const paymentMethods: SavedPaymentMethod[] = [
662 Type: PAYMENT_METHOD_TYPES.CARD,
664 Autopay: Autopay.ENABLE,
666 Name: 'Arthur Morgan',
674 External: MethodStorage.INTERNAL,
678 apiMock.mockImplementation(({ url }) => {
679 if (url === queryPaymentMethods().url) {
681 PaymentMethods: paymentMethods,
685 if (url === 'payments/v4/status') {
687 VendorStatus: paymentMethodStatus,
690 if (url === 'payments/v5/status') {
692 VendorStatus: paymentMethodStatus,
697 const methods = await initializePaymentMethods({
699 maybePaymentMethodStatus: undefined,
700 maybePaymentMethods: undefined,
701 isAuthenticated: true,
703 currency: TEST_CURRENCY,
705 flow: 'subscription' as PaymentMethodFlows,
706 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
708 statusExtendedAutomatic: () => paymentMethodStatus,
709 } as any as PaymentsApi,
710 selectedPlanName: undefined,
711 billingPlatform: undefined,
712 chargebeeUserExists: undefined,
713 disableNewPaymentMethods: false,
714 billingAddress: undefined,
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);
725 it('should correctly initialize payment methods when user is not authenticated', async () => {
726 const apiMock = jest.fn();
728 const paymentMethodStatus: PaymentMethodStatus = {
736 apiMock.mockImplementation(({ url }) => {
737 if (url === 'payments/v4/status') {
738 return paymentMethodStatus;
740 if (url === 'payments/v5/status') {
741 return paymentMethodStatus;
745 const methods = await initializePaymentMethods({
747 maybePaymentMethodStatus: undefined,
748 maybePaymentMethods: undefined,
749 isAuthenticated: false,
751 currency: TEST_CURRENCY,
753 flow: 'subscription' as PaymentMethodFlows,
754 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
756 statusExtendedAutomatic: () => paymentMethodStatus,
757 } as any as PaymentsApi,
758 selectedPlanName: undefined,
759 billingPlatform: undefined,
760 chargebeeUserExists: undefined,
761 disableNewPaymentMethods: false,
762 billingAddress: undefined,
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);
774 describe('Cash', () => {
775 it('should display cash', () => {
776 const flow: PaymentMethodFlows = 'subscription';
778 const methods = new PaymentMethods({
779 paymentMethodStatus: status,
781 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
783 currency: TEST_CURRENCY,
786 selectedPlanName: undefined,
787 billingPlatform: undefined,
788 chargebeeUserExists: undefined,
789 disableNewPaymentMethods: false,
790 billingAddress: undefinedBillingAddress,
791 enableSepa: enableSepaTrue,
794 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
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,
804 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
806 currency: TEST_CURRENCY,
809 selectedPlanName: undefined,
810 billingPlatform: undefined,
811 chargebeeUserExists: undefined,
812 disableNewPaymentMethods: false,
813 billingAddress: undefinedBillingAddress,
814 enableSepa: enableSepaTrue,
817 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
820 it.each(signupFlows)('should not display cash in signup flows', (flow) => {
821 const methods = new PaymentMethods({
822 paymentMethodStatus: status,
824 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
826 currency: TEST_CURRENCY,
829 selectedPlanName: undefined,
830 billingPlatform: undefined,
831 chargebeeUserExists: undefined,
832 disableNewPaymentMethods: false,
833 billingAddress: undefinedBillingAddress,
834 enableSepa: enableSepaTrue,
837 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
840 it('should not display cash if user buys Pass Lifetime', () => {
841 const flow: PaymentMethodFlows = 'subscription';
843 const methods = new PaymentMethods({
844 paymentMethodStatus: status,
846 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
848 currency: TEST_CURRENCY,
851 selectedPlanName: undefined,
852 billingPlatform: undefined,
853 chargebeeUserExists: undefined,
854 disableNewPaymentMethods: false,
855 billingAddress: undefinedBillingAddress,
856 enableSepa: enableSepaTrue,
858 [PLANS.PASS_LIFETIME]: 1,
862 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(false);
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,
871 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
873 currency: TEST_CURRENCY,
876 selectedPlanName: undefined,
877 billingPlatform: undefined,
878 chargebeeUserExists: undefined,
879 disableNewPaymentMethods: false,
880 billingAddress: undefinedBillingAddress,
881 enableSepa: enableSepaTrue,
883 [PLANS.MAIL]: 1, // Using a different plan
887 expect(methods.getNewMethods().some((method) => method.type === 'cash')).toBe(true);
891 describe('Chargebee Bitcoin', () => {
892 it('should display bitcoin', () => {
893 const flow: PaymentMethodFlows = 'subscription';
895 const methods = new PaymentMethods({
896 paymentMethodStatus: status,
898 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
900 currency: TEST_CURRENCY,
903 selectedPlanName: undefined,
904 billingPlatform: undefined,
905 chargebeeUserExists: undefined,
906 disableNewPaymentMethods: false,
907 billingAddress: undefinedBillingAddress,
908 enableSepa: enableSepaTrue,
911 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
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,
921 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
923 currency: TEST_CURRENCY,
926 selectedPlanName: undefined,
927 billingPlatform: undefined,
928 chargebeeUserExists: undefined,
929 disableNewPaymentMethods: false,
930 billingAddress: undefinedBillingAddress,
931 enableSepa: enableSepaTrue,
934 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
945 ] as PaymentMethodFlows[])('should not display bitcoin in %s flow', (flow) => {
946 const methods = new PaymentMethods({
947 paymentMethodStatus: status,
949 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
951 currency: TEST_CURRENCY,
954 selectedPlanName: undefined,
955 billingPlatform: undefined,
956 chargebeeUserExists: undefined,
957 disableNewPaymentMethods: false,
958 billingAddress: undefinedBillingAddress,
959 enableSepa: enableSepaTrue,
962 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
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,
971 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
972 amount: MIN_BITCOIN_AMOUNT - 1,
973 currency: TEST_CURRENCY,
976 selectedPlanName: undefined,
977 billingPlatform: undefined,
978 chargebeeUserExists: undefined,
979 disableNewPaymentMethods: false,
980 billingAddress: undefinedBillingAddress,
981 enableSepa: enableSepaTrue,
984 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
987 it.each([PLANS.MAIL_PRO, PLANS.DRIVE_PRO, PLANS.BUNDLE_PRO, PLANS.BUNDLE_PRO_2024])(
988 'should not display bitcoin for b2b plans',
990 const flow: PaymentMethodFlows = 'subscription';
992 const methods = new PaymentMethods({
993 paymentMethodStatus: status,
995 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
997 currency: TEST_CURRENCY,
1000 selectedPlanName: plan,
1001 billingPlatform: undefined,
1002 chargebeeUserExists: undefined,
1003 disableNewPaymentMethods: false,
1004 billingAddress: undefinedBillingAddress,
1005 enableSepa: enableSepaTrue,
1008 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1012 it('should return false if INHOUSE_FORCED', () => {
1013 const flow: PaymentMethodFlows = 'subscription';
1015 const methods = new PaymentMethods({
1016 paymentMethodStatus: status,
1018 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1020 currency: TEST_CURRENCY,
1023 selectedPlanName: undefined,
1024 billingPlatform: undefined,
1025 chargebeeUserExists: undefined,
1026 disableNewPaymentMethods: false,
1027 billingAddress: undefinedBillingAddress,
1028 enableSepa: enableSepaTrue,
1031 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
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,
1043 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1045 currency: TEST_CURRENCY,
1048 selectedPlanName: undefined,
1049 billingPlatform: BillingPlatform.Proton,
1050 chargebeeUserExists: chargebeeUserExists,
1051 disableNewPaymentMethods: false,
1052 billingAddress: undefinedBillingAddress,
1053 enableSepa: enableSepaTrue,
1056 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
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,
1068 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1070 currency: TEST_CURRENCY,
1073 selectedPlanName: undefined,
1074 billingPlatform: BillingPlatform.Proton,
1075 chargebeeUserExists: chargebeeUserExists,
1076 disableNewPaymentMethods: false,
1077 billingAddress: undefinedBillingAddress,
1078 enableSepa: enableSepaTrue,
1081 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
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,
1090 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1092 currency: TEST_CURRENCY,
1095 selectedPlanName: undefined,
1096 billingPlatform: undefined,
1097 chargebeeUserExists: undefined,
1098 disableNewPaymentMethods: false,
1099 billingAddress: undefinedBillingAddress,
1100 enableSepa: enableSepaTrue,
1105 [PLANS.PASS_LIFETIME]: 1,
1109 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
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,
1118 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1120 currency: TEST_CURRENCY,
1123 selectedPlanName: undefined,
1124 billingPlatform: undefined,
1125 chargebeeUserExists: undefined,
1126 disableNewPaymentMethods: false,
1127 billingAddress: undefinedBillingAddress,
1128 enableSepa: enableSepaTrue,
1131 [PLANS.PASS_LIFETIME]: 1,
1135 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
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,
1144 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1149 selectedPlanName: undefined,
1150 billingPlatform: undefined,
1151 chargebeeUserExists: undefined,
1152 disableNewPaymentMethods: false,
1153 billingAddress: undefinedBillingAddress,
1154 enableSepa: enableSepaTrue,
1157 [PLANS.PASS_LIFETIME]: 1,
1159 subscription: buildSubscription({
1164 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
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,
1173 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1175 currency: TEST_CURRENCY,
1178 selectedPlanName: undefined,
1179 billingPlatform: undefined,
1180 chargebeeUserExists: undefined,
1181 disableNewPaymentMethods: false,
1182 billingAddress: undefinedBillingAddress,
1183 enableSepa: enableSepaTrue,
1186 [PLANS.PASS_LIFETIME]: 1,
1188 subscription: buildSubscription({
1189 Currency: TEST_CURRENCY,
1193 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
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,
1202 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1204 currency: TEST_CURRENCY,
1207 selectedPlanName: undefined,
1208 billingPlatform: undefined,
1209 chargebeeUserExists: undefined,
1210 disableNewPaymentMethods: false,
1211 billingAddress: undefinedBillingAddress,
1212 enableSepa: enableSepaTrue,
1215 [PLANS.PASS_LIFETIME]: 1,
1217 subscription: FREE_SUBSCRIPTION,
1220 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
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,
1229 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1231 currency: TEST_CURRENCY,
1234 selectedPlanName: undefined,
1235 billingPlatform: undefined,
1236 chargebeeUserExists: undefined,
1237 disableNewPaymentMethods: false,
1238 billingAddress: undefinedBillingAddress,
1239 enableSepa: enableSepaTrue,
1244 subscription: FREE_SUBSCRIPTION,
1247 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1250 it('should not display bitcoin if user has unpaid invoices', () => {
1251 const user = buildUser({
1252 Delinquent: UNPAID_STATE.AVAILABLE,
1255 const methods = new PaymentMethods({
1256 paymentMethodStatus: status,
1258 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1260 currency: TEST_CURRENCY,
1262 flow: 'subscription',
1264 selectedPlanName: undefined,
1265 billingPlatform: undefined,
1266 chargebeeUserExists: undefined,
1267 disableNewPaymentMethods: false,
1268 billingAddress: undefinedBillingAddress,
1269 enableSepa: enableSepaTrue,
1272 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(false);
1275 it('should display bitcoin if user is not delinquent', () => {
1276 const user = buildUser({
1277 Delinquent: UNPAID_STATE.NOT_UNPAID,
1280 const methods = new PaymentMethods({
1281 paymentMethodStatus: status,
1283 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1285 currency: TEST_CURRENCY,
1287 flow: 'subscription',
1289 selectedPlanName: undefined,
1290 billingPlatform: undefined,
1291 chargebeeUserExists: undefined,
1292 disableNewPaymentMethods: false,
1293 billingAddress: undefinedBillingAddress,
1294 enableSepa: enableSepaTrue,
1297 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1301 describe('Bitcoin', () => {
1302 it('should NOT be present when chargebee-bitcoin is available', () => {
1303 const methods = new PaymentMethods({
1304 paymentMethodStatus: status,
1306 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1308 currency: TEST_CURRENCY,
1310 flow: 'subscription',
1311 selectedPlanName: undefined,
1312 billingPlatform: undefined,
1313 chargebeeUserExists: undefined,
1314 disableNewPaymentMethods: false,
1315 billingAddress: undefinedBillingAddress,
1316 enableSepa: enableSepaTrue,
1319 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-bitcoin')).toBe(true);
1320 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1323 it('should be available when INHOUSE_FORCED', () => {
1324 const methods = new PaymentMethods({
1325 paymentMethodStatus: status,
1327 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1329 currency: TEST_CURRENCY,
1331 flow: 'subscription',
1332 selectedPlanName: undefined,
1333 billingPlatform: undefined,
1334 chargebeeUserExists: undefined,
1335 disableNewPaymentMethods: false,
1336 billingAddress: undefinedBillingAddress,
1337 enableSepa: enableSepaTrue,
1340 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
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,
1353 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1355 currency: TEST_CURRENCY,
1358 selectedPlanName: undefined,
1359 billingPlatform: BillingPlatform.Proton,
1360 chargebeeUserExists: chargebeeUserExists,
1361 disableNewPaymentMethods: false,
1362 billingAddress: undefinedBillingAddress,
1363 enableSepa: enableSepaTrue,
1366 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
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,
1376 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1378 currency: TEST_CURRENCY,
1381 selectedPlanName: undefined,
1382 billingPlatform: undefined,
1383 chargebeeUserExists: undefined,
1384 disableNewPaymentMethods: false,
1385 billingAddress: undefinedBillingAddress,
1386 enableSepa: enableSepaTrue,
1389 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1396 'signup-v2-upgrade',
1400 ] as PaymentMethodFlows[])('should not display bitcoin in %s flow', (flow) => {
1401 const methods = new PaymentMethods({
1402 paymentMethodStatus: status,
1404 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1406 currency: TEST_CURRENCY,
1409 selectedPlanName: undefined,
1410 billingPlatform: undefined,
1411 chargebeeUserExists: undefined,
1412 disableNewPaymentMethods: false,
1413 billingAddress: undefinedBillingAddress,
1414 enableSepa: enableSepaTrue,
1417 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
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,
1426 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1427 amount: MIN_BITCOIN_AMOUNT - 1,
1428 currency: TEST_CURRENCY,
1431 selectedPlanName: undefined,
1432 billingPlatform: undefined,
1433 chargebeeUserExists: undefined,
1434 disableNewPaymentMethods: false,
1435 billingAddress: undefinedBillingAddress,
1436 enableSepa: enableSepaTrue,
1439 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1442 it.each([PLANS.MAIL_PRO, PLANS.DRIVE_PRO, PLANS.BUNDLE_PRO, PLANS.BUNDLE_PRO_2024])(
1443 'should not display bitcoin for b2b plans',
1445 const flow: PaymentMethodFlows = 'subscription';
1447 const methods = new PaymentMethods({
1448 paymentMethodStatus: status,
1450 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1452 currency: TEST_CURRENCY,
1455 selectedPlanName: plan,
1456 billingPlatform: undefined,
1457 chargebeeUserExists: undefined,
1458 disableNewPaymentMethods: false,
1459 billingAddress: undefinedBillingAddress,
1460 enableSepa: enableSepaTrue,
1463 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1467 it('should not display bitcoin if user has unpaid invoices', () => {
1468 const user = buildUser({
1469 Delinquent: UNPAID_STATE.AVAILABLE,
1472 const methods = new PaymentMethods({
1473 paymentMethodStatus: status,
1475 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1477 currency: TEST_CURRENCY,
1479 flow: 'subscription',
1481 selectedPlanName: undefined,
1482 billingPlatform: undefined,
1483 chargebeeUserExists: undefined,
1484 disableNewPaymentMethods: false,
1485 billingAddress: undefinedBillingAddress,
1486 enableSepa: enableSepaTrue,
1489 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1492 it('should display bitcoin if user is not delinquent', () => {
1493 const user = buildUser({
1494 Delinquent: UNPAID_STATE.NOT_UNPAID,
1497 const methods = new PaymentMethods({
1498 paymentMethodStatus: status,
1500 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1502 currency: TEST_CURRENCY,
1504 flow: 'subscription',
1506 selectedPlanName: undefined,
1507 billingPlatform: undefined,
1508 chargebeeUserExists: undefined,
1509 disableNewPaymentMethods: false,
1510 billingAddress: undefinedBillingAddress,
1511 enableSepa: enableSepaTrue,
1514 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1517 it('should not display bitcoin if user has unpaid invoices', () => {
1518 const user = buildUser({
1519 Delinquent: UNPAID_STATE.AVAILABLE,
1522 const methods = new PaymentMethods({
1523 paymentMethodStatus: status,
1525 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1527 currency: TEST_CURRENCY,
1529 flow: 'subscription',
1531 selectedPlanName: undefined,
1532 billingPlatform: undefined,
1533 chargebeeUserExists: undefined,
1534 disableNewPaymentMethods: false,
1535 billingAddress: undefinedBillingAddress,
1536 enableSepa: enableSepaTrue,
1539 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(false);
1542 it('should display bitcoin if user is not delinquent', () => {
1543 const user = buildUser({
1544 Delinquent: UNPAID_STATE.NOT_UNPAID,
1547 const methods = new PaymentMethods({
1548 paymentMethodStatus: status,
1550 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1552 currency: TEST_CURRENCY,
1554 flow: 'subscription',
1556 selectedPlanName: undefined,
1557 billingPlatform: undefined,
1558 chargebeeUserExists: undefined,
1559 disableNewPaymentMethods: false,
1560 billingAddress: undefinedBillingAddress,
1561 enableSepa: enableSepaTrue,
1564 expect(methods.getNewMethods().some((method) => method.type === 'bitcoin')).toBe(true);
1568 describe('Chargebee card', () => {
1569 it('should display chargebee card', () => {
1570 const flow: PaymentMethodFlows = 'subscription';
1572 const methods = new PaymentMethods({
1573 paymentMethodStatus: status,
1575 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1577 currency: TEST_CURRENCY,
1580 selectedPlanName: undefined,
1581 billingPlatform: undefined,
1582 chargebeeUserExists: undefined,
1583 disableNewPaymentMethods: false,
1584 billingAddress: undefinedBillingAddress,
1585 enableSepa: enableSepaTrue,
1588 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1591 it('should disable CB card if INHOUSE_FORCED', () => {
1592 const flow: PaymentMethodFlows = 'subscription';
1594 const methods = new PaymentMethods({
1595 paymentMethodStatus: status,
1597 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1599 currency: TEST_CURRENCY,
1602 selectedPlanName: undefined,
1603 billingPlatform: undefined,
1604 chargebeeUserExists: undefined,
1605 disableNewPaymentMethods: false,
1606 billingAddress: undefinedBillingAddress,
1607 enableSepa: enableSepaTrue,
1610 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
1611 expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
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,
1622 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1624 currency: TEST_CURRENCY,
1626 flow: flow as PaymentMethodFlows,
1627 selectedPlanName: undefined,
1628 billingPlatform: BillingPlatform.Proton,
1629 chargebeeUserExists: chargebeeUserExists,
1630 disableNewPaymentMethods: false,
1631 billingAddress: undefinedBillingAddress,
1632 enableSepa: enableSepaTrue,
1635 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
1636 expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(true);
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,
1647 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1649 currency: TEST_CURRENCY,
1651 flow: flow as PaymentMethodFlows,
1652 selectedPlanName: undefined,
1653 billingPlatform: BillingPlatform.Proton,
1654 chargebeeUserExists: chargebeeUserExists,
1655 disableNewPaymentMethods: false,
1656 billingAddress: undefinedBillingAddress,
1657 enableSepa: enableSepaTrue,
1660 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1661 expect(methods.getNewMethods().some((method) => method.type === 'card')).toBe(false);
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,
1671 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1673 currency: TEST_CURRENCY,
1676 selectedPlanName: undefined,
1677 billingPlatform: undefined,
1678 chargebeeUserExists: undefined,
1679 disableNewPaymentMethods: false,
1680 billingAddress: undefinedBillingAddress,
1681 enableSepa: enableSepaTrue,
1684 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(false);
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,
1693 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1695 currency: TEST_CURRENCY,
1698 selectedPlanName: undefined,
1699 billingPlatform: undefined,
1700 chargebeeUserExists: undefined,
1701 disableNewPaymentMethods: false,
1702 billingAddress: undefinedBillingAddress,
1703 enableSepa: enableSepaTrue,
1706 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
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,
1715 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1717 currency: TEST_CURRENCY,
1720 selectedPlanName: undefined,
1721 billingPlatform: undefined,
1722 chargebeeUserExists: undefined,
1723 disableNewPaymentMethods: false,
1724 billingAddress: undefinedBillingAddress,
1725 enableSepa: enableSepaTrue,
1728 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-card')).toBe(true);
1732 describe('Chargebee PayPal', () => {
1733 it('should display chargebee paypal', () => {
1734 const flow: PaymentMethodFlows = 'subscription';
1736 const methods = new PaymentMethods({
1737 paymentMethodStatus: status,
1739 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1741 currency: TEST_CURRENCY,
1744 selectedPlanName: undefined,
1745 billingPlatform: undefined,
1746 chargebeeUserExists: undefined,
1747 disableNewPaymentMethods: false,
1748 billingAddress: undefinedBillingAddress,
1749 enableSepa: enableSepaTrue,
1752 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
1755 it('should disable CB paypal if INHOUSE_FORCED', () => {
1756 const flow: PaymentMethodFlows = 'subscription';
1758 const methods = new PaymentMethods({
1759 paymentMethodStatus: status,
1761 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1763 currency: TEST_CURRENCY,
1766 selectedPlanName: undefined,
1767 billingPlatform: undefined,
1768 chargebeeUserExists: undefined,
1769 disableNewPaymentMethods: false,
1770 billingAddress: undefinedBillingAddress,
1771 enableSepa: enableSepaTrue,
1774 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1775 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
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,
1788 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1790 currency: TEST_CURRENCY,
1792 flow: flow as PaymentMethodFlows,
1793 selectedPlanName: undefined,
1794 billingPlatform: BillingPlatform.Proton,
1795 chargebeeUserExists: chargebeeUserExists,
1796 disableNewPaymentMethods: false,
1797 billingAddress: undefinedBillingAddress,
1798 enableSepa: enableSepaTrue,
1801 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1802 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(true);
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,
1813 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1815 currency: TEST_CURRENCY,
1817 flow: flow as PaymentMethodFlows,
1818 selectedPlanName: undefined,
1819 billingPlatform: BillingPlatform.Proton,
1820 chargebeeUserExists: chargebeeUserExists,
1821 disableNewPaymentMethods: false,
1822 billingAddress: undefinedBillingAddress,
1823 enableSepa: enableSepaTrue,
1826 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
1827 expect(methods.getNewMethods().some((method) => method.type === 'paypal')).toBe(false);
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,
1838 Type: PAYMENT_METHOD_TYPES.PAYPAL,
1841 BillingAgreementID: 'BA-123',
1847 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1849 currency: TEST_CURRENCY,
1852 selectedPlanName: undefined,
1853 billingPlatform: BillingPlatform.Chargebee,
1854 chargebeeUserExists: 1,
1855 disableNewPaymentMethods: false,
1856 billingAddress: undefinedBillingAddress,
1857 enableSepa: enableSepaTrue,
1860 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
1863 it('should disable paypal if the amount is too low', () => {
1864 const flow: PaymentMethodFlows = 'subscription';
1866 const methods = new PaymentMethods({
1867 paymentMethodStatus: status,
1869 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1870 amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1871 currency: TEST_CURRENCY,
1874 selectedPlanName: undefined,
1875 billingPlatform: undefined,
1876 chargebeeUserExists: undefined,
1877 disableNewPaymentMethods: false,
1878 billingAddress: undefinedBillingAddress,
1879 enableSepa: enableSepaTrue,
1882 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
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,
1891 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1892 amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1893 currency: TEST_CURRENCY,
1896 selectedPlanName: undefined,
1897 billingPlatform: undefined,
1898 chargebeeUserExists: undefined,
1899 disableNewPaymentMethods: false,
1900 billingAddress: undefinedBillingAddress,
1901 enableSepa: enableSepaTrue,
1904 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(true);
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,
1914 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1916 currency: TEST_CURRENCY,
1919 selectedPlanName: undefined,
1920 billingPlatform: undefined,
1921 chargebeeUserExists: undefined,
1922 disableNewPaymentMethods: false,
1923 billingAddress: undefinedBillingAddress,
1924 enableSepa: enableSepaTrue,
1927 expect(methods.getNewMethods().some((method) => method.type === 'chargebee-paypal')).toBe(false);
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,
1939 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1940 amount: MIN_PAYPAL_AMOUNT_CHARGEBEE - 1,
1941 currency: TEST_CURRENCY,
1944 selectedPlanName: undefined,
1945 billingPlatform: undefined,
1946 chargebeeUserExists: undefined,
1947 disableNewPaymentMethods: disableNewPaymentMethods,
1948 billingAddress: undefinedBillingAddress,
1949 enableSepa: enableSepaTrue,
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,
1962 chargebeeEnabled: ChargebeeEnabled.INHOUSE_FORCED,
1964 currency: TEST_CURRENCY,
1967 selectedPlanName: undefined,
1968 billingPlatform: undefined,
1969 chargebeeUserExists: undefined,
1970 disableNewPaymentMethods: false,
1971 billingAddress: { CountryCode: 'CH' },
1972 enableSepa: enableSepaTrue,
1976 methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
1980 it('should display SEPA', () => {
1981 const flow: PaymentMethodFlows = 'subscription';
1983 const methods = new PaymentMethods({
1984 paymentMethodStatus: status,
1986 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
1988 currency: TEST_CURRENCY,
1991 selectedPlanName: undefined,
1992 billingPlatform: undefined,
1993 chargebeeUserExists: undefined,
1994 disableNewPaymentMethods: false,
1995 billingAddress: { CountryCode: 'CH' },
1996 enableSepa: enableSepaTrue,
2000 methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
2008 'signup-pass-upgrade',
2009 'signup-v2-upgrade',
2011 ] as PaymentMethodFlows[])('should not offer SEPA for %s flow', (flow) => {
2012 const methods = new PaymentMethods({
2013 paymentMethodStatus: status,
2015 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2017 currency: TEST_CURRENCY,
2020 selectedPlanName: undefined,
2021 billingPlatform: undefined,
2022 chargebeeUserExists: undefined,
2023 disableNewPaymentMethods: false,
2024 billingAddress: { CountryCode: 'CH' },
2025 enableSepa: enableSepaTrue,
2029 methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
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,
2039 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2041 currency: TEST_CURRENCY,
2044 selectedPlanName: undefined,
2045 billingPlatform: undefined,
2046 chargebeeUserExists: undefined,
2047 disableNewPaymentMethods: false,
2048 billingAddress: { CountryCode: 'US' },
2049 enableSepa: enableSepaTrue,
2053 methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)
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,
2065 chargebeeEnabled: ChargebeeEnabled.CHARGEBEE_FORCED,
2067 currency: TEST_CURRENCY,
2070 selectedPlanName: undefined,
2071 billingPlatform: undefined,
2072 chargebeeUserExists: undefined,
2073 disableNewPaymentMethods: false,
2074 billingAddress: { CountryCode: 'CH' },
2075 enableSepa: enableSepaFalse,
2079 methods.getNewMethods().some((method) => method.type === PAYMENT_METHOD_TYPES.CHARGEBEE_SEPA_DIRECT_DEBIT)