diff --git a/src/app/components/ui/select/select.tsx b/src/app/components/ui/select/select.tsx
index d7586558..d358dce5 100644
--- a/src/app/components/ui/select/select.tsx
+++ b/src/app/components/ui/select/select.tsx
@@ -49,3 +49,5 @@ export const Select = forwardRef
(({ children, er
{!error && dirty && }
));
+
+Select.displayName = 'Select';
diff --git a/src/app/config/config-resolver/resolve-boolean.ts b/src/app/config/config-resolver/resolve-boolean.ts
index 01cd7072..3c5be399 100644
--- a/src/app/config/config-resolver/resolve-boolean.ts
+++ b/src/app/config/config-resolver/resolve-boolean.ts
@@ -1,5 +1,6 @@
import isBoolean from 'checkout/utils/is-boolean';
import isString from 'checkout/utils/is-string';
+
import { getMessageInvalidValue } from '../../log-messages';
const toBoolean = (str: string): boolean => {
diff --git a/src/app/config/config-resolver/resolve-init-config.spec.ts b/src/app/config/config-resolver/resolve-init-config.spec.ts
index 8697b672..679a4402 100644
--- a/src/app/config/config-resolver/resolve-init-config.spec.ts
+++ b/src/app/config/config-resolver/resolve-init-config.spec.ts
@@ -1,6 +1,7 @@
-import { resolveInitConfig } from './resolve-init-config';
import { HoldExpirationType } from 'checkout/backend';
+import { resolveInitConfig } from './resolve-init-config';
+
it('should return resolved init config', () => {
const param = {
invoiceID: 'someID',
@@ -12,7 +13,7 @@ it('should return resolved init config', () => {
description: 'some description',
email: 'test@test.com',
redirectUrl: 'some url',
- theme: 'main'
+ theme: 'main',
};
const actual = resolveInitConfig(param as any);
@@ -33,7 +34,6 @@ it('should return resolved init config', () => {
amount: 1000,
email: 'test@test.com',
description: 'some description',
- // @ts-ignore
metadata: undefined,
name: 'some name',
netBanking: true,
@@ -45,7 +45,7 @@ it('should return resolved init config', () => {
terminalBankCard: true,
terminalFormValues: undefined,
terminalWallets: true,
- upi: true
+ upi: true,
};
expect(actual).toEqual(expected);
});
diff --git a/src/app/config/config-resolver/resolve-init-config.ts b/src/app/config/config-resolver/resolve-init-config.ts
index e41b5b02..55ce0e72 100644
--- a/src/app/config/config-resolver/resolve-init-config.ts
+++ b/src/app/config/config-resolver/resolve-init-config.ts
@@ -1,14 +1,15 @@
-import { resolveBoolean } from './resolve-boolean';
-import { resolveInteger } from './resolve-integer';
-import { InitConfig } from '../init-config';
-import { resolveIntegrationType } from './resolve-integration-type';
-import { resolveString } from './resolve-string';
import { HoldExpirationType } from 'checkout/backend/model';
-import { resolveObject } from './resolve-object';
-import { detectLocale } from '../../../locale';
-import { resolveRedirectUrl } from './resolve-redirect-url';
+
+import { resolveBoolean } from './resolve-boolean';
import { resolveEmail } from './resolve-email';
+import { resolveInteger } from './resolve-integer';
+import { resolveIntegrationType } from './resolve-integration-type';
+import { resolveObject } from './resolve-object';
import { resolvePhoneNumber } from './resolve-phone-number';
+import { resolveRedirectUrl } from './resolve-redirect-url';
+import { resolveString } from './resolve-string';
+import { detectLocale } from '../../../locale';
+import { InitConfig } from '../init-config';
const setDefault = (userParam: P, defaultValue: D): P | D =>
userParam === null || userParam === undefined ? defaultValue : userParam;
@@ -16,7 +17,7 @@ const setDefault =
(userParam: P, defaultValue: D): P | D =>
const checkUnknown = (resolvedParams: object, allParams: object): void => {
const resolvedParamsKeys = Object.keys(resolvedParams);
const unknownParams = Object.keys(allParams).filter(
- (param) => resolvedParamsKeys.findIndex((v) => v === param) === -1
+ (param) => resolvedParamsKeys.findIndex((v) => v === param) === -1,
);
if (unknownParams.length) {
console.warn(`Unknown params: ${unknownParams.join(', ')}`);
@@ -41,7 +42,6 @@ export const resolveInitConfig = (userConfig: Partial): InitConfig =
holdExpiration,
locale,
recurring,
- theme,
brandless,
metadata,
terminalFormValues,
@@ -71,7 +71,7 @@ export const resolveInitConfig = (userConfig: Partial): InitConfig =
paymentFlowHold: setDefault(resolveBoolean(paymentFlowHold, 'paymentFlowHold'), false),
holdExpiration: setDefault(
resolveString(holdExpiration, 'holdExpiration') as HoldExpirationType,
- HoldExpirationType.cancel
+ HoldExpirationType.cancel,
),
locale: detectLocale(resolveString(locale, 'locale')),
recurring: setDefault(resolveBoolean(recurring, 'recurring'), false),
@@ -87,6 +87,6 @@ export const resolveInitConfig = (userConfig: Partial): InitConfig =
terminalWallets: setDefault(resolveBoolean(terminalWallets, 'terminalWallets'), true),
pix: setDefault(resolveBoolean(pix, 'pix'), true),
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction, 'skipUserInteraction'), false),
- isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded, 'isExternalIDIncluded'), false)
+ isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded, 'isExternalIDIncluded'), false),
};
};
diff --git a/src/app/config/config-resolver/resolve-integer.spec.ts b/src/app/config/config-resolver/resolve-integer.spec.ts
index 5a025e8a..8bcdf3f9 100644
--- a/src/app/config/config-resolver/resolve-integer.spec.ts
+++ b/src/app/config/config-resolver/resolve-integer.spec.ts
@@ -1,6 +1,7 @@
-import { resolveInteger } from './resolve-integer';
import { getMessageInvalidValue } from 'checkout/log-messages';
+import { resolveInteger } from './resolve-integer';
+
jest.mock('../../log-messages');
const getMessageInvalidValueMock = getMessageInvalidValue as any;
diff --git a/src/app/config/config-resolver/resolve-integer.ts b/src/app/config/config-resolver/resolve-integer.ts
index 42593465..10ef607d 100644
--- a/src/app/config/config-resolver/resolve-integer.ts
+++ b/src/app/config/config-resolver/resolve-integer.ts
@@ -1,6 +1,7 @@
-import toNumber from 'checkout/utils/to-number';
import isNumber from 'checkout/utils/is-number';
import isString from 'checkout/utils/is-string';
+import toNumber from 'checkout/utils/to-number';
+
import { getMessageInvalidValue } from '../../log-messages';
const getFromNumber = (userInteger: number): number | null => (Number.isInteger(userInteger) ? userInteger : undefined);
diff --git a/src/app/config/config-resolver/resolve-integration-type.spec.ts b/src/app/config/config-resolver/resolve-integration-type.spec.ts
index 32820eb1..a3fea4c0 100644
--- a/src/app/config/config-resolver/resolve-integration-type.spec.ts
+++ b/src/app/config/config-resolver/resolve-integration-type.spec.ts
@@ -7,7 +7,7 @@ it('empty config should return null', () => {
it('wrong config should return null', () => {
const result = resolveIntegrationType({
- wrongField: 'some value'
+ wrongField: 'some value',
} as any);
expect(result).toEqual(null);
});
@@ -16,12 +16,12 @@ it('should return invoice integration type', () => {
const result = resolveIntegrationType({
invoiceID: 'mock invoiceID',
invoiceAccessToken: 'mock token',
- someField: 'someValue'
+ someField: 'someValue',
} as any);
const expected = {
integrationType: 'invoice',
invoiceID: 'mock invoiceID',
- invoiceAccessToken: 'mock token'
+ invoiceAccessToken: 'mock token',
};
expect(result).toEqual(expected);
});
@@ -30,12 +30,12 @@ it('should return invoiceTemplate integration type', () => {
const result = resolveIntegrationType({
invoiceTemplateID: 'mock invoiceTemplateID',
invoiceTemplateAccessToken: 'mock token',
- someField: 'someValue'
+ someField: 'someValue',
} as any);
const expected = {
integrationType: 'invoiceTemplate',
invoiceTemplateID: 'mock invoiceTemplateID',
- invoiceTemplateAccessToken: 'mock token'
+ invoiceTemplateAccessToken: 'mock token',
};
expect(result).toEqual(expected);
});
diff --git a/src/app/config/config-resolver/resolve-integration-type.ts b/src/app/config/config-resolver/resolve-integration-type.ts
index 7d71a0ce..71bab95f 100644
--- a/src/app/config/config-resolver/resolve-integration-type.ts
+++ b/src/app/config/config-resolver/resolve-integration-type.ts
@@ -1,15 +1,19 @@
import intersection from 'checkout/utils/intersection';
+
import { InitConfig } from '../init-config';
-const typesDef: { type: 'invoiceTemplate' | 'invoice'; requiredFields: string[] }[] = [
+const typesDef: {
+ type: 'invoiceTemplate' | 'invoice';
+ requiredFields: string[];
+}[] = [
{
type: 'invoiceTemplate',
- requiredFields: ['invoiceTemplateID', 'invoiceTemplateAccessToken']
+ requiredFields: ['invoiceTemplateID', 'invoiceTemplateAccessToken'],
},
{
type: 'invoice',
- requiredFields: ['invoiceID', 'invoiceAccessToken']
- }
+ requiredFields: ['invoiceID', 'invoiceAccessToken'],
+ },
];
export const resolveIntegrationType = (userConfig: InitConfig): InitConfig => {
@@ -24,8 +28,8 @@ export const resolveIntegrationType = (userConfig: InitConfig): InitConfig => {
return found.requiredFields.reduce(
(acc, current) => ({
...acc,
- [current]: (userConfig as { [param: string]: string })[current]
+ [current]: (userConfig as { [param: string]: string })[current],
}),
- { integrationType: found.type }
+ { integrationType: found.type },
);
};
diff --git a/src/app/config/config-resolver/resolve-object.spec.ts b/src/app/config/config-resolver/resolve-object.spec.ts
index b7b69584..c7ce74ed 100644
--- a/src/app/config/config-resolver/resolve-object.spec.ts
+++ b/src/app/config/config-resolver/resolve-object.spec.ts
@@ -1,6 +1,7 @@
-import { resolveObject } from './resolve-object';
import { getMessageInvalidValue } from 'checkout/log-messages';
+import { resolveObject } from './resolve-object';
+
jest.mock('../../log-messages');
const getMessageInvalidValueMock = getMessageInvalidValue as any;
diff --git a/src/app/config/config-resolver/resolve-object.ts b/src/app/config/config-resolver/resolve-object.ts
index a0e10c60..8193bf1e 100644
--- a/src/app/config/config-resolver/resolve-object.ts
+++ b/src/app/config/config-resolver/resolve-object.ts
@@ -1,4 +1,5 @@
import isString from 'checkout/utils/is-string';
+
import { getMessageInvalidValue } from '../../log-messages';
const getObject = (inputObject: object | string): object => {
diff --git a/src/app/config/config-resolver/resolve-string.spec.ts b/src/app/config/config-resolver/resolve-string.spec.ts
index 7c601499..1bc6913d 100644
--- a/src/app/config/config-resolver/resolve-string.spec.ts
+++ b/src/app/config/config-resolver/resolve-string.spec.ts
@@ -1,6 +1,7 @@
-import { resolveString } from './resolve-string';
import { getMessageInvalidValue } from 'checkout/log-messages';
+import { resolveString } from './resolve-string';
+
jest.mock('../../log-messages');
const getMessageInvalidValueMock = getMessageInvalidValue as any;
diff --git a/src/app/config/config-resolver/resolve-string.ts b/src/app/config/config-resolver/resolve-string.ts
index ad0d1aa7..3d73af3d 100644
--- a/src/app/config/config-resolver/resolve-string.ts
+++ b/src/app/config/config-resolver/resolve-string.ts
@@ -1,4 +1,5 @@
import isString from 'checkout/utils/is-string';
+
import { getMessageInvalidValue } from '../../log-messages';
const getString = (userString: any): string => {
diff --git a/src/app/hooks/create-payment/__mocks__/@fingerprintjs/fingerprintjs.ts b/src/app/hooks/create-payment/__mocks__/@fingerprintjs/fingerprintjs.ts
index fd81924e..e60230ca 100644
--- a/src/app/hooks/create-payment/__mocks__/@fingerprintjs/fingerprintjs.ts
+++ b/src/app/hooks/create-payment/__mocks__/@fingerprintjs/fingerprintjs.ts
@@ -3,9 +3,9 @@ module.exports = {
Promise.resolve({
get: jest.fn().mockReturnValue(
Promise.resolve({
- visitorId: 'userFingerprintTest'
- })
- )
- })
- )
+ visitorId: 'userFingerprintTest',
+ }),
+ ),
+ }),
+ ),
};
diff --git a/src/app/hooks/create-payment/create-invoice-with-template.ts b/src/app/hooks/create-payment/create-invoice-with-template.ts
index 735e562e..f068470f 100644
--- a/src/app/hooks/create-payment/create-invoice-with-template.ts
+++ b/src/app/hooks/create-payment/create-invoice-with-template.ts
@@ -1,8 +1,8 @@
-import { toMinorAmount } from 'checkout/utils';
import { InvoiceAndToken, InvoiceTemplate, createInvoiceWithTemplate as request } from 'checkout/backend';
+import { toMinorAmount } from 'checkout/utils';
-import { AmountInfo } from '../init-app';
import { PayableInvoiceData } from './types';
+import { AmountInfo } from '../init-app';
const getAmount = (amountInfo: AmountInfo, formAmount: string): number => {
switch (amountInfo.status) {
@@ -15,10 +15,10 @@ const getAmount = (amountInfo: AmountInfo, formAmount: string): number => {
const toPayableInvoiceData = ({
invoice: { id, dueDate, externalID },
- invoiceAccessToken
+ invoiceAccessToken,
}: InvoiceAndToken): PayableInvoiceData => ({
invoice: { id, dueDate, externalID },
- invoiceAccessToken: invoiceAccessToken.payload
+ invoiceAccessToken: invoiceAccessToken.payload,
});
export type CreateInvoiceParams = {
@@ -34,12 +34,12 @@ export const createInvoiceWithTemplate = async ({
invoiceTemplateAccessToken,
invoiceTemplate: { metadata, id },
amountInfo,
- formAmount
+ formAmount,
}: CreateInvoiceParams): Promise => {
const params = {
amount: getAmount(amountInfo, formAmount),
metadata,
- currency: amountInfo.currencyCode
+ currency: amountInfo.currencyCode,
};
const invoiceAndToken = await request(capiEndpoint, invoiceTemplateAccessToken, id, params);
return toPayableInvoiceData(invoiceAndToken);
diff --git a/src/app/hooks/create-payment/create-payment.spec.ts b/src/app/hooks/create-payment/create-payment.spec.ts
index 567696c6..110542cc 100644
--- a/src/app/hooks/create-payment/create-payment.spec.ts
+++ b/src/app/hooks/create-payment/create-payment.spec.ts
@@ -1,12 +1,13 @@
import { PaymentTerminalFormValues } from 'checkout/hooks';
-import { PaymentMethodName } from '../init-app';
+
import { createPayment } from './create-payment';
+import { PaymentMethodName } from '../init-app';
const fetchMock = (result, status = 200, ok = true) =>
Promise.resolve({
status,
ok,
- json: () => Promise.resolve(result)
+ json: () => Promise.resolve(result),
});
describe('createPayment', () => {
@@ -16,7 +17,7 @@ describe('createPayment', () => {
}
if (args === 'https://shortener.test.com/v1/shortened-urls') {
return fetchMock({
- shortenedUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ shortenedUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
}
if (args === 'https://api.test.com/v2/processing/invoices/1nLoSaB3UUU/payments') {
@@ -35,14 +36,14 @@ describe('createPayment', () => {
initConfig: {
recurring: false,
metadata: {
- paymentMetaField: 'payment meta field'
+ paymentMetaField: 'payment meta field',
},
isExternalIDIncluded: true,
paymentFlowHold: false,
redirectUrl: 'https://init.config.redirect.url',
locale: null,
email: 'test@test.com',
- phoneNumber: '+79774443411'
+ phoneNumber: '+79774443411',
},
formData: {
method: PaymentMethodName.PaymentTerminal,
@@ -50,22 +51,22 @@ describe('createPayment', () => {
provider: 'provider ID',
paymentSessionInfo: {
redirectUrlInfo: {
- type: 'self'
- }
+ type: 'self',
+ },
},
metadata: {
- someField: 'test'
- }
- } as PaymentTerminalFormValues
+ someField: 'test',
+ },
+ } as PaymentTerminalFormValues,
},
payableInvoice: {
invoice: {
id: '1nLoSaB3UUU',
dueDate: '2023-05-22T13:47:47.444260Z',
- externalID: 'Invoice external ID'
+ externalID: 'Invoice external ID',
},
- invoiceAccessToken: 'eyJhb...'
- }
+ invoiceAccessToken: 'eyJhb...',
+ },
};
await createPayment(params);
@@ -80,15 +81,15 @@ describe('createPayment', () => {
paymentToolType: 'PaymentTerminalData',
provider: 'provider ID',
metadata: {
- someField: 'test'
- }
+ someField: 'test',
+ },
},
clientInfo: {
- fingerprint: 'userFingerprintTest'
- }
+ fingerprint: 'userFingerprintTest',
+ },
}),
- headers: expect.any(Object)
- })
+ headers: expect.any(Object),
+ }),
);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
@@ -97,10 +98,10 @@ describe('createPayment', () => {
body: JSON.stringify({
sourceUrl:
'https://origin.test.com/v1/checkout.html?invoiceID=1nLoSaB3UUU&invoiceAccessToken=eyJhb...&redirectUrl=https%3A%2F%2Finit.config.redirect.url&skipUserInteraction=true',
- expiresAt: '2023-05-22T13:47:47.444260Z'
+ expiresAt: '2023-05-22T13:47:47.444260Z',
}),
- headers: expect.any(Object)
- })
+ headers: expect.any(Object),
+ }),
);
expect(mockFetch).toHaveBeenCalledWith(
'https://api.test.com/v2/processing/invoices/1nLoSaB3UUU/payments',
@@ -108,26 +109,26 @@ describe('createPayment', () => {
method: 'POST',
body: JSON.stringify({
flow: {
- type: 'PaymentFlowInstant'
+ type: 'PaymentFlowInstant',
},
payer: {
payerType: 'PaymentResourcePayer',
contactInfo: {
email: 'test@test.com',
- phoneNumber: '+79774443411'
+ phoneNumber: '+79774443411',
},
sessionInfo: {
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
- }
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
+ },
},
makeRecurrent: false,
metadata: {
- paymentMetaField: 'payment meta field'
+ paymentMetaField: 'payment meta field',
},
- externalID: 'Invoice external ID'
+ externalID: 'Invoice external ID',
}),
- headers: expect.any(Object)
- })
+ headers: expect.any(Object),
+ }),
);
});
});
diff --git a/src/app/hooks/create-payment/create-payment.ts b/src/app/hooks/create-payment/create-payment.ts
index 78d267cb..7b233a3c 100644
--- a/src/app/hooks/create-payment/create-payment.ts
+++ b/src/app/hooks/create-payment/create-payment.ts
@@ -1,7 +1,8 @@
+import { Payment, createPayment as request } from 'checkout/backend';
+
import { createPayer } from './payer';
import { toPaymentFlow } from './to-payment-flow';
import { CreatePaymentParams } from './types';
-import { Payment, createPayment as request } from 'checkout/backend';
export const createPayment = async ({
capiEndpoint,
@@ -9,7 +10,7 @@ export const createPayment = async ({
origin,
initConfig,
formData,
- payableInvoice
+ payableInvoice,
}: CreatePaymentParams): Promise => {
const { invoice, invoiceAccessToken } = payableInvoice;
const {
@@ -21,7 +22,7 @@ export const createPayment = async ({
holdExpiration,
recurring,
metadata,
- isExternalIDIncluded
+ isExternalIDIncluded,
} = initConfig;
const payer = await createPayer({
capiEndpoint,
@@ -31,17 +32,17 @@ export const createPayment = async ({
redirectUrl,
locale,
email,
- phoneNumber
+ phoneNumber,
},
formData,
- payableInvoice
+ payableInvoice,
});
const params = {
flow: toPaymentFlow({ paymentFlowHold, holdExpiration }),
payer,
makeRecurrent: recurring,
metadata,
- externalID: isExternalIDIncluded ? invoice.externalID : undefined
+ externalID: isExternalIDIncluded ? invoice.externalID : undefined,
};
return await request(capiEndpoint, invoiceAccessToken, invoice.id, params);
};
diff --git a/src/app/hooks/create-payment/payer/create-payer.ts b/src/app/hooks/create-payment/payer/create-payer.ts
index daf32546..405a561b 100644
--- a/src/app/hooks/create-payment/payer/create-payer.ts
+++ b/src/app/hooks/create-payment/payer/create-payer.ts
@@ -1,4 +1,5 @@
import { PayerType, PaymentResourcePayer } from 'checkout/backend';
+
import { createPaymentResource } from './create-payment-resource';
import { createSessionInfo } from './create-session-info';
import { toContactInfo } from './to-contact-info';
@@ -10,12 +11,12 @@ export const createPayer = async ({
origin,
payableInvoice,
initConfig,
- formData
+ formData,
}: CreatePayerParams): Promise => {
const { paymentToolToken, paymentSession } = await createPaymentResource(
capiEndpoint,
payableInvoice.invoiceAccessToken,
- formData
+ formData,
);
const sessionInfo = await createSessionInfo(urlShortenerEndpoint, origin, initConfig, payableInvoice, formData);
const contactInfo = toContactInfo(initConfig, formData.values);
@@ -24,6 +25,6 @@ export const createPayer = async ({
paymentToolToken,
paymentSession,
contactInfo,
- sessionInfo
+ sessionInfo,
};
};
diff --git a/src/app/hooks/create-payment/payer/create-payment-resource.ts b/src/app/hooks/create-payment/payer/create-payment-resource.ts
index 1297449b..320f99c0 100644
--- a/src/app/hooks/create-payment/payer/create-payment-resource.ts
+++ b/src/app/hooks/create-payment/payer/create-payment-resource.ts
@@ -1,5 +1,7 @@
import { load } from '@fingerprintjs/fingerprintjs';
+
import { PaymentResource, createPaymentResource as request } from 'checkout/backend';
+
import { toPaymentTool } from './to-payment-tool';
import { FormData } from '../types';
@@ -17,12 +19,12 @@ const getFingerprint = (): Promise =>
export const createPaymentResource = async (
capiEndpoint: string,
invoiceAccessToken: string,
- formData: FormData
+ formData: FormData,
): Promise => {
const paymentTool = toPaymentTool(formData);
const clientInfo = {
fingerprint: await getFingerprint(),
- ...getClientInfoUrl()
+ ...getClientInfoUrl(),
};
return request(capiEndpoint, invoiceAccessToken, paymentTool, clientInfo);
};
diff --git a/src/app/hooks/create-payment/payer/create-session-info.spec.ts b/src/app/hooks/create-payment/payer/create-session-info.spec.ts
index bf394ba9..c9643d66 100644
--- a/src/app/hooks/create-payment/payer/create-session-info.spec.ts
+++ b/src/app/hooks/create-payment/payer/create-session-info.spec.ts
@@ -1,19 +1,20 @@
import { PaymentMethodName } from 'checkout/backend';
-import { createSessionInfo } from './create-session-info';
import { PaymentTerminalFormValues } from 'checkout/hooks';
+import { createSessionInfo } from './create-session-info';
+
const fetchMock = (result, status = 200, ok = true) =>
Promise.resolve({
status,
ok,
- json: () => Promise.resolve(result)
+ json: () => Promise.resolve(result),
});
describe('createSessionInfo', () => {
const mockFetch = jest.fn().mockImplementation((args) => {
if (args === 'https://shortener.test.com/v1/shortened-urls') {
return fetchMock({
- shortenedUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ shortenedUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
}
return Promise.reject('Mock function is not found');
@@ -29,15 +30,15 @@ describe('createSessionInfo', () => {
const origin = 'https://origin.test.com';
const initConfig = {
redirectUrl: 'https://init.config.redirect.url',
- locale: 'kr'
+ locale: 'kr',
};
const invoiceData = {
invoice: {
id: '1nLoSaB3UUU',
dueDate: '2023-05-22T13:47:47.444260Z',
- externalID: 'Invoice external ID'
+ externalID: 'Invoice external ID',
},
- invoiceAccessToken: 'eyJhb...'
+ invoiceAccessToken: 'eyJhb...',
};
const shortenerCallBody = (skipUserInteraction) =>
@@ -45,9 +46,9 @@ describe('createSessionInfo', () => {
method: 'POST',
body: JSON.stringify({
sourceUrl: `https://origin.test.com/v1/checkout.html?invoiceID=1nLoSaB3UUU&invoiceAccessToken=eyJhb...&redirectUrl=https%3A%2F%2Finit.config.redirect.url&locale=kr&skipUserInteraction=${skipUserInteraction}`,
- expiresAt: '2023-05-22T13:47:47.444260Z'
+ expiresAt: '2023-05-22T13:47:47.444260Z',
}),
- headers: expect.any(Object)
+ headers: expect.any(Object),
});
describe('method payment terminal', () => {
@@ -60,10 +61,10 @@ describe('createSessionInfo', () => {
values: {
paymentSessionInfo: {
redirectUrlInfo: {
- type: 'self'
- }
- }
- } as PaymentTerminalFormValues
+ type: 'self',
+ },
+ },
+ } as PaymentTerminalFormValues,
};
test('should shorten with initConfigRedirectUrl', async () => {
@@ -72,15 +73,15 @@ describe('createSessionInfo', () => {
origin,
initConfig,
invoiceData,
- formValues
+ formValues,
);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
- shortenerCallBody(skipUserInteraction)
+ shortenerCallBody(skipUserInteraction),
);
});
@@ -90,10 +91,10 @@ describe('createSessionInfo', () => {
origin,
{ redirectUrl: null },
invoiceData,
- formValues
+ formValues,
);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
@@ -102,10 +103,10 @@ describe('createSessionInfo', () => {
method: 'POST',
body: JSON.stringify({
sourceUrl: `https://origin.test.com/v1/checkout.html?invoiceID=1nLoSaB3UUU&invoiceAccessToken=eyJhb...&skipUserInteraction=${skipUserInteraction}`,
- expiresAt: '2023-05-22T13:47:47.444260Z'
+ expiresAt: '2023-05-22T13:47:47.444260Z',
}),
- headers: expect.any(Object)
- })
+ headers: expect.any(Object),
+ }),
);
});
});
@@ -116,10 +117,10 @@ describe('createSessionInfo', () => {
values: {
paymentSessionInfo: {
redirectUrlInfo: {
- type: 'outer'
- }
- }
- } as PaymentTerminalFormValues
+ type: 'outer',
+ },
+ },
+ } as PaymentTerminalFormValues,
};
test('should return initConfigRedirectUrl and do not shorten', async () => {
@@ -128,10 +129,10 @@ describe('createSessionInfo', () => {
origin,
initConfig,
invoiceData,
- formValues
+ formValues,
);
expect(result).toStrictEqual({
- redirectUrl: 'https://init.config.redirect.url'
+ redirectUrl: 'https://init.config.redirect.url',
});
expect(mockFetch).toHaveBeenCalledTimes(0);
});
@@ -143,10 +144,10 @@ describe('createSessionInfo', () => {
origin,
{ redirectUrl: null },
invoiceData,
- formValues
+ formValues,
);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
@@ -155,10 +156,10 @@ describe('createSessionInfo', () => {
method: 'POST',
body: JSON.stringify({
sourceUrl: `https://origin.test.com/v1/checkout.html?invoiceID=1nLoSaB3UUU&invoiceAccessToken=eyJhb...&skipUserInteraction=${skipUserInteraction}`,
- expiresAt: '2023-05-22T13:47:47.444260Z'
+ expiresAt: '2023-05-22T13:47:47.444260Z',
}),
- headers: expect.any(Object)
- })
+ headers: expect.any(Object),
+ }),
);
expect(errorSpy).toHaveBeenCalled();
});
@@ -168,17 +169,17 @@ describe('createSessionInfo', () => {
test('redirect url info is not specified', async () => {
const formValues = {
method: PaymentMethodName.PaymentTerminal,
- values: {}
+ values: {},
};
const result = await createSessionInfo(urlShortenerEndpoint, origin, initConfig, invoiceData, formValues);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
- shortenerCallBody(skipUserInteraction)
+ shortenerCallBody(skipUserInteraction),
);
});
@@ -186,18 +187,18 @@ describe('createSessionInfo', () => {
const formValues = {
method: PaymentMethodName.PaymentTerminal,
values: {
- paymentSessionInfo: {}
- } as PaymentTerminalFormValues
+ paymentSessionInfo: {},
+ } as PaymentTerminalFormValues,
};
const result = await createSessionInfo(urlShortenerEndpoint, origin, initConfig, invoiceData, formValues);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
- shortenerCallBody(skipUserInteraction)
+ shortenerCallBody(skipUserInteraction),
);
});
});
@@ -207,17 +208,17 @@ describe('createSessionInfo', () => {
test('should shorten redirect url with false skipUserInteraction', async () => {
const formValues = {
- method: PaymentMethodName.BankCard
+ method: PaymentMethodName.BankCard,
};
const result = await createSessionInfo(urlShortenerEndpoint, origin, initConfig, invoiceData, formValues);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
- shortenerCallBody(skipUserInteraction)
+ shortenerCallBody(skipUserInteraction),
);
});
});
@@ -227,17 +228,17 @@ describe('createSessionInfo', () => {
test('should shorten redirect url with false skipUserInteraction', async () => {
const formValues = {
- method: PaymentMethodName.DigitalWallet
+ method: PaymentMethodName.DigitalWallet,
};
const result = await createSessionInfo(urlShortenerEndpoint, origin, initConfig, invoiceData, formValues);
expect(result).toStrictEqual({
- redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH'
+ redirectUrl: 'https://shrt.empayre.com/6ut9gYaaMwH',
});
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledWith(
'https://shortener.test.com/v1/shortened-urls',
- shortenerCallBody(skipUserInteraction)
+ shortenerCallBody(skipUserInteraction),
);
});
});
diff --git a/src/app/hooks/create-payment/payer/create-session-info.ts b/src/app/hooks/create-payment/payer/create-session-info.ts
index cd0515e2..8e18c35f 100644
--- a/src/app/hooks/create-payment/payer/create-session-info.ts
+++ b/src/app/hooks/create-payment/payer/create-session-info.ts
@@ -1,13 +1,14 @@
import { PaymentMethodName, SessionInfo, ShortenedUrlParams, shortenUrl } from 'checkout/backend';
-import { FormData, PayableInvoiceData } from '../types';
-import { toSelfRedirectUrl } from './to-self-redirect-url';
import { PaymentTerminalFormValues } from 'checkout/hooks';
import isNil from 'checkout/utils/is-nil';
+import { toSelfRedirectUrl } from './to-self-redirect-url';
+import { FormData, PayableInvoiceData } from '../types';
+
export const shorten = (
urlShortenerEndpoint: string,
invoiceAccessToken: string,
- params: ShortenedUrlParams
+ params: ShortenedUrlParams,
): Promise =>
shortenUrl(urlShortenerEndpoint, invoiceAccessToken, params).then(({ shortenedUrl }) => shortenedUrl);
@@ -36,7 +37,7 @@ export const createSessionInfo = async (
origin: string,
initConfig: { redirectUrl?: string; locale?: string },
{ invoice, invoiceAccessToken }: PayableInvoiceData,
- formValues: FormData
+ formValues: FormData,
): Promise => {
let redirectUrl;
const redirectUrlType = toRedirectUrlType(formValues, initConfig.redirectUrl);
@@ -48,9 +49,9 @@ export const createSessionInfo = async (
invoice.id,
invoiceAccessToken,
initConfig,
- isSkipUserInteractionParam(formValues.method)
+ isSkipUserInteractionParam(formValues.method),
),
- expiresAt: invoice.dueDate
+ expiresAt: invoice.dueDate,
});
break;
case 'outer':
diff --git a/src/app/hooks/create-payment/payer/to-contact-info.spec.ts b/src/app/hooks/create-payment/payer/to-contact-info.spec.ts
index e1cff0a9..6c9447b7 100644
--- a/src/app/hooks/create-payment/payer/to-contact-info.spec.ts
+++ b/src/app/hooks/create-payment/payer/to-contact-info.spec.ts
@@ -1,16 +1,17 @@
import { PaymentTerminalFormValues } from 'checkout/hooks';
+
import { toContactInfo } from './to-contact-info';
describe('toContactInfo', () => {
test('should return empty object', () => {
const initConfig = {
- someField1: 'someValue1'
+ someField1: 'someValue1',
} as any;
const formValues = {
amount: 'test',
metadata: {
- someField3: 'someValue1'
- }
+ someField3: 'someValue1',
+ },
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
@@ -21,15 +22,15 @@ describe('toContactInfo', () => {
test('should apply init config data', () => {
const initConfig = {
email: 'test@test.com',
- phoneNumber: '+79772223323'
+ phoneNumber: '+79772223323',
};
const formValues = {
metadata: {
email: 'meta-email@test.com',
- phoneNumber: 'metaPhoneNumber'
+ phoneNumber: 'metaPhoneNumber',
},
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
@@ -39,15 +40,15 @@ describe('toContactInfo', () => {
test('should apply metadata', () => {
const initConfig = {
email: null,
- phoneNumber: null
+ phoneNumber: null,
};
const formValues = {
metadata: {
email: 'meta-email@test.com',
- phoneNumber: 'metaPhoneNumber'
+ phoneNumber: 'metaPhoneNumber',
},
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
@@ -57,36 +58,36 @@ describe('toContactInfo', () => {
test('should apply metadata', () => {
const initConfig = {
email: null,
- phoneNumber: null
+ phoneNumber: null,
};
const formValues = {
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
expect(result).toStrictEqual({
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
});
});
test('should apply form value email', () => {
const initConfig = {
- phoneNumber: '+79772223323'
+ phoneNumber: '+79772223323',
} as any;
const formValues = {
metadata: {
email: 'meta-email@test.com',
- phoneNumber: 'metaPhoneNumber'
+ phoneNumber: 'metaPhoneNumber',
},
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
const expected = {
email: 'meta-email@test.com',
- phoneNumber: '+79772223323'
+ phoneNumber: '+79772223323',
};
expect(result).toStrictEqual(expected);
});
@@ -94,20 +95,20 @@ describe('toContactInfo', () => {
test('should apply form value phoneNumber', () => {
const initConfig = {
email: 'test@test.com',
- phoneNumber: null
+ phoneNumber: null,
};
const formValues = {
metadata: {
email: 'meta-email@test.com',
- phoneNumber: 'metaPhoneNumber'
+ phoneNumber: 'metaPhoneNumber',
},
- email: 'form-email@test.com'
+ email: 'form-email@test.com',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
const expected = {
email: 'test@test.com',
- phoneNumber: 'metaPhoneNumber'
+ phoneNumber: 'metaPhoneNumber',
};
expect(result).toStrictEqual(expected);
});
@@ -116,7 +117,7 @@ describe('toContactInfo', () => {
const initConfig = {} as any;
const formValues = {
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
@@ -128,14 +129,14 @@ describe('toContactInfo', () => {
const initConfig = {} as any;
const formValues = {
email: ' form-email@test.com',
- phoneNumber: 'formPhoneNumber '
+ phoneNumber: 'formPhoneNumber ',
} as PaymentTerminalFormValues;
const result = toContactInfo(initConfig, formValues);
expect(result).toStrictEqual({
email: 'form-email@test.com',
- phoneNumber: 'formPhoneNumber'
+ phoneNumber: 'formPhoneNumber',
});
});
});
diff --git a/src/app/hooks/create-payment/payer/to-contact-info.ts b/src/app/hooks/create-payment/payer/to-contact-info.ts
index 49f9723c..a932a815 100644
--- a/src/app/hooks/create-payment/payer/to-contact-info.ts
+++ b/src/app/hooks/create-payment/payer/to-contact-info.ts
@@ -1,7 +1,7 @@
-import replaceSpaces from 'checkout/utils/replace-spaces';
-import isNil from 'checkout/utils/is-nil';
-import { PayableFormValues, PaymentTerminalFormValues } from 'checkout/hooks';
import { ContactInfo } from 'checkout/backend';
+import { PayableFormValues, PaymentTerminalFormValues } from 'checkout/hooks';
+import isNil from 'checkout/utils/is-nil';
+import replaceSpaces from 'checkout/utils/replace-spaces';
const mapFrom = (obj: { email?: string; phoneNumber?: string }, targetKeys = ['email', 'phoneNumber']): ContactInfo => {
const defaultResult = {} as ContactInfo;
@@ -15,14 +15,14 @@ const mapFrom = (obj: { email?: string; phoneNumber?: string }, targetKeys = ['e
}
return {
...acc,
- [targetKey]: replaceSpaces(val)
+ [targetKey]: replaceSpaces(val),
};
}, defaultResult);
};
export const toContactInfo = (
initConfig: { email: string; phoneNumber: string },
- formValues: PayableFormValues
+ formValues: PayableFormValues,
): ContactInfo => {
const fromFormValues = mapFrom(formValues);
const fromMetadata = mapFrom((formValues as PaymentTerminalFormValues)?.metadata);
@@ -30,7 +30,7 @@ export const toContactInfo = (
const byPriority = {
...fromFormValues,
...fromMetadata,
- ...fromInitConfig
+ ...fromInitConfig,
};
return byPriority;
};
diff --git a/src/app/hooks/create-payment/payer/to-payment-tool.ts b/src/app/hooks/create-payment/payer/to-payment-tool.ts
index 9cef4bc8..191e2bb4 100644
--- a/src/app/hooks/create-payment/payer/to-payment-tool.ts
+++ b/src/app/hooks/create-payment/payer/to-payment-tool.ts
@@ -1,6 +1,7 @@
import { CardData, PaymentMethodName, PaymentTool, PaymentToolType } from 'checkout/backend';
import { CardFormValues, PaymentTerminalFormValues, WalletFormValues } from 'checkout/hooks';
import replaceSpaces from 'checkout/utils/replace-spaces';
+
import { FormData } from '../types';
const toPaymentToolBankCard = (values: CardFormValues): CardData => {
@@ -11,19 +12,19 @@ const toPaymentToolBankCard = (values: CardFormValues): CardData => {
cardNumber,
expDate,
cvv: values.secureCode,
- cardHolder: values.cardHolder
+ cardHolder: values.cardHolder,
};
};
const toPaymentToolDigitalWallet = (values: WalletFormValues) => ({
paymentToolType: PaymentToolType.DigitalWalletData,
- ...values
+ ...values,
});
const toPaymentToolTerminal = (values: PaymentTerminalFormValues) => ({
paymentToolType: PaymentToolType.PaymentTerminalData,
provider: values.provider,
- metadata: values.metadata
+ metadata: values.metadata,
});
export const toPaymentTool = (formValues: FormData): PaymentTool => {
diff --git a/src/app/hooks/create-payment/payer/to-self-redirect-url.ts b/src/app/hooks/create-payment/payer/to-self-redirect-url.ts
index 93f0976d..5d4f504c 100644
--- a/src/app/hooks/create-payment/payer/to-self-redirect-url.ts
+++ b/src/app/hooks/create-payment/payer/to-self-redirect-url.ts
@@ -5,12 +5,12 @@ export const toSelfRedirectUrl = (
invoiceID: string,
invoiceAccessToken: string,
{ redirectUrl, locale }: { redirectUrl?: string; locale?: string },
- skipUserInteraction: boolean
+ skipUserInteraction: boolean,
) =>
`${origin}/v1/checkout.html?${serializeUrlParams({
invoiceID,
invoiceAccessToken,
redirectUrl,
locale,
- skipUserInteraction
+ skipUserInteraction,
})}`;
diff --git a/src/app/hooks/create-payment/to-payment-flow.ts b/src/app/hooks/create-payment/to-payment-flow.ts
index 86e3fa62..a69ca345 100644
--- a/src/app/hooks/create-payment/to-payment-flow.ts
+++ b/src/app/hooks/create-payment/to-payment-flow.ts
@@ -1,8 +1,12 @@
import { FlowType, PaymentFlow } from 'checkout/backend';
+
import { PaymentFlowParams } from './types';
export const toPaymentFlow = ({ paymentFlowHold, holdExpiration }: PaymentFlowParams): PaymentFlow => {
- const hold = { type: FlowType.PaymentFlowHold, onHoldExpiration: holdExpiration };
+ const hold = {
+ type: FlowType.PaymentFlowHold,
+ onHoldExpiration: holdExpiration,
+ };
const instant = { type: FlowType.PaymentFlowInstant };
return paymentFlowHold ? hold : instant;
};
diff --git a/src/app/hooks/create-payment/types/index.ts b/src/app/hooks/create-payment/types/index.ts
index 9470f5e6..6a5d6af1 100644
--- a/src/app/hooks/create-payment/types/index.ts
+++ b/src/app/hooks/create-payment/types/index.ts
@@ -1,4 +1,5 @@
import { HoldExpirationType } from 'checkout/backend';
+
import { FormData } from './form-data';
export * from '../payer/types';
diff --git a/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.spec.ts b/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.spec.ts
index 549e4bcf..5afe5a37 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.spec.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.spec.ts
@@ -7,7 +7,7 @@ it('should return amount', () => {
cost: 100000,
price: 100000,
product: 'Product 1',
- quantity: 1
+ quantity: 1,
},
{
cost: 400000,
@@ -16,8 +16,8 @@ it('should return amount', () => {
quantity: 2,
taxMode: {
rate: '0%',
- type: 'InvoiceLineTaxVAT'
- }
+ type: 'InvoiceLineTaxVAT',
+ },
},
{
cost: 500000,
@@ -26,19 +26,19 @@ it('should return amount', () => {
quantity: 1,
taxMode: {
rate: '18%',
- type: 'InvoiceLineTaxVAT'
- }
- }
+ type: 'InvoiceLineTaxVAT',
+ },
+ },
],
currency: 'RUB',
- templateType: 'InvoiceTemplateMultiLine'
+ templateType: 'InvoiceTemplateMultiLine',
} as any;
const actual = getAmountFromMultiLine(multiLine, 'ru');
const expected = {
status: 'final',
currencyCode: 'RUB',
minorValue: 1000000,
- locale: 'ru'
+ locale: 'ru',
};
expect(actual).toEqual(expected);
});
diff --git a/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.ts b/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.ts
index 07e16d1f..294a2cec 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-from-multi-line.ts
@@ -1,9 +1,10 @@
import { InvoiceTemplateMultiLine } from 'checkout/backend';
+
import { AmountInfo } from './types';
export const getAmountFromMultiLine = (details: InvoiceTemplateMultiLine, locale: string): AmountInfo => ({
status: 'final',
minorValue: details.cart.reduce((p, c) => p + c.price * c.quantity, 0),
currencyCode: details.currency,
- locale
+ locale,
});
diff --git a/src/app/hooks/init-app/amount-info/get-amount-from-single-line.spec.ts b/src/app/hooks/init-app/amount-info/get-amount-from-single-line.spec.ts
index 726d0d24..9a50703e 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-from-single-line.spec.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-from-single-line.spec.ts
@@ -5,15 +5,15 @@ it('InvoiceTemplateLineCostFixed should return amount', () => {
price: {
costType: 'InvoiceTemplateLineCostFixed',
amount: 149900,
- currency: 'RUB'
- }
+ currency: 'RUB',
+ },
} as any;
const actual = getAmountFromSingleLine(singleLine, 111, 'ru');
const expected = {
status: 'final',
currencyCode: 'RUB',
locale: 'ru',
- minorValue: 149900
+ minorValue: 149900,
};
expect(actual).toEqual(expected);
});
@@ -24,10 +24,10 @@ describe('InvoiceTemplateLineCostRange', () => {
costType: 'InvoiceTemplateLineCostRange',
range: {
lowerBound: 1000,
- upperBound: 2000
+ upperBound: 2000,
},
- currency: 'RUB'
- }
+ currency: 'RUB',
+ },
} as any;
it('with amountConfig should return final status', () => {
@@ -36,7 +36,7 @@ describe('InvoiceTemplateLineCostRange', () => {
status: 'final',
currencyCode: 'RUB',
minorValue: 111,
- locale: 'ru'
+ locale: 'ru',
};
expect(actual).toEqual(expected);
});
@@ -47,7 +47,7 @@ describe('InvoiceTemplateLineCostRange', () => {
status: 'notKnown',
currencyCode: 'RUB',
locale: 'ru',
- minorValue: undefined
+ minorValue: undefined,
};
expect(actual).toEqual(expected);
});
@@ -56,8 +56,8 @@ describe('InvoiceTemplateLineCostRange', () => {
describe('InvoiceTemplateLineCostUnlim', () => {
const singleLine = {
price: {
- costType: 'InvoiceTemplateLineCostUnlim'
- }
+ costType: 'InvoiceTemplateLineCostUnlim',
+ },
} as any;
it('with amountConfig should return final status', () => {
@@ -66,7 +66,7 @@ describe('InvoiceTemplateLineCostUnlim', () => {
status: 'final',
currencyCode: 'RUB',
minorValue: 111,
- locale: 'ru'
+ locale: 'ru',
};
expect(actual).toEqual(expected);
});
@@ -76,7 +76,7 @@ describe('InvoiceTemplateLineCostUnlim', () => {
const expected = {
status: 'notKnown',
currencyCode: 'RUB',
- locale: 'ru'
+ locale: 'ru',
};
expect(actual).toEqual(expected);
});
diff --git a/src/app/hooks/init-app/amount-info/get-amount-from-single-line.ts b/src/app/hooks/init-app/amount-info/get-amount-from-single-line.ts
index 42d9f815..787df360 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-from-single-line.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-from-single-line.ts
@@ -1,10 +1,11 @@
-import isNumber from 'checkout/utils/is-number';
import {
CostType,
InvoiceTemplateLineCostFixed,
InvoiceTemplateLineCostRange,
- InvoiceTemplateSingleLine
+ InvoiceTemplateSingleLine,
} from 'checkout/backend/model';
+import isNumber from 'checkout/utils/is-number';
+
import { AmountInfo } from './types';
const getStatus = (configAmount: number) => (isNumber(configAmount) ? 'final' : 'notKnown');
@@ -12,7 +13,7 @@ const getStatus = (configAmount: number) => (isNumber(configAmount) ? 'final' :
export const getAmountFromSingleLine = (
details: InvoiceTemplateSingleLine,
configAmount: number,
- locale: string
+ locale: string,
): AmountInfo => {
const price = details.price;
if (!price) {
@@ -25,21 +26,21 @@ export const getAmountFromSingleLine = (
status: 'final',
minorValue: fixed.amount,
currencyCode: fixed.currency,
- locale
+ locale,
};
case CostType.InvoiceTemplateLineCostRange:
return {
status: getStatus(configAmount),
minorValue: configAmount || undefined,
currencyCode: (price as InvoiceTemplateLineCostRange).currency,
- locale
+ locale,
};
case CostType.InvoiceTemplateLineCostUnlim:
return {
status: getStatus(configAmount),
minorValue: configAmount || undefined,
currencyCode: 'RUB', // TODO unlim cost type does't support currency
- locale
+ locale,
};
}
};
diff --git a/src/app/hooks/init-app/amount-info/get-amount-info.spec.ts b/src/app/hooks/init-app/amount-info/get-amount-info.spec.ts
index a929ea23..572d3d7b 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-info.spec.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-info.spec.ts
@@ -1,5 +1,5 @@
-import { resolveInvoice } from './resolve-invoice';
import { getAmountInfo } from './get-amount-info';
+import { resolveInvoice } from './resolve-invoice';
import { resolveInvoiceTemplate } from './resolve-invoice-template';
jest.mock('./resolve-invoice');
@@ -10,10 +10,10 @@ const resolveInvoiceTemplateMock = resolveInvoiceTemplate as any;
it('invoice integration type should call resolveInvoice', () => {
const initConfig = {
- integrationType: 'invoice'
+ integrationType: 'invoice',
} as any;
const model = {
- invoice: 'invoiceMock'
+ invoice: 'invoiceMock',
} as any;
getAmountInfo(initConfig, model);
expect(resolveInvoiceMock.mock.calls.length).toBe(1);
@@ -23,10 +23,10 @@ it('invoice integration type should call resolveInvoice', () => {
it('invoice template integration type should call resolveInvoiceTemplate', () => {
const initConfig = {
integrationType: 'invoiceTemplate',
- amount: 999
+ amount: 999,
} as any;
const model = {
- invoiceTemplate: 'invoiceTemplateMock'
+ invoiceTemplate: 'invoiceTemplateMock',
} as any;
getAmountInfo(initConfig, model);
expect(resolveInvoiceTemplateMock.mock.calls.length).toBe(1);
diff --git a/src/app/hooks/init-app/amount-info/get-amount-info.ts b/src/app/hooks/init-app/amount-info/get-amount-info.ts
index 0660c628..6a7b1182 100644
--- a/src/app/hooks/init-app/amount-info/get-amount-info.ts
+++ b/src/app/hooks/init-app/amount-info/get-amount-info.ts
@@ -1,6 +1,7 @@
import { InitConfig } from 'checkout/config';
-import { resolveInvoiceTemplate } from './resolve-invoice-template';
+
import { resolveInvoice } from './resolve-invoice';
+import { resolveInvoiceTemplate } from './resolve-invoice-template';
import { AmountInfo } from './types';
import { Model } from '..';
diff --git a/src/app/hooks/init-app/amount-info/resolve-invoice-template.spec.ts b/src/app/hooks/init-app/amount-info/resolve-invoice-template.spec.ts
index 253cedd8..8b607124 100644
--- a/src/app/hooks/init-app/amount-info/resolve-invoice-template.spec.ts
+++ b/src/app/hooks/init-app/amount-info/resolve-invoice-template.spec.ts
@@ -1,8 +1,9 @@
-import { getAmountFromSingleLine } from './get-amount-from-single-line';
-import { getAmountFromMultiLine } from './get-amount-from-multi-line';
-import { resolveInvoiceTemplate } from './resolve-invoice-template';
import { TemplateType } from 'checkout/backend';
+import { getAmountFromMultiLine } from './get-amount-from-multi-line';
+import { getAmountFromSingleLine } from './get-amount-from-single-line';
+import { resolveInvoiceTemplate } from './resolve-invoice-template';
+
jest.mock('./get-amount-from-single-line');
jest.mock('./get-amount-from-multi-line');
@@ -12,8 +13,8 @@ const getAmountFromMultiLineMocked = getAmountFromMultiLine as any;
it('InvoiceTemplateSingleLine should call getAmountFromSingleLine', () => {
const singleLine = {
details: {
- templateType: TemplateType.InvoiceTemplateSingleLine
- }
+ templateType: TemplateType.InvoiceTemplateSingleLine,
+ },
} as any;
getAmountFromSingleLineMocked.mockReturnValueOnce(singleLine.details);
resolveInvoiceTemplate(singleLine, 111, 'ru');
@@ -23,8 +24,8 @@ it('InvoiceTemplateSingleLine should call getAmountFromSingleLine', () => {
it('InvoiceTemplateMultiLine should call getAmountFromMultiLine', () => {
const multiLine = {
details: {
- templateType: TemplateType.InvoiceTemplateMultiLine
- }
+ templateType: TemplateType.InvoiceTemplateMultiLine,
+ },
} as any;
getAmountFromMultiLineMocked.mockReturnValueOnce(multiLine.details);
resolveInvoiceTemplate(multiLine, 111, 'ru');
diff --git a/src/app/hooks/init-app/amount-info/resolve-invoice-template.ts b/src/app/hooks/init-app/amount-info/resolve-invoice-template.ts
index c48af2bc..7a09515a 100644
--- a/src/app/hooks/init-app/amount-info/resolve-invoice-template.ts
+++ b/src/app/hooks/init-app/amount-info/resolve-invoice-template.ts
@@ -1,12 +1,13 @@
import { InvoiceTemplate, InvoiceTemplateMultiLine, InvoiceTemplateSingleLine, TemplateType } from 'checkout/backend';
-import { getAmountFromSingleLine } from './get-amount-from-single-line';
+
import { getAmountFromMultiLine } from './get-amount-from-multi-line';
+import { getAmountFromSingleLine } from './get-amount-from-single-line';
import { AmountInfo } from './types';
export const resolveInvoiceTemplate = (
invoiceTemplate: InvoiceTemplate,
configAmount: number,
- locale: string
+ locale: string,
): AmountInfo => {
switch (invoiceTemplate.details.templateType) {
case TemplateType.InvoiceTemplateSingleLine:
diff --git a/src/app/hooks/init-app/amount-info/resolve-invoice.spec.ts b/src/app/hooks/init-app/amount-info/resolve-invoice.spec.ts
index 2af710ba..dd27cf84 100644
--- a/src/app/hooks/init-app/amount-info/resolve-invoice.spec.ts
+++ b/src/app/hooks/init-app/amount-info/resolve-invoice.spec.ts
@@ -3,14 +3,14 @@ import { resolveInvoice } from './resolve-invoice';
it('should return amount', () => {
const invoice = {
amount: 10000,
- currency: 'RUB'
+ currency: 'RUB',
} as any;
const actual = resolveInvoice(invoice, 'ru');
const expected = {
status: 'final',
currencyCode: 'RUB',
minorValue: 10000,
- locale: 'ru'
+ locale: 'ru',
};
expect(actual).toEqual(expected);
});
diff --git a/src/app/hooks/init-app/amount-info/resolve-invoice.ts b/src/app/hooks/init-app/amount-info/resolve-invoice.ts
index 42de3123..a5a2926d 100644
--- a/src/app/hooks/init-app/amount-info/resolve-invoice.ts
+++ b/src/app/hooks/init-app/amount-info/resolve-invoice.ts
@@ -1,9 +1,10 @@
import { Invoice } from 'checkout/backend';
+
import { AmountInfo } from './types';
export const resolveInvoice = ({ amount, currency }: Invoice, locale: string): AmountInfo => ({
status: 'final',
minorValue: amount,
currencyCode: currency,
- locale
+ locale,
});
diff --git a/src/app/hooks/init-app/fetch-model.ts b/src/app/hooks/init-app/fetch-model.ts
index 526b4ece..93ea2576 100644
--- a/src/app/hooks/init-app/fetch-model.ts
+++ b/src/app/hooks/init-app/fetch-model.ts
@@ -2,11 +2,11 @@ import {
getInvoiceByID,
getInvoicePaymentMethods,
getInvoiceTemplateByID,
- getInvoicePaymentMethodsByTemplateID
+ getInvoicePaymentMethodsByTemplateID,
} from 'checkout/backend';
+import { InitConfig } from 'checkout/config';
import { getServiceProviders } from './get-service-providers';
-import { InitConfig } from 'checkout/config';
import { Model } from './types';
type InvoiceTemplateParams = {
@@ -26,13 +26,13 @@ const isInvoiceTemplateParams = (params: InitConfig): params is InvoiceTemplateP
const resolveInvoiceTemplate = async (
endpoint: string,
- { invoiceTemplateID, invoiceTemplateAccessToken }: InvoiceTemplateParams
+ { invoiceTemplateID, invoiceTemplateAccessToken }: InvoiceTemplateParams,
): Promise => {
const invoiceTemplate = await getInvoiceTemplateByID(endpoint, invoiceTemplateAccessToken, invoiceTemplateID);
const paymentMethods = await getInvoicePaymentMethodsByTemplateID(
endpoint,
invoiceTemplateAccessToken,
- invoiceTemplateID
+ invoiceTemplateID,
);
const serviceProviders = await getServiceProviders(paymentMethods, endpoint, invoiceTemplateAccessToken);
return { paymentMethods, invoiceTemplate, serviceProviders };
diff --git a/src/app/hooks/init-app/get-service-providers.ts b/src/app/hooks/init-app/get-service-providers.ts
index d8f34b4f..cd79f655 100644
--- a/src/app/hooks/init-app/get-service-providers.ts
+++ b/src/app/hooks/init-app/get-service-providers.ts
@@ -3,14 +3,14 @@ import {
PaymentMethod,
PaymentMethodName,
PaymentTerminal,
- ServiceProvider
+ ServiceProvider,
} from 'checkout/backend';
import { logPrefix } from 'checkout/log-messages';
export async function getServiceProviderOrNull(
endpoint: string,
accessToken: string,
- id: string
+ id: string,
): Promise {
try {
return await getServiceProviderByID(endpoint, accessToken, id);
@@ -32,11 +32,11 @@ const providerIDsReducer = (result: string[], method: PaymentMethod): string[] =
export async function getServiceProviders(
paymentMethods: PaymentMethod[],
endpoint: string,
- accessToken: string
+ accessToken: string,
): Promise {
const providerIDs = paymentMethods.reduce(providerIDsReducer, []);
const serviceProvidersOrNull = await Promise.all(
- providerIDs.map((id) => getServiceProviderOrNull(endpoint, accessToken, id))
+ providerIDs.map((id) => getServiceProviderOrNull(endpoint, accessToken, id)),
);
return serviceProvidersOrNull.filter((provider) => provider !== null);
}
diff --git a/src/app/hooks/init-app/init-app.ts b/src/app/hooks/init-app/init-app.ts
index 9978885c..2c582cf8 100644
--- a/src/app/hooks/init-app/init-app.ts
+++ b/src/app/hooks/init-app/init-app.ts
@@ -1,8 +1,9 @@
import { getLocale } from 'checkout/backend';
-import { fetchModel } from './fetch-model';
-import { getAmountInfo } from './amount-info';
-import { initAvailablePaymentMethods } from './init-available-payment-methods';
import { InitParams } from 'checkout/initialize';
+
+import { getAmountInfo } from './amount-info';
+import { fetchModel } from './fetch-model';
+import { initAvailablePaymentMethods } from './init-available-payment-methods';
import { InitialData } from './types';
export const initApp = async ({ initConfig, appConfig, origin }: InitParams): Promise => {
@@ -17,6 +18,6 @@ export const initApp = async ({ initConfig, appConfig, origin }: InitParams): Pr
locale,
model,
amountInfo,
- availablePaymentMethods
+ availablePaymentMethods,
};
};
diff --git a/src/app/hooks/init-app/init-available-payment-methods/bank-card-to-methods/bank-card-to-methods.ts b/src/app/hooks/init-app/init-available-payment-methods/bank-card-to-methods/bank-card-to-methods.ts
index 674bb9c3..fe73475f 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/bank-card-to-methods/bank-card-to-methods.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/bank-card-to-methods/bank-card-to-methods.ts
@@ -1,8 +1,9 @@
-import { PaymentMethod as PaymentMethodState, PaymentMethodName as PaymentMethodNameState } from '../types';
import { InitConfig } from 'checkout/config';
+import { PaymentMethod as PaymentMethodState, PaymentMethodName as PaymentMethodNameState } from '../types';
+
export function bankCardToMethods(initConfig: InitConfig): PaymentMethodState[] {
- let result: PaymentMethodState[] = [];
+ const result: PaymentMethodState[] = [];
if (initConfig.bankCard) {
result.push({ name: PaymentMethodNameState.BankCard });
}
diff --git a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/filter-by-payment-method-providers.ts b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/filter-by-payment-method-providers.ts
index 9a5def2a..f9213c36 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/filter-by-payment-method-providers.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/filter-by-payment-method-providers.ts
@@ -1,7 +1,10 @@
import { ServiceProvider } from 'checkout/backend';
-const findByID = ({ id }: ServiceProvider) => (providerID: string) => providerID === id;
+const findByID =
+ ({ id }: ServiceProvider) =>
+ (providerID: string) =>
+ providerID === id;
-export const filterByPaymentMethodProviders = (paymentMethodProviderIDs: string[]) => (
- serviceProvider: ServiceProvider
-) => paymentMethodProviderIDs.find(findByID(serviceProvider));
+export const filterByPaymentMethodProviders =
+ (paymentMethodProviderIDs: string[]) => (serviceProvider: ServiceProvider) =>
+ paymentMethodProviderIDs.find(findByID(serviceProvider));
diff --git a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-digital-wallet-payment-methods.ts b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-digital-wallet-payment-methods.ts
index 3fdb8ebd..24055fee 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-digital-wallet-payment-methods.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-digital-wallet-payment-methods.ts
@@ -1,19 +1,20 @@
-import groupBy from 'checkout/utils/group-by';
import { DigitalWallet, METADATA_NAMESPACE, ServiceProvider } from 'checkout/backend';
+import { assertUnreachable } from 'checkout/utils';
+import groupBy from 'checkout/utils/group-by';
+
+import { filterByPaymentMethodProviders } from './filter-by-payment-method-providers';
import {
DigitalWalletPaymentMethod,
PaymentMethodName as PaymentMethodNameState,
- KnownDigitalWalletProviderCategories
+ KnownDigitalWalletProviderCategories,
} from '../types';
-import { assertUnreachable } from 'checkout/utils';
-import { filterByPaymentMethodProviders } from './filter-by-payment-method-providers';
const metadataReducer = (result: ServiceProvider[], serviceProvider: ServiceProvider): ServiceProvider[] =>
serviceProvider?.metadata?.[METADATA_NAMESPACE] ? result.concat(serviceProvider) : result;
const categoryReducer = (
result: ServiceProvider[],
- [category, serviceProviders]: [KnownDigitalWalletProviderCategories, ServiceProvider[]]
+ [category, serviceProviders]: [KnownDigitalWalletProviderCategories, ServiceProvider[]],
): ServiceProvider[] => {
switch (category) {
case KnownDigitalWalletProviderCategories.DigitalWallet:
@@ -30,7 +31,7 @@ export const getDigitalWalletPaymentMethods = (
serviceProviders: ServiceProvider[],
isMethod: boolean,
paymentFlowHold: boolean,
- recurring: boolean
+ recurring: boolean,
): DigitalWalletPaymentMethod[] => {
if (!isMethod) {
return [];
@@ -47,7 +48,7 @@ export const getDigitalWalletPaymentMethods = (
return [
{
name: PaymentMethodNameState.DigitalWallet,
- serviceProviders: reduced
- }
+ serviceProviders: reduced,
+ },
];
};
diff --git a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-terminals-payment-methods.ts b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-terminals-payment-methods.ts
index 744de78d..66c5ab89 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-terminals-payment-methods.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/get-payment-methods/get-terminals-payment-methods.ts
@@ -1,8 +1,9 @@
-import groupBy from 'checkout/utils/group-by';
-import { KnownProviderCategories, PaymentMethod, PaymentMethodName } from '../types';
import { PaymentTerminal, ServiceProvider } from 'checkout/backend';
import { assertUnreachable } from 'checkout/utils';
+import groupBy from 'checkout/utils/group-by';
+
import { filterByPaymentMethodProviders } from './filter-by-payment-method-providers';
+import { KnownProviderCategories, PaymentMethod, PaymentMethodName } from '../types';
interface InitConfigChunk {
onlineBanking: boolean;
@@ -14,54 +15,53 @@ interface InitConfigChunk {
recurring: boolean;
}
-const categoryReducer = ({ onlineBanking, netBanking, upi, terminalWallets, pix }: Partial) => (
- result: PaymentMethod[],
- [category, serviceProviders]: [KnownProviderCategories, ServiceProvider[]]
-) => {
- const paymentMethod = {
- name: PaymentMethodName.PaymentTerminal,
- category,
- serviceProviders
+const categoryReducer =
+ ({ onlineBanking, netBanking, upi, terminalWallets, pix }: Partial) =>
+ (result: PaymentMethod[], [category, serviceProviders]: [KnownProviderCategories, ServiceProvider[]]) => {
+ const paymentMethod = {
+ name: PaymentMethodName.PaymentTerminal,
+ category,
+ serviceProviders,
+ };
+ switch (category) {
+ case KnownProviderCategories.OnlineBanking:
+ if (onlineBanking) {
+ result = result.concat([paymentMethod]);
+ }
+ break;
+ case KnownProviderCategories.NetBanking:
+ if (netBanking) {
+ result = result.concat([paymentMethod]);
+ }
+ break;
+ case KnownProviderCategories.UPI:
+ if (upi) {
+ result = result.concat([paymentMethod]);
+ }
+ break;
+ case KnownProviderCategories.DigitalWallet:
+ if (terminalWallets) {
+ result = result.concat([paymentMethod]);
+ }
+ break;
+ case KnownProviderCategories.PIX:
+ if (pix) {
+ result = result.concat([paymentMethod]);
+ }
+ break;
+ case KnownProviderCategories.PaymentTerminal:
+ result = result.concat([paymentMethod]);
+ break;
+ default:
+ assertUnreachable(category);
+ }
+ return result;
};
- switch (category) {
- case KnownProviderCategories.OnlineBanking:
- if (onlineBanking) {
- result = result.concat([paymentMethod]);
- }
- break;
- case KnownProviderCategories.NetBanking:
- if (netBanking) {
- result = result.concat([paymentMethod]);
- }
- break;
- case KnownProviderCategories.UPI:
- if (upi) {
- result = result.concat([paymentMethod]);
- }
- break;
- case KnownProviderCategories.DigitalWallet:
- if (terminalWallets) {
- result = result.concat([paymentMethod]);
- }
- break;
- case KnownProviderCategories.PIX:
- if (pix) {
- result = result.concat([paymentMethod]);
- }
- break;
- case KnownProviderCategories.PaymentTerminal:
- result = result.concat([paymentMethod]);
- break;
- default:
- assertUnreachable(category);
- }
- return result;
-};
export const getTerminalsPaymentMethods = (
{ providers }: PaymentTerminal,
serviceProviders: ServiceProvider[],
- { paymentFlowHold, recurring, onlineBanking, netBanking, upi, terminalWallets, pix }: InitConfigChunk
+ { paymentFlowHold, recurring, onlineBanking, netBanking, upi, terminalWallets, pix }: InitConfigChunk,
): PaymentMethod[] => {
if (paymentFlowHold) {
return [];
@@ -71,5 +71,14 @@ export const getTerminalsPaymentMethods = (
}
const filtered = serviceProviders.filter(filterByPaymentMethodProviders(providers));
const groupedByCategory = Object.entries(groupBy(filtered, 'category'));
- return groupedByCategory.reduce(categoryReducer({ onlineBanking, netBanking, upi, terminalWallets, pix }), []);
+ return groupedByCategory.reduce(
+ categoryReducer({
+ onlineBanking,
+ netBanking,
+ upi,
+ terminalWallets,
+ pix,
+ }),
+ [],
+ );
};
diff --git a/src/app/hooks/init-app/init-available-payment-methods/init-available-payment-methods.ts b/src/app/hooks/init-app/init-available-payment-methods/init-available-payment-methods.ts
index 6a2a0350..f666bcbf 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/init-available-payment-methods.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/init-available-payment-methods.ts
@@ -1,6 +1,7 @@
import { InitConfig } from 'checkout/config';
-import { toAvailablePaymentMethods } from './to-available-payment-methods';
+
import { setPriority } from './set-priority';
+import { toAvailablePaymentMethods } from './to-available-payment-methods';
import { Model } from '..';
export const initAvailablePaymentMethods = (initConfig: InitConfig, { paymentMethods, serviceProviders }: Model) => {
diff --git a/src/app/hooks/init-app/init-available-payment-methods/set-priority.ts b/src/app/hooks/init-app/init-available-payment-methods/set-priority.ts
index 33ba2147..8fa35065 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/set-priority.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/set-priority.ts
@@ -1,6 +1,7 @@
-import { KnownProviderCategories, PaymentMethod, PaymentMethodName, PaymentTerminalPaymentMethod } from './types';
import { assertUnreachable } from 'checkout/utils';
+import { KnownProviderCategories, PaymentMethod, PaymentMethodName, PaymentTerminalPaymentMethod } from './types';
+
const getPriority = (method: PaymentMethod): number => {
switch (method.name) {
case PaymentMethodName.BankCard:
@@ -23,6 +24,7 @@ const getPriority = (method: PaymentMethod): number => {
default:
assertUnreachable(category);
}
+ break;
case PaymentMethodName.DigitalWallet:
return 8;
default:
@@ -33,5 +35,5 @@ const getPriority = (method: PaymentMethod): number => {
export const setPriority = (methods: PaymentMethod[]): PaymentMethod[] =>
methods.map((method) => ({
...method,
- priority: getPriority(method)
+ priority: getPriority(method),
}));
diff --git a/src/app/hooks/init-app/init-available-payment-methods/terminal-digital-wallet-reducer.ts b/src/app/hooks/init-app/init-available-payment-methods/terminal-digital-wallet-reducer.ts
index a27fc831..26a149be 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/terminal-digital-wallet-reducer.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/terminal-digital-wallet-reducer.ts
@@ -1,17 +1,18 @@
+import isNil from 'checkout/utils/is-nil';
+
import {
DigitalWalletPaymentMethod,
KnownProviderCategories,
PaymentMethod,
PaymentMethodName,
- PaymentTerminalPaymentMethod
+ PaymentTerminalPaymentMethod,
} from './types';
-import isNil from 'checkout/utils/is-nil';
export const terminalDigitalWalletReducer = (
acc: PaymentMethod[],
curr: PaymentMethod,
_index,
- methods: PaymentMethod[]
+ methods: PaymentMethod[],
) => {
if (curr.name === PaymentMethodName.PaymentTerminal) {
const paymentTerminal = curr as PaymentTerminalPaymentMethod;
@@ -25,7 +26,7 @@ export const terminalDigitalWalletReducer = (
if (curr.name === PaymentMethodName.DigitalWallet) {
const digitalWallet = curr as DigitalWalletPaymentMethod;
const paymentTerminal = methods.find(
- (m) => m.name === PaymentMethodName.PaymentTerminal
+ (m) => m.name === PaymentMethodName.PaymentTerminal,
) as PaymentTerminalPaymentMethod;
if (!isNil(paymentTerminal) && paymentTerminal.category === KnownProviderCategories.DigitalWallet) {
digitalWallet.serviceProviders = digitalWallet.serviceProviders.concat(paymentTerminal.serviceProviders);
diff --git a/src/app/hooks/init-app/init-available-payment-methods/to-available-payment-methods.ts b/src/app/hooks/init-app/init-available-payment-methods/to-available-payment-methods.ts
index 9ff7b885..fdb06394 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/to-available-payment-methods.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/to-available-payment-methods.ts
@@ -1,15 +1,16 @@
-import { PaymentMethod as PaymentMethodState } from './types';
import { DigitalWallet, PaymentMethod, PaymentMethodName, PaymentTerminal, ServiceProvider } from 'checkout/backend';
import { InitConfig } from 'checkout/config';
+import { assertUnreachable } from 'checkout/utils';
+
import { bankCardToMethods } from './bank-card-to-methods';
import { getDigitalWalletPaymentMethods, getTerminalsPaymentMethods } from './get-payment-methods';
-import { assertUnreachable } from 'checkout/utils';
import { terminalDigitalWalletReducer } from './terminal-digital-wallet-reducer';
+import { PaymentMethod as PaymentMethodState } from './types';
export function toAvailablePaymentMethods(
paymentMethods: PaymentMethod[],
initConfig: InitConfig,
- serviceProviders: ServiceProvider[]
+ serviceProviders: ServiceProvider[],
): PaymentMethodState[] {
let result: PaymentMethodState[] = [];
const { wallets, onlineBanking, netBanking, upi, terminalWallets, paymentFlowHold, recurring, pix } = initConfig;
@@ -26,8 +27,8 @@ export function toAvailablePaymentMethods(
serviceProviders,
wallets,
paymentFlowHold,
- recurring
- )
+ recurring,
+ ),
);
break;
case PaymentMethodName.PaymentTerminal:
@@ -39,8 +40,8 @@ export function toAvailablePaymentMethods(
terminalWallets,
paymentFlowHold,
recurring,
- pix
- })
+ pix,
+ }),
);
break;
default:
diff --git a/src/app/hooks/init-app/init-available-payment-methods/types/digital-wallet-payment-method.ts b/src/app/hooks/init-app/init-available-payment-methods/types/digital-wallet-payment-method.ts
index c62f8122..f880d88a 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/types/digital-wallet-payment-method.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/types/digital-wallet-payment-method.ts
@@ -1,4 +1,5 @@
import { ServiceProvider } from 'checkout/backend';
+
import { PaymentMethod } from './payment-method';
export interface DigitalWalletPaymentMethod extends PaymentMethod {
diff --git a/src/app/hooks/init-app/init-available-payment-methods/types/known-digital-wallet-provider-categories.ts b/src/app/hooks/init-app/init-available-payment-methods/types/known-digital-wallet-provider-categories.ts
index 9dce4150..5baa94b3 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/types/known-digital-wallet-provider-categories.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/types/known-digital-wallet-provider-categories.ts
@@ -1,3 +1,3 @@
export enum KnownDigitalWalletProviderCategories {
- DigitalWallet = 'digitalwallet'
+ DigitalWallet = 'digitalwallet',
}
diff --git a/src/app/hooks/init-app/init-available-payment-methods/types/known-provider-categories.ts b/src/app/hooks/init-app/init-available-payment-methods/types/known-provider-categories.ts
index 902f9088..e94522c7 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/types/known-provider-categories.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/types/known-provider-categories.ts
@@ -4,5 +4,5 @@ export enum KnownProviderCategories {
UPI = 'upi',
DigitalWallet = 'digitalwallet',
PIX = 'pix',
- PaymentTerminal = 'paymentterminal'
+ PaymentTerminal = 'paymentterminal',
}
diff --git a/src/app/hooks/init-app/init-available-payment-methods/types/payment-method-name.ts b/src/app/hooks/init-app/init-available-payment-methods/types/payment-method-name.ts
index 6b257fb5..78a5948c 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/types/payment-method-name.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/types/payment-method-name.ts
@@ -1,5 +1,5 @@
export enum PaymentMethodName {
BankCard = 'BankCard',
DigitalWallet = 'DigitalWallet',
- PaymentTerminal = 'PaymentTerminal'
+ PaymentTerminal = 'PaymentTerminal',
}
diff --git a/src/app/hooks/init-app/init-available-payment-methods/types/payment-terminal-payment-method.ts b/src/app/hooks/init-app/init-available-payment-methods/types/payment-terminal-payment-method.ts
index da836c19..8245821b 100644
--- a/src/app/hooks/init-app/init-available-payment-methods/types/payment-terminal-payment-method.ts
+++ b/src/app/hooks/init-app/init-available-payment-methods/types/payment-terminal-payment-method.ts
@@ -1,4 +1,5 @@
import { ServiceProvider } from 'checkout/backend';
+
import { KnownProviderCategories } from './known-provider-categories';
import { PaymentMethod } from './payment-method';
import { PaymentMethodName } from './payment-method-name';
diff --git a/src/app/hooks/init-app/types.ts b/src/app/hooks/init-app/types.ts
index 7545ebc8..6d5c185a 100644
--- a/src/app/hooks/init-app/types.ts
+++ b/src/app/hooks/init-app/types.ts
@@ -3,10 +3,11 @@ import {
Invoice,
InvoiceTemplate,
ServiceProvider,
- PaymentMethod as ApiPaymentMethod
+ PaymentMethod as ApiPaymentMethod,
} from 'checkout/backend';
import { InitConfig } from 'checkout/config';
import { Locale } from 'checkout/locale';
+
import { AmountInfo } from './amount-info';
import { PaymentMethod } from './init-available-payment-methods';
diff --git a/src/app/hooks/invoice-events/poll-invoice-events.spec.ts b/src/app/hooks/invoice-events/poll-invoice-events.spec.ts
index f3f3e395..25e26f68 100644
--- a/src/app/hooks/invoice-events/poll-invoice-events.spec.ts
+++ b/src/app/hooks/invoice-events/poll-invoice-events.spec.ts
@@ -1,10 +1,11 @@
import { InvoiceChangeType } from 'checkout/backend';
+
import { pollInvoiceEvents } from './poll-invoice-events';
const fetchValueMock = (result, status = 200, ok = true) => ({
status,
ok,
- json: async () => result
+ json: async () => result,
});
describe('pollInvoiceEvents', () => {
@@ -17,8 +18,8 @@ describe('pollInvoiceEvents', () => {
stopPollingTypes: [
InvoiceChangeType.InvoiceStatusChanged,
InvoiceChangeType.PaymentStatusChanged,
- InvoiceChangeType.PaymentInteractionRequested
- ]
+ InvoiceChangeType.PaymentInteractionRequested,
+ ],
};
const getEventsUrl = (capiEndpoint: string, invoiceID: string, eventID?: number, limit = 20) => {
const eventIDParam = eventID ? `&eventID=${eventID}` : '';
@@ -35,7 +36,7 @@ describe('pollInvoiceEvents', () => {
const delays = {
pollingTimeout: 300,
- apiMethodCall: 100
+ apiMethodCall: 100,
};
const result = await pollInvoiceEvents({ ...params, delays });
await delay(300); // for checking that after timeout there are no more api calls
@@ -43,7 +44,7 @@ describe('pollInvoiceEvents', () => {
expect(mockFetch).toHaveBeenCalledTimes(4);
const expected = {
- status: 'TIMEOUT'
+ status: 'TIMEOUT',
};
expect(result).toStrictEqual(expected);
});
@@ -56,23 +57,23 @@ describe('pollInvoiceEvents', () => {
changes: [
{
changeType: 'InvoiceCreated',
- invoice: 'invoice mock'
- }
+ invoice: 'invoice mock',
+ },
],
createdAt: '2023-05-25T17:31:57.248146Z',
- id: 1
+ id: 1,
},
{
changes: [
{
changeType: 'PaymentStarted',
- payment: 'payment mock'
- }
+ payment: 'payment mock',
+ },
],
createdAt: '2023-05-25T17:31:58.442598Z',
- id: 2
- }
- ])
+ id: 2,
+ },
+ ]),
);
mockFetch.mockResolvedValueOnce(fetchValueMock([]));
mockFetch.mockResolvedValueOnce(
@@ -82,19 +83,19 @@ describe('pollInvoiceEvents', () => {
{
changeType: 'PaymentInteractionRequested',
paymentID: '1',
- userInteraction: 'user interaction mock'
- }
+ userInteraction: 'user interaction mock',
+ },
],
createdAt: '2023-05-25T17:32:01.601868Z',
- id: 7
- }
- ])
+ id: 7,
+ },
+ ]),
);
global.fetch = mockFetch;
const delays = {
pollingTimeout: 100,
- apiMethodCall: 10
+ apiMethodCall: 10,
};
const result = await pollInvoiceEvents({ ...params, delays });
@@ -109,8 +110,8 @@ describe('pollInvoiceEvents', () => {
change: {
changeType: 'PaymentInteractionRequested',
paymentID: '1',
- userInteraction: 'user interaction mock'
- }
+ userInteraction: 'user interaction mock',
+ },
};
expect(result).toStrictEqual(expected);
});
@@ -124,9 +125,9 @@ describe('pollInvoiceEvents', () => {
{
changes: ['someChange_01', 'someChange_02'],
createdAt: '2023-05-25T17:31:58.442598Z',
- id: 19
- }
- ])
+ id: 19,
+ },
+ ]),
);
mockFetch.mockResolvedValueOnce(fetchValueMock([]));
mockFetch.mockResolvedValueOnce(
@@ -138,21 +139,25 @@ describe('pollInvoiceEvents', () => {
{
changeType: 'PaymentInteractionRequested',
paymentID: '1',
- userInteraction: 'user interaction mock'
- }
+ userInteraction: 'user interaction mock',
+ },
],
createdAt: '2023-05-25T17:32:01.601868Z',
- id: 21
- }
- ])
+ id: 21,
+ },
+ ]),
);
global.fetch = mockFetch;
const delays = {
pollingTimeout: 100,
- apiMethodCall: 10
+ apiMethodCall: 10,
};
- const result = await pollInvoiceEvents({ ...params, delays, ...{ eventID: 15 } });
+ const result = await pollInvoiceEvents({
+ ...params,
+ delays,
+ ...{ eventID: 15 },
+ });
expect(mockFetch).toHaveBeenCalledTimes(3);
expect(mockFetch).toHaveBeenCalledWith(getEventsUrl(capiEndpoint, invoiceID, 15), expect.any(Object));
@@ -165,8 +170,8 @@ describe('pollInvoiceEvents', () => {
change: {
changeType: 'PaymentInteractionRequested',
paymentID: '1',
- userInteraction: 'user interaction mock'
- }
+ userInteraction: 'user interaction mock',
+ },
};
expect(result).toStrictEqual(expected);
});
diff --git a/src/app/hooks/invoice-events/poll-invoice-events.ts b/src/app/hooks/invoice-events/poll-invoice-events.ts
index d309186c..53248022 100644
--- a/src/app/hooks/invoice-events/poll-invoice-events.ts
+++ b/src/app/hooks/invoice-events/poll-invoice-events.ts
@@ -7,7 +7,7 @@ const GET_INVOICE_EVENTS_LIMIT = 20;
const getChange = (
event: InvoiceEvent | undefined,
- stopPollingChangeTypes: InvoiceChangeType[]
+ stopPollingChangeTypes: InvoiceChangeType[],
): InvoiceChange | undefined => {
if (isNil(event) || isNil(event.changes)) {
return undefined;
@@ -28,7 +28,7 @@ const fetchEvents = async (params: PollInvoiceEventsParams, isStop: () => boolea
invoiceAccessToken,
invoiceID,
GET_INVOICE_EVENTS_LIMIT,
- eventID
+ eventID,
);
const lastEvent = last(events);
const change = getChange(lastEvent, stopPollingTypes);
@@ -36,7 +36,7 @@ const fetchEvents = async (params: PollInvoiceEventsParams, isStop: () => boolea
return {
status: 'POLLED',
eventID: lastEvent.id,
- change
+ change,
};
}
if (isStop()) {
@@ -74,7 +74,7 @@ export const pollInvoiceEvents = async (params: PollInvoiceEventsParams): Promis
if (isNil(result)) {
stopPolling = true;
return {
- status: 'TIMEOUT'
+ status: 'TIMEOUT',
};
}
return result;
diff --git a/src/app/hooks/modal/provide-interaction.ts b/src/app/hooks/modal/provide-interaction.ts
index 0397b54c..80c7961a 100644
--- a/src/app/hooks/modal/provide-interaction.ts
+++ b/src/app/hooks/modal/provide-interaction.ts
@@ -5,9 +5,9 @@ import {
PaymentToolDetailsType,
QrCodeDisplayRequest,
Redirect,
- ServiceProvider
+ ServiceProvider,
} from 'checkout/backend';
-import { InteractionModel } from './types/interaction-model';
+import { getMetadata } from 'checkout/components/ui/metadata/utils/get-metadata';
import {
EventInteractionObject,
ModalForms,
@@ -15,18 +15,19 @@ import {
ModalInteractionType,
ModalState,
QrCodeInteractionFormInfo,
- RedirectFormInfo
+ RedirectFormInfo,
} from 'checkout/hooks';
import isNil from 'checkout/utils/is-nil';
-import { getMetadata } from 'checkout/components/ui/metadata/utils/get-metadata';
+
+import { InteractionModel } from './types/interaction-model';
const toModalInteraction = (userInteraction: Redirect): ModalInteraction =>
new ModalInteraction(
{
type: ModalInteractionType.EventInteraction,
- request: userInteraction.request
+ request: userInteraction.request,
} as EventInteractionObject,
- true
+ true,
);
const providePaymentTerminalPaymentTool = (userInteraction: Redirect, serviceProvider: ServiceProvider) => {
@@ -48,7 +49,7 @@ const provideRedirect = (userInteraction: Redirect, activeServiceProvider: Servi
const provideQrCode = (
userInteraction: QrCodeDisplayRequest,
- activeServiceProvider: ServiceProvider | null
+ activeServiceProvider: ServiceProvider | null,
): ModalForms => {
let providerID = null;
if (activeServiceProvider) {
@@ -60,7 +61,7 @@ const provideQrCode = (
const getActiveServiceProvider = (
serviceProviders: ServiceProvider[],
- paymentToolDetails: PaymentToolDetails
+ paymentToolDetails: PaymentToolDetails,
): ServiceProvider | null => {
if (paymentToolDetails.detailsType === PaymentToolDetailsType.PaymentToolDetailsPaymentTerminal) {
const provider = (paymentToolDetails as PaymentToolDetailsPaymentTerminal).provider;
@@ -71,7 +72,7 @@ const getActiveServiceProvider = (
export const provideInteraction = (
serviceProviders: ServiceProvider[],
- { paymentToolDetails, userInteraction }: InteractionModel
+ { paymentToolDetails, userInteraction }: InteractionModel,
): ModalState => {
const activeServiceProvider = getActiveServiceProvider(serviceProviders, paymentToolDetails);
switch (userInteraction.interactionType) {
diff --git a/src/app/hooks/modal/to-initial-form.ts b/src/app/hooks/modal/to-initial-form.ts
index 39afdc74..dbe1c0b5 100644
--- a/src/app/hooks/modal/to-initial-form.ts
+++ b/src/app/hooks/modal/to-initial-form.ts
@@ -3,8 +3,10 @@ import {
KnownProviderCategories,
PaymentMethod,
PaymentMethodName,
- PaymentTerminalPaymentMethod
+ PaymentTerminalPaymentMethod,
} from 'checkout/hooks';
+import { assertUnreachable } from 'checkout/utils';
+
import {
CardFormInfo,
FormInfo,
@@ -12,9 +14,8 @@ import {
NoAvailablePaymentMethodFormInfo,
WalletProvidersFormInfo,
PaymentTerminalFormInfo,
- PaymentTerminalSelectorFormInfo
+ PaymentTerminalSelectorFormInfo,
} from './types';
-import { assertUnreachable } from 'checkout/utils';
const toPaymentTerminalForms = ({ category, serviceProviders }: PaymentTerminalPaymentMethod) => {
switch (category) {
diff --git a/src/app/hooks/modal/to-initial-state.ts b/src/app/hooks/modal/to-initial-state.ts
index 4fdcdddd..407860d6 100644
--- a/src/app/hooks/modal/to-initial-state.ts
+++ b/src/app/hooks/modal/to-initial-state.ts
@@ -1,7 +1,6 @@
-import { FormInfo, ModalForms, ModalState, NoAvailablePaymentMethodFormInfo, PaymentMethodsFormInfo } from './types';
-
-import { PaymentMethod } from '../init-app';
import { toInitialForm } from './to-initial-form';
+import { FormInfo, ModalForms, ModalState, NoAvailablePaymentMethodFormInfo, PaymentMethodsFormInfo } from './types';
+import { PaymentMethod } from '../init-app';
const toInitialModal = (formInfo: FormInfo[]): ModalForms => new ModalForms(formInfo, true);
diff --git a/src/app/hooks/modal/types/form-info/card-form-info.ts b/src/app/hooks/modal/types/form-info/card-form-info.ts
index fb5351d7..0f2c281c 100644
--- a/src/app/hooks/modal/types/form-info/card-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/card-form-info.ts
@@ -2,8 +2,6 @@ import { FormInfo, FormName } from './form-info';
import { PaymentStatus } from './payment-status';
export class CardFormInfo extends FormInfo {
- paymentStatus: PaymentStatus;
-
constructor(previous?: FormName) {
super(previous);
this.name = FormName.cardForm;
diff --git a/src/app/hooks/modal/types/form-info/form-info.ts b/src/app/hooks/modal/types/form-info/form-info.ts
index cbcd3714..17a5a64b 100644
--- a/src/app/hooks/modal/types/form-info/form-info.ts
+++ b/src/app/hooks/modal/types/form-info/form-info.ts
@@ -1,5 +1,5 @@
-import { Named } from '../named';
import { PaymentStatus } from './payment-status';
+import { Named } from '../named';
export enum FormName {
paymentMethods = 'paymentMethods',
@@ -11,7 +11,7 @@ export enum FormName {
redirectForm = 'redirectForm',
paymentTerminalForm = 'paymentTerminalForm',
paymentTerminalSelector = 'paymentTerminalSelector',
- qrCodeInteractionForm = 'qrCodeInteractionForm'
+ qrCodeInteractionForm = 'qrCodeInteractionForm',
}
export abstract class FormInfo implements Named {
diff --git a/src/app/hooks/modal/types/form-info/form-view-info.ts b/src/app/hooks/modal/types/form-info/form-view-info.ts
index 72c5ad05..7d626cbf 100644
--- a/src/app/hooks/modal/types/form-info/form-view-info.ts
+++ b/src/app/hooks/modal/types/form-info/form-view-info.ts
@@ -1,7 +1,7 @@
export enum SlideDirection {
right = 'slideRightAnimation',
left = 'slideLeftAnimation',
- none = 'none'
+ none = 'none',
}
export interface FormViewInfo {
diff --git a/src/app/hooks/modal/types/form-info/payment-status.ts b/src/app/hooks/modal/types/form-info/payment-status.ts
index 13fa113f..62db33f5 100644
--- a/src/app/hooks/modal/types/form-info/payment-status.ts
+++ b/src/app/hooks/modal/types/form-info/payment-status.ts
@@ -1,5 +1,5 @@
export enum PaymentStatus {
pristine = 'pristine',
started = 'started',
- needRetry = 'needRetry'
+ needRetry = 'needRetry',
}
diff --git a/src/app/hooks/modal/types/form-info/payment-terminal-form-info.ts b/src/app/hooks/modal/types/form-info/payment-terminal-form-info.ts
index f7c42e72..cdce8d3c 100644
--- a/src/app/hooks/modal/types/form-info/payment-terminal-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/payment-terminal-form-info.ts
@@ -6,7 +6,10 @@ export class PaymentTerminalFormInfo extends FormInfo {
active = true;
paymentStatus = PaymentStatus.pristine;
- constructor(public providerID: string, previous?: FormName) {
+ constructor(
+ public providerID: string,
+ previous?: FormName,
+ ) {
super(previous);
}
}
diff --git a/src/app/hooks/modal/types/form-info/payment-terminal-selector-form-info.ts b/src/app/hooks/modal/types/form-info/payment-terminal-selector-form-info.ts
index 44875a81..45a58022 100644
--- a/src/app/hooks/modal/types/form-info/payment-terminal-selector-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/payment-terminal-selector-form-info.ts
@@ -1,11 +1,15 @@
import { KnownProviderCategories } from 'checkout/hooks';
+
import { FormInfo, FormName } from './form-info';
export class PaymentTerminalSelectorFormInfo extends FormInfo {
name = FormName.paymentTerminalSelector;
active = true;
- constructor(public category: KnownProviderCategories, previous?: FormName) {
+ constructor(
+ public category: KnownProviderCategories,
+ previous?: FormName,
+ ) {
super(previous);
}
}
diff --git a/src/app/hooks/modal/types/form-info/qr-code-interaction-form-info.ts b/src/app/hooks/modal/types/form-info/qr-code-interaction-form-info.ts
index 71b864b1..d477f1e0 100644
--- a/src/app/hooks/modal/types/form-info/qr-code-interaction-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/qr-code-interaction-form-info.ts
@@ -1,8 +1,12 @@
import { QrCodeDisplayRequest } from 'checkout/backend';
+
import { FormInfo, FormName } from './form-info';
export class QrCodeInteractionFormInfo extends FormInfo {
- constructor(public request: QrCodeDisplayRequest, public providerID: string) {
+ constructor(
+ public request: QrCodeDisplayRequest,
+ public providerID: string,
+ ) {
super();
this.name = FormName.qrCodeInteractionForm;
this.active = true;
diff --git a/src/app/hooks/modal/types/form-info/redirect-form-info.ts b/src/app/hooks/modal/types/form-info/redirect-form-info.ts
index 476ef3e0..c2396512 100644
--- a/src/app/hooks/modal/types/form-info/redirect-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/redirect-form-info.ts
@@ -1,4 +1,5 @@
import { BrowserRequest } from 'checkout/backend';
+
import { FormInfo, FormName } from '../form-info';
export class RedirectFormInfo extends FormInfo {
diff --git a/src/app/hooks/modal/types/form-info/result-form-info.ts b/src/app/hooks/modal/types/form-info/result-form-info.ts
index f87ae6ff..c823d4aa 100644
--- a/src/app/hooks/modal/types/form-info/result-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/result-form-info.ts
@@ -1,10 +1,11 @@
import { InvoiceChange } from 'checkout/backend';
+
import { FormInfo, FormName } from '../form-info';
export enum ResultType {
hookError = 'hookError',
hookProcessed = 'hookProcessed',
- hookTimeout = 'hookTimeout'
+ hookTimeout = 'hookTimeout',
}
export type HookPayload = {
diff --git a/src/app/hooks/modal/types/form-info/wallet-form-info.ts b/src/app/hooks/modal/types/form-info/wallet-form-info.ts
index 21e2f5a9..deea1216 100644
--- a/src/app/hooks/modal/types/form-info/wallet-form-info.ts
+++ b/src/app/hooks/modal/types/form-info/wallet-form-info.ts
@@ -1,9 +1,9 @@
import { ServiceProvider } from 'checkout/backend';
+
import { FormInfo, FormName } from './form-info';
import { PaymentStatus } from './payment-status';
export class WalletFormInfo extends FormInfo {
- paymentStatus: PaymentStatus;
activeProvider: ServiceProvider;
constructor(activeProvider: ServiceProvider, previous?: FormName) {
diff --git a/src/app/hooks/modal/types/modal-forms.ts b/src/app/hooks/modal/types/modal-forms.ts
index aa391ee1..8035f10f 100644
--- a/src/app/hooks/modal/types/modal-forms.ts
+++ b/src/app/hooks/modal/types/modal-forms.ts
@@ -1,18 +1,18 @@
-import { ModalName, ModalState } from './modal-state';
-import { FormInfo, FormViewInfo, SlideDirection } from './form-info';
-
-export class ModalForms extends ModalState {
- formsInfo: FormInfo[];
- viewInfo: FormViewInfo;
-
- constructor(formsInfo: FormInfo[], active: boolean, inProcess = false) {
- super();
- this.name = ModalName.modalForms;
- this.viewInfo = {
- slideDirection: SlideDirection.none,
- inProcess
- };
- this.formsInfo = formsInfo;
- this.active = active;
- }
-}
+import { FormInfo, FormViewInfo, SlideDirection } from './form-info';
+import { ModalName, ModalState } from './modal-state';
+
+export class ModalForms extends ModalState {
+ formsInfo: FormInfo[];
+ viewInfo: FormViewInfo;
+
+ constructor(formsInfo: FormInfo[], active: boolean, inProcess = false) {
+ super();
+ this.name = ModalName.modalForms;
+ this.viewInfo = {
+ slideDirection: SlideDirection.none,
+ inProcess,
+ };
+ this.formsInfo = formsInfo;
+ this.active = active;
+ }
+}
diff --git a/src/app/hooks/modal/types/modal-interaction.ts b/src/app/hooks/modal/types/modal-interaction.ts
index 22c7c207..71651374 100644
--- a/src/app/hooks/modal/types/modal-interaction.ts
+++ b/src/app/hooks/modal/types/modal-interaction.ts
@@ -1,9 +1,10 @@
-import { ModalName, ModalState } from './modal-state';
import { BrowserRequest } from 'checkout/backend';
+import { ModalName, ModalState } from './modal-state';
+
export enum ModalInteractionType {
TokenizedInteraction = 'TokenizedInteraction',
- EventInteraction = 'EventInteraction'
+ EventInteraction = 'EventInteraction',
}
interface InteractionObject {
diff --git a/src/app/hooks/modal/types/modal-state.ts b/src/app/hooks/modal/types/modal-state.ts
index 6be6f1f5..92e29ab5 100644
--- a/src/app/hooks/modal/types/modal-state.ts
+++ b/src/app/hooks/modal/types/modal-state.ts
@@ -2,7 +2,7 @@ import { Named } from './named';
export enum ModalName {
modalInteraction = 'modalInteraction',
- modalForms = 'modalForms'
+ modalForms = 'modalForms',
}
export abstract class ModalState implements Named {
diff --git a/src/app/hooks/use-create-payment.ts b/src/app/hooks/use-create-payment.ts
index aa70947b..e7f3da16 100644
--- a/src/app/hooks/use-create-payment.ts
+++ b/src/app/hooks/use-create-payment.ts
@@ -1,9 +1,9 @@
import { useContext, useCallback, useReducer } from 'react';
import isNil from 'checkout/utils/is-nil';
+
import { createInvoiceWithTemplate, createPayment } from './create-payment';
import { FormData } from './create-payment';
-
import { InitialContext } from '../components/app/initial-context';
import { PayableInvoiceContext } from '../components/app/modal-container/payable-invoice-context';
@@ -16,13 +16,13 @@ const dataReducer = (state: State, action: Action): State => {
case 'CREATE_PAYMENT_SUCCESS':
return {
...state,
- status: 'SUCCESS'
+ status: 'SUCCESS',
};
case 'CREATE_PAYMENT_FAILURE':
return {
...state,
status: 'FAILURE',
- error: action.error
+ error: action.error,
};
}
};
@@ -33,12 +33,12 @@ export const useCreatePayment = () => {
appConfig,
model: { invoiceTemplate },
amountInfo,
- origin
+ origin,
} = useContext(InitialContext);
const { payableInvoiceData, setPayableInvoiceData } = useContext(PayableInvoiceContext);
const [createPaymentState, dispatch] = useReducer(dataReducer, {
- status: 'PRISTINE'
+ status: 'PRISTINE',
});
const setFormData = useCallback(
@@ -52,7 +52,7 @@ export const useCreatePayment = () => {
invoiceTemplateAccessToken: initConfig.invoiceTemplateAccessToken,
invoiceTemplate,
amountInfo,
- formAmount: formData.values?.amount
+ formAmount: formData.values?.amount,
});
setPayableInvoiceData(data);
}
@@ -69,10 +69,10 @@ export const useCreatePayment = () => {
holdExpiration: initConfig.holdExpiration,
recurring: initConfig.recurring,
metadata: initConfig.metadata,
- isExternalIDIncluded: initConfig.isExternalIDIncluded
+ isExternalIDIncluded: initConfig.isExternalIDIncluded,
},
formData,
- payableInvoice: data
+ payableInvoice: data,
});
dispatch({ type: 'CREATE_PAYMENT_SUCCESS' });
} catch (error) {
@@ -82,7 +82,7 @@ export const useCreatePayment = () => {
};
fetchData();
},
- [payableInvoiceData]
+ [payableInvoiceData],
);
return { createPaymentState, setFormData };
diff --git a/src/app/hooks/use-init-app.test.ts b/src/app/hooks/use-init-app.test.ts
index 3bcf0b42..9d898b0e 100644
--- a/src/app/hooks/use-init-app.test.ts
+++ b/src/app/hooks/use-init-app.test.ts
@@ -1,17 +1,18 @@
import { act, renderHook } from '@testing-library/react';
-import { useInitApp } from './use-init-app';
import { PaymentMethodName } from 'checkout/backend';
+import { useInitApp } from './use-init-app';
+
const fetchMock = (result, status = 200, ok = true) =>
Promise.resolve({
status,
ok,
- json: () => Promise.resolve(result)
+ json: () => Promise.resolve(result),
});
const getLocaleMock = fetchMock({
- 'mock.locale.key': 'Mock locale value'
+ 'mock.locale.key': 'Mock locale value',
});
describe('useInitApp', () => {
@@ -20,8 +21,8 @@ describe('useInitApp', () => {
category: 'onlinebanking',
id: 'providerID_001',
metadata: {
- 'dev.vality.checkout': {}
- }
+ 'dev.vality.checkout': {},
+ },
});
const getServiceProviderByIdMock_002 = fetchMock({
@@ -29,31 +30,35 @@ describe('useInitApp', () => {
category: 'pix',
id: 'providerID_002',
metadata: {
- 'dev.vality.checkout': {}
- }
+ 'dev.vality.checkout': {},
+ },
});
describe('init with invoice template', () => {
const getInvoiceTemplateMock = fetchMock({
createdAt: '2023-05-10T08:34:22.263596Z',
details: {
- price: { amount: 100, costType: 'InvoiceTemplateLineCostFixed', currency: 'USD' },
+ price: {
+ amount: 100,
+ costType: 'InvoiceTemplateLineCostFixed',
+ currency: 'USD',
+ },
product: 'test',
- templateType: 'InvoiceTemplateSingleLine'
+ templateType: 'InvoiceTemplateSingleLine',
},
id: '1n1ELRnJcBP',
lifetime: { days: 21, months: 5, years: 0 },
- shopID: '000rrrrr-0000-0000-0000-45388402c928'
+ shopID: '000rrrrr-0000-0000-0000-45388402c928',
});
const getInvoicePaymentMethodsByTemplateIdMock = fetchMock([
{
- method: PaymentMethodName.BankCard
+ method: PaymentMethodName.BankCard,
},
{
method: PaymentMethodName.PaymentTerminal,
- providers: ['providerID_001', 'providerID_002']
- }
+ providers: ['providerID_001', 'providerID_002'],
+ },
]);
test('should success init', async () => {
@@ -82,7 +87,7 @@ describe('useInitApp', () => {
await act(async () =>
result.current.init({
appConfig: {
- capiEndpoint: 'https://api.test.com'
+ capiEndpoint: 'https://api.test.com',
},
initConfig: {
integrationType: 'invoiceTemplate',
@@ -91,10 +96,10 @@ describe('useInitApp', () => {
locale: 'en',
bankCard: true,
onlineBanking: true,
- pix: true
+ pix: true,
},
- origin: 'https://checkout.test.com'
- })
+ origin: 'https://checkout.test.com',
+ }),
);
const state = result.current.state;
expect(state.status).toBe('SUCCESS');
@@ -108,7 +113,7 @@ describe('useInitApp', () => {
locale: 'en',
bankCard: true,
onlineBanking: true,
- pix: true
+ pix: true,
},
appConfig: { capiEndpoint: 'https://api.test.com' },
origin: 'https://checkout.test.com',
@@ -116,35 +121,47 @@ describe('useInitApp', () => {
model: {
paymentMethods: [
{ method: 'BankCard' },
- { method: 'PaymentTerminal', providers: ['providerID_001', 'providerID_002'] }
+ {
+ method: 'PaymentTerminal',
+ providers: ['providerID_001', 'providerID_002'],
+ },
],
invoiceTemplate: {
createdAt: '2023-05-10T08:34:22.263596Z',
details: {
- price: { amount: 100, costType: 'InvoiceTemplateLineCostFixed', currency: 'USD' },
+ price: {
+ amount: 100,
+ costType: 'InvoiceTemplateLineCostFixed',
+ currency: 'USD',
+ },
product: 'test',
- templateType: 'InvoiceTemplateSingleLine'
+ templateType: 'InvoiceTemplateSingleLine',
},
id: '1n1ELRnJcBP',
lifetime: { days: 21, months: 5, years: 0 },
- shopID: '000rrrrr-0000-0000-0000-45388402c928'
+ shopID: '000rrrrr-0000-0000-0000-45388402c928',
},
serviceProviders: [
{
brandName: 'Provider Brand Name 1',
category: 'onlinebanking',
id: 'providerID_001',
- metadata: { 'dev.vality.checkout': {} }
+ metadata: { 'dev.vality.checkout': {} },
},
{
brandName: 'Provider Brand Name 2',
category: 'pix',
id: 'providerID_002',
- metadata: { 'dev.vality.checkout': {} }
- }
- ]
+ metadata: { 'dev.vality.checkout': {} },
+ },
+ ],
+ },
+ amountInfo: {
+ status: 'final',
+ minorValue: 100,
+ currencyCode: 'USD',
+ locale: 'en',
},
- amountInfo: { status: 'final', minorValue: 100, currencyCode: 'USD', locale: 'en' },
availablePaymentMethods: [
{ name: 'BankCard', priority: 1 },
{
@@ -155,10 +172,10 @@ describe('useInitApp', () => {
brandName: 'Provider Brand Name 1',
category: 'onlinebanking',
id: 'providerID_001',
- metadata: { 'dev.vality.checkout': {} }
- }
+ metadata: { 'dev.vality.checkout': {} },
+ },
],
- priority: 3
+ priority: 3,
},
{
name: 'PaymentTerminal',
@@ -168,12 +185,12 @@ describe('useInitApp', () => {
brandName: 'Provider Brand Name 2',
category: 'pix',
id: 'providerID_002',
- metadata: { 'dev.vality.checkout': {} }
- }
+ metadata: { 'dev.vality.checkout': {} },
+ },
],
- priority: 7
- }
- ]
+ priority: 7,
+ },
+ ],
};
expect(state.data).toStrictEqual(expected);
@@ -193,7 +210,7 @@ describe('useInitApp', () => {
await act(async () =>
result.current.init({
appConfig: {
- capiEndpoint: 'https://api.test.com'
+ capiEndpoint: 'https://api.test.com',
},
initConfig: {
integrationType: 'invoiceTemplate',
@@ -202,16 +219,20 @@ describe('useInitApp', () => {
locale: 'en',
bankCard: true,
onlineBanking: true,
- pix: true
+ pix: true,
},
- origin: 'https://checkout.test.com'
- })
+ origin: 'https://checkout.test.com',
+ }),
);
const state = result.current.state;
expect(state.status).toBe('FAILURE');
expect(errorSpy).toHaveBeenCalled();
if (state.status !== 'FAILURE') return;
- expect(state.error).toStrictEqual({ details: errorMsg, status: 500, statusText: undefined });
+ expect(state.error).toStrictEqual({
+ details: errorMsg,
+ status: 500,
+ statusText: undefined,
+ });
});
});
@@ -227,19 +248,19 @@ describe('useInitApp', () => {
metadata: {},
product: 'test',
shopID: 'cb323cb7-2abc-4626-a786-b70d8abbd0ec',
- status: 'unpaid'
+ status: 'unpaid',
};
const getInvoiceMock = fetchMock(invoice);
const getInvoicePaymentMethodsByTemplateIdMock = fetchMock([
{
- method: PaymentMethodName.BankCard
+ method: PaymentMethodName.BankCard,
},
{
method: PaymentMethodName.PaymentTerminal,
- providers: ['providerID_001', 'providerID_002']
- }
+ providers: ['providerID_001', 'providerID_002'],
+ },
]);
test('should success init', async () => {
@@ -268,7 +289,7 @@ describe('useInitApp', () => {
await act(async () =>
result.current.init({
appConfig: {
- capiEndpoint: 'https://api.test.com'
+ capiEndpoint: 'https://api.test.com',
},
initConfig: {
integrationType: 'invoice',
@@ -277,10 +298,10 @@ describe('useInitApp', () => {
locale: 'en',
bankCard: true,
onlineBanking: true,
- pix: true
+ pix: true,
},
- origin: 'https://checkout.test.com'
- })
+ origin: 'https://checkout.test.com',
+ }),
);
const state = result.current.state;
expect(state.status).toBe('SUCCESS');
@@ -294,7 +315,7 @@ describe('useInitApp', () => {
locale: 'en',
bankCard: true,
onlineBanking: true,
- pix: true
+ pix: true,
},
appConfig: { capiEndpoint: 'https://api.test.com' },
origin: 'https://checkout.test.com',
@@ -302,11 +323,21 @@ describe('useInitApp', () => {
model: {
paymentMethods: [
{ method: 'BankCard' },
- { method: 'PaymentTerminal', providers: ['providerID_001', 'providerID_002'] }
+ {
+ method: 'PaymentTerminal',
+ providers: ['providerID_001', 'providerID_002'],
+ },
],
invoice: {
amount: 100000,
- cart: [{ cost: 100000, price: 100000, product: 'test', quantity: 1 }],
+ cart: [
+ {
+ cost: 100000,
+ price: 100000,
+ product: 'test',
+ quantity: 1,
+ },
+ ],
createdAt: '2023-05-11T12:14:44.001097Z',
currency: 'RUB',
description: '',
@@ -315,25 +346,30 @@ describe('useInitApp', () => {
metadata: {},
product: 'test',
shopID: 'cb323cb7-2abc-4626-a786-b70d8abbd0ec',
- status: 'unpaid'
+ status: 'unpaid',
},
serviceProviders: [
{
brandName: 'Provider Brand Name 1',
category: 'onlinebanking',
id: 'providerID_001',
- metadata: { 'dev.vality.checkout': {} }
+ metadata: { 'dev.vality.checkout': {} },
},
{
brandName: 'Provider Brand Name 2',
category: 'pix',
id: 'providerID_002',
- metadata: { 'dev.vality.checkout': {} }
- }
+ metadata: { 'dev.vality.checkout': {} },
+ },
],
- invoiceAccessToken: 'eyJhbGciOiJ...'
+ invoiceAccessToken: 'eyJhbGciOiJ...',
+ },
+ amountInfo: {
+ status: 'final',
+ minorValue: 100000,
+ currencyCode: 'RUB',
+ locale: 'en',
},
- amountInfo: { status: 'final', minorValue: 100000, currencyCode: 'RUB', locale: 'en' },
availablePaymentMethods: [
{ name: 'BankCard', priority: 1 },
{
@@ -344,10 +380,10 @@ describe('useInitApp', () => {
brandName: 'Provider Brand Name 1',
category: 'onlinebanking',
id: 'providerID_001',
- metadata: { 'dev.vality.checkout': {} }
- }
+ metadata: { 'dev.vality.checkout': {} },
+ },
],
- priority: 3
+ priority: 3,
},
{
name: 'PaymentTerminal',
@@ -357,12 +393,12 @@ describe('useInitApp', () => {
brandName: 'Provider Brand Name 2',
category: 'pix',
id: 'providerID_002',
- metadata: { 'dev.vality.checkout': {} }
- }
+ metadata: { 'dev.vality.checkout': {} },
+ },
],
- priority: 7
- }
- ]
+ priority: 7,
+ },
+ ],
};
expect(state.data).toStrictEqual(expected);
diff --git a/src/app/hooks/use-init-app.ts b/src/app/hooks/use-init-app.ts
index 57308ace..cef1f88b 100644
--- a/src/app/hooks/use-init-app.ts
+++ b/src/app/hooks/use-init-app.ts
@@ -1,6 +1,7 @@
import { useCallback, useReducer } from 'react';
import { InitParams } from 'checkout/initialize';
+
import { InitialData, initApp } from './init-app';
type State =
@@ -16,21 +17,21 @@ const dataFetchReducer = (state: State, action: Action): State => {
return {
...state,
status: 'SUCCESS',
- data: action.payload
+ data: action.payload,
};
case 'APP_INIT_FAILURE':
return {
...state,
status: 'FAILURE',
error: action.error,
- data: null
+ data: null,
};
}
};
export const useInitApp = () => {
const [state, dispatch] = useReducer(dataFetchReducer, {
- status: 'PRISTINE'
+ status: 'PRISTINE',
});
const init = useCallback((initParams: InitParams) => {
@@ -39,7 +40,7 @@ export const useInitApp = () => {
const payload = await initApp(initParams);
dispatch({
type: 'APP_INIT_SUCCESS',
- payload
+ payload,
});
} catch (error) {
dispatch({ type: 'APP_INIT_FAILURE', error });
diff --git a/src/app/hooks/use-invoice-events.ts b/src/app/hooks/use-invoice-events.ts
index 85c16692..223fb5d0 100644
--- a/src/app/hooks/use-invoice-events.ts
+++ b/src/app/hooks/use-invoice-events.ts
@@ -1,9 +1,11 @@
import { useCallback, useEffect, useReducer, useState } from 'react';
-import isNil from 'checkout/utils/is-nil';
-import { PayableInvoiceData } from './create-payment';
-import { PollingResult, pollInvoiceEvents } from './invoice-events';
+
import { InvoiceChange, InvoiceChangeType, getInvoiceEvents } from 'checkout/backend';
import { findChange } from 'checkout/utils/event-utils';
+import isNil from 'checkout/utils/is-nil';
+
+import { PayableInvoiceData } from './create-payment';
+import { PollingResult, pollInvoiceEvents } from './invoice-events';
const API_METHOD_CALL_MS = 1000;
const DEFAULT_TIMEOUT_MS = 60 * 1000 * 10;
@@ -27,28 +29,28 @@ const dataReducer = (_state: State, action: Action): State => {
case 'SET_FAILURE':
return {
status: 'FAILURE',
- error: action.error
+ error: action.error,
};
case 'POLL_EVENTS_TIMEOUT':
return {
- status: 'POLLING_TIMEOUT'
+ status: 'POLLING_TIMEOUT',
};
case 'SET_POLLING_RESULT':
return {
status: 'POLLING_SUCCESS',
- payload: action.payload
+ payload: action.payload,
};
case 'SET_SEARCH_RESULT':
return {
status: 'EVENT_CHANGE_FOUND',
- payload: action.payload
+ payload: action.payload,
};
}
};
export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData) => {
const [eventsState, dispatch] = useReducer(dataReducer, {
- status: 'PRISTINE'
+ status: 'PRISTINE',
});
const [pollingResult, setPollingResult] = useState(null);
@@ -66,13 +68,13 @@ export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData)
InvoiceChangeType.PaymentStarted,
InvoiceChangeType.InvoiceStatusChanged,
InvoiceChangeType.PaymentStatusChanged,
- InvoiceChangeType.PaymentInteractionRequested
+ InvoiceChangeType.PaymentInteractionRequested,
],
delays: {
pollingTimeout,
- apiMethodCall: API_METHOD_CALL_MS
+ apiMethodCall: API_METHOD_CALL_MS,
},
- eventID
+ eventID,
});
setPollingResult(pollingResult);
} catch (error) {
@@ -82,7 +84,7 @@ export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData)
};
fetchData();
},
- [capiEndpoint, data]
+ [capiEndpoint, data],
);
useEffect(() => {
@@ -97,7 +99,10 @@ export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData)
startPolling(pollingResult.eventID, PAYMENT_STARTED_TIMEOUT_MS);
} else {
startPolling(pollingResult.eventID);
- dispatch({ type: 'SET_POLLING_RESULT', payload: pollingResult.change });
+ dispatch({
+ type: 'SET_POLLING_RESULT',
+ payload: pollingResult.change,
+ });
}
break;
}
@@ -115,7 +120,7 @@ export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData)
} else {
dispatch({
type: 'SET_FAILURE',
- error: new Error(`Event change: "${foundType}" is not found`)
+ error: new Error(`Event change: "${foundType}" is not found`),
});
}
} catch (error) {
@@ -125,7 +130,7 @@ export const useInvoiceEvents = (capiEndpoint: string, data: PayableInvoiceData)
};
fetchData();
},
- [capiEndpoint, data]
+ [capiEndpoint, data],
);
return { eventsState, startPolling, searchEventsChange };
diff --git a/src/app/hooks/use-modal.ts b/src/app/hooks/use-modal.ts
index 8225fd7d..9135e29a 100644
--- a/src/app/hooks/use-modal.ts
+++ b/src/app/hooks/use-modal.ts
@@ -1,4 +1,11 @@
import { useCallback, useReducer } from 'react';
+
+import { ServiceProvider } from 'checkout/backend';
+import { InitConfig } from 'checkout/config';
+import { findNamed } from 'checkout/utils';
+
+import { PaymentMethod } from './init-app';
+import { InteractionModel, provideInteraction, toInitialState } from './modal';
import {
FormInfo,
ModalForms,
@@ -7,20 +14,14 @@ import {
Named,
PaymentMethodsFormInfo,
PaymentStatus,
- SlideDirection
+ SlideDirection,
} from './modal/types';
-import { PaymentMethod } from './init-app';
-import { InteractionModel, provideInteraction, toInitialState } from './modal';
-import { InitConfig } from 'checkout/config';
-import { findNamed } from 'checkout/utils';
-import { ServiceProvider } from 'checkout/backend';
-
type State = ModalState[];
export enum Direction {
back = 'back',
- forward = 'forward'
+ forward = 'forward',
}
type Action =
@@ -91,12 +92,12 @@ const updateFound = (s: ModalState[], found: ModalForms, formInfo: FormInfo, dir
viewInfo: {
...found.viewInfo,
inProcess: false,
- slideDirection: toSlideDirection(direction)
+ slideDirection: toSlideDirection(direction),
},
formsInfo: addOrUpdate(found.formsInfo, {
...formInfo,
- active: true
- } as FormInfo)
+ active: true,
+ } as FormInfo),
} as ModalForms);
};
@@ -114,8 +115,8 @@ const setActiveToPristine = (s: ModalState[]): ModalState[] => {
...modal,
formsInfo: addOrUpdate(modal.formsInfo, {
...started,
- paymentStatus: PaymentStatus.pristine
- } as FormInfo)
+ paymentStatus: PaymentStatus.pristine,
+ } as FormInfo),
} as ModalForms)
: s;
};
@@ -127,12 +128,12 @@ const prepareToPay = (s: ModalState[]): ModalState[] => {
...modal,
viewInfo: {
...modal.viewInfo,
- inProcess: true
+ inProcess: true,
},
formsInfo: addOrUpdate(modal.formsInfo, {
...active,
- paymentStatus: PaymentStatus.started
- } as FormInfo)
+ paymentStatus: PaymentStatus.started,
+ } as FormInfo),
} as ModalForms);
};
@@ -142,8 +143,8 @@ const updateViewInfo = (s: ModalState[], field: string, value: any): ModalState[
...modal,
viewInfo: {
...modal.viewInfo,
- [field]: value
- }
+ [field]: value,
+ },
} as ModalForms);
};
@@ -156,13 +157,13 @@ const prepareToRetry = (s: ModalState[], toPristine: boolean): ModalState[] => {
...modal,
viewInfo: {
...modal.viewInfo,
- slideDirection: SlideDirection.left
+ slideDirection: SlideDirection.left,
},
formsInfo: addOrUpdate(modal.formsInfo, {
...started,
paymentStatus: toPristine ? PaymentStatus.pristine : PaymentStatus.needRetry,
- active: true
- } as FormInfo)
+ active: true,
+ } as FormInfo),
} as ModalForms);
};
@@ -171,16 +172,16 @@ const forgetPaymentAttempt = (s: ModalState[]) => {
const pristine = addOrUpdate(modal.formsInfo, {
...findStarted(modal.formsInfo),
paymentStatus: PaymentStatus.pristine,
- active: false
+ active: false,
} as FormInfo);
return addOrUpdate(s, {
...modal,
viewInfo: {
...modal.viewInfo,
slideDirection: SlideDirection.left,
- inProcess: false
+ inProcess: false,
},
- formsInfo: addOrUpdate(pristine, new PaymentMethodsFormInfo())
+ formsInfo: addOrUpdate(pristine, new PaymentMethodsFormInfo()),
} as ModalForms);
};
@@ -223,11 +224,17 @@ export const useModal = ({ integrationType, availablePaymentMethods, serviceProv
const [modalState, dispatch] = useReducer(dataReducer, init(integrationType, availablePaymentMethods));
const toInitialState = useCallback(() => {
- dispatch({ type: 'TO_INITIAL_STATE', payload: availablePaymentMethods });
+ dispatch({
+ type: 'TO_INITIAL_STATE',
+ payload: availablePaymentMethods,
+ });
}, [availablePaymentMethods]);
const goToFormInfo = useCallback((formInfo: FormInfo, direction: Direction = Direction.forward) => {
- dispatch({ type: 'GO_TO_FORM_INFO', payload: { formInfo, direction } });
+ dispatch({
+ type: 'GO_TO_FORM_INFO',
+ payload: { formInfo, direction },
+ });
}, []);
const prepareToPay = useCallback(() => {
@@ -248,9 +255,12 @@ export const useModal = ({ integrationType, availablePaymentMethods, serviceProv
const toInteractionState = useCallback(
(interactionModel: InteractionModel) => {
- dispatch({ type: 'TO_INTERACTION_STATE', payload: provideInteraction(serviceProviders, interactionModel) });
+ dispatch({
+ type: 'TO_INTERACTION_STATE',
+ payload: provideInteraction(serviceProviders, interactionModel),
+ });
},
- [serviceProviders]
+ [serviceProviders],
);
return {
@@ -261,6 +271,6 @@ export const useModal = ({ integrationType, availablePaymentMethods, serviceProv
prepareToRetry,
forgetPaymentAttempt,
setViewInfoError,
- toInteractionState
+ toInteractionState,
};
};
diff --git a/src/app/hooks/use-theme.test.ts b/src/app/hooks/use-theme.test.ts
index a114572c..e0ae05ea 100644
--- a/src/app/hooks/use-theme.test.ts
+++ b/src/app/hooks/use-theme.test.ts
@@ -1,22 +1,23 @@
import { renderHook } from '@testing-library/react';
-import { useTheme } from './use-theme';
import { ThemeName } from 'checkout/themes';
import plantation from 'checkout/themes/plantation';
import rhino from 'checkout/themes/rhino';
+import { useTheme } from './use-theme';
+
describe('useTheme', () => {
test('should apply init config theme', () => {
const { result } = renderHook(() =>
useTheme({
appConfig: {
- fixedTheme: ThemeName.plantation
+ fixedTheme: ThemeName.plantation,
},
initConfig: {
- theme: 'rhino'
+ theme: 'rhino',
},
- origin: ''
- })
+ origin: '',
+ }),
);
expect(result.current).toStrictEqual(rhino);
@@ -26,11 +27,11 @@ describe('useTheme', () => {
const { result } = renderHook(() =>
useTheme({
appConfig: {
- fixedTheme: ThemeName.plantation
+ fixedTheme: ThemeName.plantation,
},
initConfig: {},
- origin: ''
- })
+ origin: '',
+ }),
);
expect(result.current).toStrictEqual(plantation);
@@ -41,8 +42,8 @@ describe('useTheme', () => {
useTheme({
appConfig: {},
initConfig: {},
- origin: ''
- })
+ origin: '',
+ }),
);
expect(result.current).toStrictEqual(plantation);
@@ -53,10 +54,10 @@ describe('useTheme', () => {
useTheme({
appConfig: {},
initConfig: {
- theme: 'rhino'
+ theme: 'rhino',
},
- origin: ''
- })
+ origin: '',
+ }),
);
expect(result.current).toStrictEqual(rhino);
diff --git a/src/app/hooks/use-theme.ts b/src/app/hooks/use-theme.ts
index 10836519..8fbc1fbf 100644
--- a/src/app/hooks/use-theme.ts
+++ b/src/app/hooks/use-theme.ts
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
-import { getTheme } from 'checkout/themes';
+
import { InitParams } from 'checkout/initialize';
+import { getTheme } from 'checkout/themes';
export const useTheme = ({ appConfig, initConfig }: InitParams) => {
const fixedThemeName = appConfig.fixedTheme;
diff --git a/src/app/index.tsx b/src/app/index.tsx
index 6d3ab801..8b9ff539 100644
--- a/src/app/index.tsx
+++ b/src/app/index.tsx
@@ -1,10 +1,10 @@
-import * as React from 'react';
+import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './components/app';
import { initialize } from './initialize';
-import { CommunicatorEvents } from '../communicator';
import isNil from './utils/is-nil';
+import { CommunicatorEvents } from '../communicator';
const ON_COMPLETE_TIMEOUT_MS = 1000 * 5;
@@ -12,19 +12,22 @@ initialize().then(([transport, initParams]) => {
const container = document.getElementById('app');
const root = createRoot(container);
root.render(
- {
- setTimeout(() => {
- transport.emit(CommunicatorEvents.finished);
- transport.destroy();
- const redirectUrl = initParams.initConfig.redirectUrl;
- if (!isNil(redirectUrl)) {
- window.open(redirectUrl, '_self');
- }
- root.unmount();
- }, ON_COMPLETE_TIMEOUT_MS);
- }}
- />
+
+ {
+ setTimeout(() => {
+ transport.emit(CommunicatorEvents.finished);
+ transport.destroy();
+ const redirectUrl = initParams.initConfig.redirectUrl;
+ if (!isNil(redirectUrl)) {
+ window.open(redirectUrl, '_self');
+ }
+ root.unmount();
+ }, ON_COMPLETE_TIMEOUT_MS);
+ }}
+ />
+ ,
+ ,
);
});
diff --git a/src/app/initialize.ts b/src/app/initialize.ts
index e8454695..c3b2ec16 100644
--- a/src/app/initialize.ts
+++ b/src/app/initialize.ts
@@ -1,11 +1,12 @@
-import * as creditCardType from 'credit-card-type';
-import * as Sentry from '@sentry/react';
import { CaptureConsole as CaptureConsoleIntegration } from '@sentry/integrations';
+import * as Sentry from '@sentry/react';
+import * as creditCardType from 'credit-card-type';
-import { listen, Transport, StubTransport, CommunicatorEvents, communicatorInstanceName } from '../communicator';
-import { getUrlParams, URLParams } from 'checkout/utils';
import { InitConfig, resolveInitConfig } from 'checkout/config';
+import { getUrlParams, URLParams } from 'checkout/utils';
+
import { AppConfig, getAppConfig, getEnv } from './backend';
+import { listen, Transport, StubTransport, CommunicatorEvents, communicatorInstanceName } from '../communicator';
import { getOrigin } from '../get-origin';
/**
@@ -19,8 +20,8 @@ creditCardType.addCard({
lengths: [16],
code: {
name: 'CVV',
- size: 3
- }
+ size: 3,
+ },
});
creditCardType.addCard({
@@ -31,8 +32,8 @@ creditCardType.addCard({
lengths: [16],
code: {
name: 'CVV',
- size: 3
- }
+ size: 3,
+ },
});
const initSentry = async (dsn: string) => {
@@ -43,14 +44,14 @@ const initSentry = async (dsn: string) => {
integrations: [
new Sentry.BrowserTracing(),
new CaptureConsoleIntegration({
- levels: ['warn', 'error']
+ levels: ['warn', 'error'],
}),
- new Sentry.Replay()
+ new Sentry.Replay(),
],
tracesSampleRate: 0.2,
release: env.version,
replaysOnErrorSampleRate: 1.0,
- replaysSessionSampleRate: 0.1
+ replaysSessionSampleRate: 0.1,
});
};
@@ -85,8 +86,8 @@ export const initialize = async (): Promise<[Transport, InitParams]> => {
{
initConfig,
appConfig,
- origin
- }
+ origin,
+ },
];
} catch (e) {
console.error(e);
diff --git a/src/app/polyfills.ts b/src/app/polyfills.ts
deleted file mode 100644
index 57a61eeb..00000000
--- a/src/app/polyfills.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-if (!String.prototype.replaceAll) {
- String.prototype.replaceAll = function(str, newStr) {
- if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
- return this.replace(str, newStr);
- }
- return this.replace(new RegExp(str, 'g'), newStr);
- };
-}
diff --git a/src/app/themes/index.ts b/src/app/themes/index.ts
index cff9b725..091a14af 100644
--- a/src/app/themes/index.ts
+++ b/src/app/themes/index.ts
@@ -1,6 +1,6 @@
-import { Theme } from './theme';
import plantation from './plantation';
import rhino from './rhino';
+import { Theme } from './theme';
const themes = [plantation, rhino];
diff --git a/src/app/themes/plantation.ts b/src/app/themes/plantation.ts
index a7091ab7..e1abf176 100644
--- a/src/app/themes/plantation.ts
+++ b/src/app/themes/plantation.ts
@@ -1,6 +1,7 @@
import { css } from 'styled-components';
-import { ThemeName } from './theme-name';
+
import { Theme } from './theme';
+import { ThemeName } from './theme-name';
const palette = {
Mustard: '#FFDB57',
@@ -18,37 +19,37 @@ const palette = {
SeaNymph: '#71A19D',
BlueRibbon: '#0038FF',
Candlelight: '#ffe05c',
- Silver: '#979797'
+ Silver: '#979797',
};
const theme: Theme = {
name: ThemeName.plantation,
font: {
family: "'Roboto', sans-serif",
- primaryColor: palette.Zeus
+ primaryColor: palette.Zeus,
},
background: {
gradient: css`linear-gradient(30deg, ${palette.Aztec} 0%, ${palette.GableGreen} 50%, ${palette.William} 100%)`,
loader: [
[palette.Flamenco, '0%'],
- [palette.Mustard, '100%']
- ]
+ [palette.Mustard, '100%'],
+ ],
},
form: {
background: palette.AthensGray,
- border: palette.Loblolly
+ border: palette.Loblolly,
},
input: {
border: palette.Loblolly,
placeholder: palette.RegentGray,
error: palette.Cinnabar,
- focus: palette.Zeus
+ focus: palette.Zeus,
},
icons: {
success: palette.SeaNymph,
error: palette.CopperRose,
warn: palette.Candlelight,
- checkmark: palette.SeaNymph
+ checkmark: palette.SeaNymph,
},
divider: palette.Loblolly,
externalLink: palette.BlueRibbon,
@@ -56,22 +57,22 @@ const theme: Theme = {
border: palette.Loblolly,
hover: palette.Zeus,
color: palette.Zeus,
- error: palette.Cinnabar
+ error: palette.Cinnabar,
},
chevronButton: {
color: palette.Zeus,
- disabled: palette.Silver
+ disabled: palette.Silver,
},
button: {
primaryText: palette.Zeus,
outlineText: palette.Zeus,
color: palette.Mustard,
- hover: palette.LightningYellow
+ hover: palette.LightningYellow,
},
linkButton: {
color: palette.Zeus,
- hover: palette.Zeus
- }
+ hover: palette.Zeus,
+ },
};
export default theme;
diff --git a/src/app/themes/rhino.ts b/src/app/themes/rhino.ts
index 1ebdc4dc..278a379f 100644
--- a/src/app/themes/rhino.ts
+++ b/src/app/themes/rhino.ts
@@ -1,6 +1,7 @@
import { css } from 'styled-components';
-import { ThemeName } from './theme-name';
+
import { Theme } from './theme';
+import { ThemeName } from './theme-name';
const palette = {
CodGray: '#110E0B',
@@ -18,37 +19,37 @@ const palette = {
Gorse: '#fdec4a',
Rhino: '#33436B',
BlueCharcoal: '#000C1F',
- Silver: '#979797'
+ Silver: '#979797',
};
const theme: Theme = {
name: ThemeName.rhino,
font: {
family: "'Roboto', sans-serif",
- primaryColor: palette.CodGray
+ primaryColor: palette.CodGray,
},
background: {
gradient: css`radial-gradient(75.93% 95.05% at 46.36% 43.35%, ${palette.Rhino} 0%, ${palette.BlueCharcoal} 100%)`,
loader: [
[palette.Gorse, '0%'],
- [palette.FlushOrange, '100%']
- ]
+ [palette.FlushOrange, '100%'],
+ ],
},
form: {
background: palette.Alabaster,
- border: palette.SilverChalice
+ border: palette.SilverChalice,
},
input: {
border: palette.SilverChalice,
placeholder: palette.RegentGray,
error: palette.Cinnabar,
- focus: palette.CodGray
+ focus: palette.CodGray,
},
icons: {
success: palette.SeaNymph,
error: palette.CopperRose,
warn: palette.Candlelight,
- checkmark: palette.SeaNymph
+ checkmark: palette.SeaNymph,
},
divider: palette.SilverChalice,
externalLink: palette.BlueRibbon,
@@ -56,22 +57,22 @@ const theme: Theme = {
border: palette.SilverChalice,
hover: palette.CodGray,
color: palette.CodGray,
- error: palette.Cinnabar
+ error: palette.Cinnabar,
},
chevronButton: {
color: palette.CodGray,
- disabled: palette.Silver
+ disabled: palette.Silver,
},
button: {
primaryText: palette.White,
outlineText: palette.FlushOrange,
color: palette.FlushOrange,
- hover: palette.Clementine
+ hover: palette.Clementine,
},
linkButton: {
color: palette.CodGray,
- hover: palette.CodGray
- }
+ hover: palette.CodGray,
+ },
};
export default theme;
diff --git a/src/app/themes/theme-name.ts b/src/app/themes/theme-name.ts
index d2040ea2..914e15e1 100644
--- a/src/app/themes/theme-name.ts
+++ b/src/app/themes/theme-name.ts
@@ -1,4 +1,4 @@
export enum ThemeName {
plantation = 'plantation',
- rhino = 'rhino'
+ rhino = 'rhino',
}
diff --git a/src/app/themes/theme.ts b/src/app/themes/theme.ts
index 6efd38aa..5b85b0a4 100644
--- a/src/app/themes/theme.ts
+++ b/src/app/themes/theme.ts
@@ -1,4 +1,5 @@
import { css } from 'styled-components';
+
import { ThemeName } from './theme-name';
export interface Theme {
diff --git a/src/app/utils/amount/format-amount.ts b/src/app/utils/amount/format-amount.ts
index bf4ec65b..de3ee4c7 100644
--- a/src/app/utils/amount/format-amount.ts
+++ b/src/app/utils/amount/format-amount.ts
@@ -7,8 +7,9 @@ const getAmountByExponent = ({ minorValue, currencyCode }: AmountInfo): number =
export const formatAmount = (amount: AmountInfo): string | null => {
return amount && amount.minorValue
- ? new Intl.NumberFormat(amount.locale, { style: 'currency', currency: amount.currencyCode }).format(
- getAmountByExponent(amount)
- )
+ ? new Intl.NumberFormat(amount.locale, {
+ style: 'currency',
+ currency: amount.currencyCode,
+ }).format(getAmountByExponent(amount))
: null;
};
diff --git a/src/app/utils/country-data/countries.ts b/src/app/utils/country-data/countries.ts
index 54c4dafc..17d3aa55 100644
--- a/src/app/utils/country-data/countries.ts
+++ b/src/app/utils/country-data/countries.ts
@@ -18,151 +18,151 @@ export const countries: Country[] = [
sub: [
{
name: 'Andhra Pradesh',
- code: 'AP'
+ code: 'AP',
},
{
name: 'Arunāchal Pradesh',
- code: 'AR'
+ code: 'AR',
},
{
name: 'Assam',
- code: 'AS'
+ code: 'AS',
},
{
name: 'Bihār',
- code: 'BR'
+ code: 'BR',
},
{
name: 'Chhattīsgarh',
- code: 'CT'
+ code: 'CT',
},
{
name: 'Goa',
- code: 'GA'
+ code: 'GA',
},
{
name: 'Gujarāt',
- code: 'GJ'
+ code: 'GJ',
},
{
name: 'Haryāna',
- code: 'HR'
+ code: 'HR',
},
{
name: 'Himāchal Pradesh',
- code: 'HP'
+ code: 'HP',
},
{
name: 'Jhārkhand',
- code: 'JH'
+ code: 'JH',
},
{
name: 'Karnātaka',
- code: 'KA'
+ code: 'KA',
},
{
name: 'Kerala',
- code: 'KL'
+ code: 'KL',
},
{
name: 'Madhya Pradesh',
- code: 'MP'
+ code: 'MP',
},
{
name: 'Mahārāshtra',
- code: 'MH'
+ code: 'MH',
},
{
name: 'Manipur',
- code: 'MN'
+ code: 'MN',
},
{
name: 'Meghālaya',
- code: 'ML'
+ code: 'ML',
},
{
name: 'Mizoram',
- code: 'MZ'
+ code: 'MZ',
},
{
name: 'Nāgāland',
- code: 'NL'
+ code: 'NL',
},
{
name: 'Odisha',
- code: 'OR'
+ code: 'OR',
},
{
name: 'Punjab',
- code: 'PB'
+ code: 'PB',
},
{
name: 'Rājasthān',
- code: 'RJ'
+ code: 'RJ',
},
{
name: 'Sikkim',
- code: 'SK'
+ code: 'SK',
},
{
name: 'Tamil Nādu',
- code: 'TN'
+ code: 'TN',
},
{
name: 'Telangāna',
- code: 'TG'
+ code: 'TG',
},
{
name: 'Tripura',
- code: 'TR'
+ code: 'TR',
},
{
name: 'Uttarākhand',
- code: 'UT'
+ code: 'UT',
},
{
name: 'Uttar Pradesh',
- code: 'UP'
+ code: 'UP',
},
{
name: 'West Bengal',
- code: 'WB'
+ code: 'WB',
},
{
name: 'Andaman and Nicobar Islands',
- code: 'AN'
+ code: 'AN',
},
{
name: 'Chandīgarh',
- code: 'CH'
+ code: 'CH',
},
{
name: 'Dādra and Nagar Haveli and Damān and Diu',
- code: 'DH'
+ code: 'DH',
},
{
name: 'Delhi',
- code: 'DL'
+ code: 'DL',
},
{
name: 'Jammu and Kashmīr',
- code: 'JK'
+ code: 'JK',
},
{
name: 'Ladākh',
- code: 'LA'
+ code: 'LA',
},
{
name: 'Lakshadweep',
- code: 'LD'
+ code: 'LD',
},
{
name: 'Puducherry',
- code: 'PY'
- }
- ]
- }
+ code: 'PY',
+ },
+ ],
+ },
];
diff --git a/src/app/utils/device.ts b/src/app/utils/device.ts
index 84497203..b51a0242 100644
--- a/src/app/utils/device.ts
+++ b/src/app/utils/device.ts
@@ -1,8 +1,8 @@
const size = {
- mobile: 768
+ mobile: 768,
};
export const device = {
desktop: `(min-width: ${size.mobile}px)`,
- mobile: `(max-width: ${size.mobile - 1}px)`
+ mobile: `(max-width: ${size.mobile - 1}px)`,
};
diff --git a/src/app/utils/find-previous.ts b/src/app/utils/find-previous.ts
index b9610aef..522c8ba0 100644
--- a/src/app/utils/find-previous.ts
+++ b/src/app/utils/find-previous.ts
@@ -1,4 +1,5 @@
import { FormInfo, ModalForms, ModalName, ModalState } from 'checkout/hooks/modal/types';
+
import { findNamed } from './find-named';
export const findInfoWithPrevious = (modals: ModalState[]): FormInfo => {
diff --git a/src/app/utils/get-url-params.spec.ts b/src/app/utils/get-url-params.spec.ts
index c0821d99..7bf3f93b 100644
--- a/src/app/utils/get-url-params.spec.ts
+++ b/src/app/utils/get-url-params.spec.ts
@@ -40,7 +40,7 @@ it('Number, string, boolean, null, undefined params', () => {
integer: 123,
null: null,
str: 'hello',
- undef: undefined
+ undef: undefined,
});
});
diff --git a/src/app/utils/get-url-params.ts b/src/app/utils/get-url-params.ts
index aba2e7e3..82296494 100644
--- a/src/app/utils/get-url-params.ts
+++ b/src/app/utils/get-url-params.ts
@@ -52,7 +52,7 @@ export const getUrlParams = (url: string): URLParams =>
Object.entries(getEncodedUrlParams(url)).reduce(
(acc, [name, value]) => ({
...acc,
- [decodeURIComponentWithLogError(name)]: parseValue(decodeURIComponentWithLogError(value))
+ [decodeURIComponentWithLogError(name)]: parseValue(decodeURIComponentWithLogError(value)),
}),
- {}
+ {},
);
diff --git a/src/app/utils/group-by.ts b/src/app/utils/group-by.ts
index 37e18c2a..0bb4837d 100644
--- a/src/app/utils/group-by.ts
+++ b/src/app/utils/group-by.ts
@@ -8,7 +8,7 @@ function baseAssignValue(object, key, value) {
configurable: true,
enumerable: true,
value: value,
- writable: true
+ writable: true,
});
} else {
object[key] = value;
diff --git a/src/app/utils/interaction-form/prepare-form.ts b/src/app/utils/interaction-form/prepare-form.ts
index f1dc47bf..9d72ad4f 100644
--- a/src/app/utils/interaction-form/prepare-form.ts
+++ b/src/app/utils/interaction-form/prepare-form.ts
@@ -1,6 +1,7 @@
import { BrowserPostRequest, BrowserRequest, RequestType } from 'checkout/backend';
-import { toPostFormInputs } from './to-post-form-inputs';
+
import { toGetFormInputs } from './to-get-form-inputs';
+import { toPostFormInputs } from './to-post-form-inputs';
const toInputs = (origin: string, request: BrowserRequest): HTMLInputElement[] => {
switch (request.requestType) {
@@ -23,7 +24,7 @@ const toMethod = (request: BrowserRequest): 'POST' | 'GET' => {
export const prepareForm = (
origin: string,
request: BrowserRequest,
- target: '_self' | '_blank' = '_self'
+ target: '_self' | '_blank' = '_self',
): HTMLFormElement => {
const form = document.createElement('form');
form.action = request.uriTemplate;
diff --git a/src/app/utils/interaction-form/to-get-form-inputs.ts b/src/app/utils/interaction-form/to-get-form-inputs.ts
index a28ae563..888f3230 100644
--- a/src/app/utils/interaction-form/to-get-form-inputs.ts
+++ b/src/app/utils/interaction-form/to-get-form-inputs.ts
@@ -1,5 +1,6 @@
import { BrowserGetRequest } from 'checkout/backend';
import { getEncodedUrlParams } from 'checkout/utils';
+
import { expandWithRedirect, hasTerminationUriTemplate } from './uri-template';
const createInput = (name: string, value: any): HTMLInputElement => {
diff --git a/src/app/utils/interaction-form/to-post-form-inputs.ts b/src/app/utils/interaction-form/to-post-form-inputs.ts
index ecc85be4..802e148b 100644
--- a/src/app/utils/interaction-form/to-post-form-inputs.ts
+++ b/src/app/utils/interaction-form/to-post-form-inputs.ts
@@ -1,4 +1,5 @@
import { FormField } from 'checkout/backend';
+
import { expandWithRedirect } from './uri-template';
const createInput = (origin: string, formField: FormField): HTMLInputElement => {
diff --git a/src/app/utils/interaction-form/uri-template.ts b/src/app/utils/interaction-form/uri-template.ts
index cbfe1677..2da20369 100644
--- a/src/app/utils/interaction-form/uri-template.ts
+++ b/src/app/utils/interaction-form/uri-template.ts
@@ -1,6 +1,7 @@
-import isString from 'checkout/utils/is-string';
import { TemplateExpression, parse } from 'uri-template';
+import isString from 'checkout/utils/is-string';
+
const hasTerminationUriParam = (expression: TemplateExpression): boolean =>
!!expression.params.find((param) => param.name === 'termination_uri');
diff --git a/src/app/utils/is-payment-result-success.ts b/src/app/utils/is-payment-result-success.ts
index 58b61c61..c6fa7774 100644
--- a/src/app/utils/is-payment-result-success.ts
+++ b/src/app/utils/is-payment-result-success.ts
@@ -1,12 +1,12 @@
-import last from 'checkout/utils/last';
import {
InvoiceEvent,
InvoiceChangeType,
InvoiceStatusChanged,
PaymentStatusChanged,
PaymentStatuses,
- InvoiceStatuses
+ InvoiceStatuses,
} from 'checkout/backend';
+import last from 'checkout/utils/last';
const fromPaymentStatusChanged = (change: PaymentStatusChanged): boolean => {
switch (change.status) {
diff --git a/src/app/utils/partial-right.ts b/src/app/utils/partial-right.ts
index 4bd07835..43dccbe8 100644
--- a/src/app/utils/partial-right.ts
+++ b/src/app/utils/partial-right.ts
@@ -1,3 +1,6 @@
-const partialRight = (func, ...cachedArgs) => (...args) => func(...args, ...cachedArgs);
+const partialRight =
+ (func, ...cachedArgs) =>
+ (...args) =>
+ func(...args, ...cachedArgs);
export default partialRight;
diff --git a/src/app/utils/phone/format-phone-number.ts b/src/app/utils/phone/format-phone-number.ts
index 97f0145c..ae66f4f4 100644
--- a/src/app/utils/phone/format-phone-number.ts
+++ b/src/app/utils/phone/format-phone-number.ts
@@ -1,5 +1,5 @@
-import { FormEvent } from 'react';
import { AsYouType } from 'libphonenumber-js/min';
+import { FormEvent } from 'react';
export const formatOnInput = (value: string): string => {
if (value === '') {
diff --git a/src/app/utils/phone/get-phone-country-code.ts b/src/app/utils/phone/get-phone-country-code.ts
index 76cdccad..7f010cf9 100644
--- a/src/app/utils/phone/get-phone-country-code.ts
+++ b/src/app/utils/phone/get-phone-country-code.ts
@@ -1,7 +1,9 @@
import { AsYouType, getCountryCallingCode, CountryCode } from 'libphonenumber-js/min';
export function getPhoneCountryCode(value: string): string {
- const formatter = new AsYouType('RU') as AsYouType & { country: CountryCode };
+ const formatter = new AsYouType('RU') as AsYouType & {
+ country: CountryCode;
+ };
formatter.input(value);
return getCountryCallingCode(formatter.country).toString();
}
diff --git a/src/appConfig.json b/src/appConfig.json
index ea8b98c2..b6aab93c 100644
--- a/src/appConfig.json
+++ b/src/appConfig.json
@@ -1,23 +1,8 @@
{
- "capiEndpoint": "",
- "wrapperEndpoint": "",
- "applePayMerchantID": "",
- "samsungPayMerchantName": "",
- "samsungPayServiceID": "",
"brandless": false,
"fixedTheme": "",
- "brandName": "Vality",
- "yandexPay": {
- "merchantName": "Vality",
- "merchantID": "00000000-0000-0000-0000-000000000000",
- "gatewayMerchantID": "vality"
- },
- "googlePay": {
- "merchantName": "Vality",
- "merchantID": "12345678901234567890",
- "gateway": "vality",
- "gatewayMerchantID": "vality",
- "merchantOrigin": "vality.dev/checkout"
- },
- "sentryDsn": "/projects//keys/>"
+ "capiEndpoint": "",
+ "wrapperEndpoint": "",
+ "urlShortenerEndpoint": "",
+ "sentryDsn": ""
}
diff --git a/src/communicator/communicator-events.ts b/src/communicator/communicator-events.ts
index 0d74cba4..11b750fe 100644
--- a/src/communicator/communicator-events.ts
+++ b/src/communicator/communicator-events.ts
@@ -3,5 +3,5 @@ export const communicatorInstanceName = 'checkout-initializer';
export enum CommunicatorEvents {
init = 'checkout-init',
finished = 'checkout-finished',
- close = 'checkout-close'
+ close = 'checkout-close',
}
diff --git a/src/communicator/constants.ts b/src/communicator/constants.ts
index aba5ba93..0e0cef82 100644
--- a/src/communicator/constants.ts
+++ b/src/communicator/constants.ts
@@ -1,4 +1,4 @@
export enum Constants {
initializerHandName = 'communicator-initializer-hand',
- listenerHandName = 'communicator-listener-hand'
+ listenerHandName = 'communicator-listener-hand',
}
diff --git a/src/communicator/initialize.ts b/src/communicator/initialize.ts
index 9b29769b..38f79d35 100644
--- a/src/communicator/initialize.ts
+++ b/src/communicator/initialize.ts
@@ -1,13 +1,13 @@
+import { Constants } from './constants';
+import { log } from './log';
import { RealTransport } from './real-transport';
import { Transport } from './transport';
-import { log } from './log';
-import { Constants } from './constants';
export const initialize = (
target: Window,
origin: string,
transportName: string,
- isLog: boolean = false
+ isLog: boolean = false,
): Promise => {
let interval: number;
return new Promise((resolve, reject) => {
diff --git a/src/communicator/listen.ts b/src/communicator/listen.ts
index d75b8e23..c7c672d8 100644
--- a/src/communicator/listen.ts
+++ b/src/communicator/listen.ts
@@ -1,7 +1,7 @@
+import { Constants } from './constants';
+import { log } from './log';
import { RealTransport } from './real-transport';
import { Transport } from './transport';
-import { log } from './log';
-import { Constants } from './constants';
const timeout = (ms: number): Promise =>
new Promise((_resolve, reject) => {
diff --git a/src/communicator/real-transport.ts b/src/communicator/real-transport.ts
index e9699e14..594fbcb7 100644
--- a/src/communicator/real-transport.ts
+++ b/src/communicator/real-transport.ts
@@ -4,7 +4,7 @@ const parse = (data: any): any => {
let parsed;
try {
parsed = JSON.parse(data);
- } catch (e) {} // tslint:disable-line:no-empty
+ } catch (e) {} // eslint-disable-line no-empty
return parsed;
};
@@ -24,7 +24,7 @@ export class RealTransport implements Transport {
constructor(
private readonly target: Window,
private readonly origin: string,
- private readonly transportName = 'default-communicator-transport'
+ private readonly transportName = 'default-communicator-transport',
) {
this.transportListener = transportListener.bind(this, this.transportName, this.events);
window.addEventListener('message', this.transportListener, false);
@@ -34,7 +34,7 @@ export class RealTransport implements Transport {
const serialized = JSON.stringify({
data,
name: eventName,
- transport: this.transportName
+ transport: this.transportName,
});
this.target.postMessage(serialized, this.origin);
}
diff --git a/src/environment.ts b/src/environment.ts
index c3e3311c..d94cb09b 100644
--- a/src/environment.ts
+++ b/src/environment.ts
@@ -8,4 +8,4 @@ export interface Configurator {
configure: (userConfig: any) => Initializer;
}
-export const environment = (window as any) as Environment;
+export const environment = window as any as Environment;
diff --git a/src/get-origin.ts b/src/get-origin.ts
index 8ac1fadc..35958846 100644
--- a/src/get-origin.ts
+++ b/src/get-origin.ts
@@ -1,5 +1,5 @@
export const ieCurrentScriptStub = {
- src: `${document.location.origin}/checkout.js`
+ src: `${document.location.origin}/checkout.js`,
};
const getCurrentScript = (): HTMLScriptElement => (document.currentScript || ieCurrentScriptStub) as HTMLScriptElement;
diff --git a/src/initializer/dom-ready.ts b/src/initializer/dom-ready.ts
index f195848e..3211ce8e 100644
--- a/src/initializer/dom-ready.ts
+++ b/src/initializer/dom-ready.ts
@@ -34,8 +34,7 @@ export const domReady = (): Promise => {
let top: any = false;
try {
top = window.frameElement === null && document.documentElement;
- /* tslint:disable: no-empty */
- } catch (e) {}
+ } catch (e) {} // eslint-disable-line no-empty
if (top && top.doScroll) {
(function scrollCheck() {
if (ready) {
diff --git a/src/initializer/html-integration.ts b/src/initializer/html-integration.ts
index 313d1fbc..a32a3262 100644
--- a/src/initializer/html-integration.ts
+++ b/src/initializer/html-integration.ts
@@ -4,9 +4,9 @@ const mapKeys = (obj, mapper) =>
Object.entries(obj).reduce(
(acc, [key, value]) => ({
...acc,
- [mapper(value, key)]: value
+ [mapper(value, key)]: value,
}),
- {}
+ {},
);
const getOuterForm = (element: HTMLScriptElement) => {
@@ -21,7 +21,7 @@ const prepareUserConfig = (element: HTMLScriptElement): object => ({
if (outerForm) {
outerForm.submit();
}
- }
+ },
});
export class HtmlIntegration {
diff --git a/src/initializer/iframe-container.ts b/src/initializer/iframe-container.ts
index 34d3a6a3..a7ba26b0 100644
--- a/src/initializer/iframe-container.ts
+++ b/src/initializer/iframe-container.ts
@@ -18,11 +18,11 @@ const styles = {
top: '0',
width: '100%',
height: '100%',
- zIndex: 2147483647
+ zIndex: 2147483647,
};
const setStyles = (element, styles) => {
- for (let property in styles) {
+ for (const property in styles) {
element.style[property] = styles[property];
}
};
@@ -37,7 +37,7 @@ const create = (origin: string): HTMLIFrameElement => {
iframe.setAttribute('allowpaymentrequest', '');
setStyles(iframe, {
...iframe.style,
- ...styles
+ ...styles,
});
return iframe;
};
diff --git a/src/initializer/iframe-initializer.ts b/src/initializer/iframe-initializer.ts
index 03436ba5..4d7d4323 100644
--- a/src/initializer/iframe-initializer.ts
+++ b/src/initializer/iframe-initializer.ts
@@ -1,7 +1,8 @@
-import { initialize, CommunicatorEvents, communicatorInstanceName } from '../communicator';
+import { InitConfig } from 'checkout/config';
+
import { IframeContainer } from './iframe-container';
import { Initializer } from './initializer';
-import { InitConfig } from 'checkout/config';
+import { initialize, CommunicatorEvents, communicatorInstanceName } from '../communicator';
export class IframeInitializer extends Initializer {
private container: IframeContainer;
@@ -16,7 +17,10 @@ export class IframeInitializer extends Initializer {
this.container.show();
initialize(target, this.origin, communicatorInstanceName).then((transport) => {
this.opened();
- transport.emit(CommunicatorEvents.init, { ...this.config, ...openConfig });
+ transport.emit(CommunicatorEvents.init, {
+ ...this.config,
+ ...openConfig,
+ });
transport.on(CommunicatorEvents.finished, () => {
transport.destroy();
this.container.reinitialize();
diff --git a/src/initializer/index.ts b/src/initializer/index.ts
index 31dec238..f9a9fd71 100644
--- a/src/initializer/index.ts
+++ b/src/initializer/index.ts
@@ -3,7 +3,7 @@ import { PopupInitializer } from './popup-initializer';
import { environment, Configurator } from '../environment';
const init = (origin: string): Configurator => ({
- configure: (userConfig: any) => new PopupInitializer(origin, userConfig)
+ configure: (userConfig: any) => new PopupInitializer(origin, userConfig),
});
domReady().then((origin) => {
diff --git a/src/initializer/init-button/init-button.css b/src/initializer/init-button/init-button.css
index 11157f26..def5056f 100644
--- a/src/initializer/init-button/init-button.css
+++ b/src/initializer/init-button/init-button.css
@@ -5,7 +5,11 @@
visibility: visible;
padding: 8px 12px;
outline: 0;
- font: bold 14px/14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ font:
+ bold 14px/14px 'Helvetica Neue',
+ Helvetica,
+ Arial,
+ sans-serif;
text-decoration: none;
color: #fff;
border: 1px solid #2384c1;
diff --git a/src/initializer/initializer.ts b/src/initializer/initializer.ts
index 575906e4..9ae4bbb8 100644
--- a/src/initializer/initializer.ts
+++ b/src/initializer/initializer.ts
@@ -27,7 +27,7 @@ const getLocale = (userConfig: any) => userConfig.locale || 'auto';
const prepareConfig = (userConfig: any): any => ({
...mapBoolean(userConfig),
- locale: getLocale(userConfig)
+ locale: getLocale(userConfig),
});
const dummyFn: ActionCallback = () => undefined;
diff --git a/src/initializer/popup-initializer.ts b/src/initializer/popup-initializer.ts
index d7c94a5f..2dae1a03 100644
--- a/src/initializer/popup-initializer.ts
+++ b/src/initializer/popup-initializer.ts
@@ -1,11 +1,14 @@
-import { initialize, CommunicatorEvents, communicatorInstanceName } from '../communicator';
import { Initializer } from './initializer';
import { InitConfig } from '../app/config';
+import { initialize, CommunicatorEvents, communicatorInstanceName } from '../communicator';
import { serializeUrlParams } from '../serialize-url-params';
export class PopupInitializer extends Initializer {
open(openConfig: InitConfig = {}) {
- const url = `${this.origin}/v1/checkout.html?${serializeUrlParams({ ...this.config, ...openConfig })}`;
+ const url = `${this.origin}/v1/checkout.html?${serializeUrlParams({
+ ...this.config,
+ ...openConfig,
+ })}`;
const target = window.open(url, '_blank');
initialize(target, this.origin, communicatorInstanceName).then((transport) => {
this.opened();
diff --git a/src/serialize-url-params.ts b/src/serialize-url-params.ts
index 44b05865..4abc714a 100644
--- a/src/serialize-url-params.ts
+++ b/src/serialize-url-params.ts
@@ -1,7 +1,7 @@
export const serializeUrlParams = (params: { [name: string]: any }): string => {
const urlParams: string[] = [];
for (const prop in params) {
- if (params.hasOwnProperty(prop)) {
+ if (Object.prototype.hasOwnProperty.call(params, prop)) {
let value = params[prop];
if (typeof value === 'function' || value === undefined || value === null) {
continue;
diff --git a/tsconfig.json b/tsconfig.json
index 3fc69089..39bf651c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,21 +1,25 @@
{
"compilerOptions": {
- "outDir": "./dist/",
- "sourceMap": true,
- "moduleResolution": "Node",
- "module": "ES2015",
- "target": "ES5",
- "jsx": "react",
- "lib": ["ESNext", "DOM"],
+ "target": "ES2020",
+ "useDefineForClassFields": true,
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
+ "module": "ESNext",
+ "skipLibCheck": true,
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "noEmit": true,
+ "jsx": "react-jsx",
+ "allowSyntheticDefaultImports": true,
+ "strict": false,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"checkout/*": ["./src/app/*", "./src/locale/*"]
- },
- "pretty": true,
- "noUnusedLocals": true,
- "noUnusedParameters": true,
- "skipLibCheck": true,
- "esModuleInterop": true
+ }
},
"include": ["./src/**/*", "./types/**/*"]
}
diff --git a/tslint.json b/tslint.json
deleted file mode 100644
index 484dc235..00000000
--- a/tslint.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "extends": ["tslint:recommended", "tslint-react", "tslint-immutable", "tslint-config-prettier"],
- "rules": {
- "member-access": [true, "no-public"],
- "trailing-comma": false,
- "ordered-imports": false,
- "no-console": [true, "log"],
- "max-line-length": false,
- "object-literal-sort-keys": false,
- "interface-name": false,
- "no-namespace": false,
- "jsx-alignment": false,
- "jsx-no-multiline-js": false,
- "jsx-no-lambda": false,
- "variable-name": {
- "options": [
- "ban-keywords",
- "check-format",
- "allow-leading-underscore",
- "allow-pascal-case",
- "require-const-for-all-caps"
- ]
- }
- }
-}
diff --git a/types/kjua.d.ts b/types/kjua.d.ts
index 60d465cf..533cfa1a 100644
--- a/types/kjua.d.ts
+++ b/types/kjua.d.ts
@@ -51,7 +51,7 @@ declare module 'kjua' {
}
function kjua(
- options: KjuaOptions & { render?: T }
+ options: KjuaOptions & { render?: T },
): T extends 'canvas' ? HTMLCanvasElement : HTMLImageElement;
namespace kjua {
export { KjuaOptions as Options };
diff --git a/vite.config.app.ts b/vite.config.app.ts
index 9c7a2f7e..3685d6ab 100644
--- a/vite.config.app.ts
+++ b/vite.config.app.ts
@@ -1,8 +1,8 @@
-import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
-import tsconfigPaths from 'vite-tsconfig-paths';
+import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import svgr from 'vite-plugin-svgr';
+import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
base: './',
@@ -10,9 +10,9 @@ export default defineConfig({
outDir: 'dist/v1',
rollupOptions: {
input: {
- app: './checkout.html'
- }
- }
+ app: './checkout.html',
+ },
+ },
},
plugins: [
react(),
@@ -22,30 +22,30 @@ export default defineConfig({
targets: [
{
src: 'src/appConfig.json',
- dest: './'
+ dest: './',
},
{
src: 'src/env.json',
- dest: './'
+ dest: './',
},
{
src: 'src/assets/*',
- dest: './assets'
+ dest: './assets',
},
{
src: 'src/locale/*.json',
- dest: './locale'
- }
- ]
- })
+ dest: './locale',
+ },
+ ],
+ }),
],
server: {
port: 7050,
proxy: {
'^/v1': {
target: 'http://localhost:7050',
- rewrite: (path) => path.replace(/^\/v1/, '')
- }
- }
- }
+ rewrite: (path) => path.replace(/^\/v1/, ''),
+ },
+ },
+ },
});
diff --git a/vite.config.checkout.ts b/vite.config.checkout.ts
index 478d5839..412112a2 100644
--- a/vite.config.checkout.ts
+++ b/vite.config.checkout.ts
@@ -5,12 +5,12 @@ export default defineConfig({
outDir: 'dist',
lib: {
entry: './src/initializer/index.ts',
- name: 'checkout'
+ name: 'checkout',
},
rollupOptions: {
output: {
- entryFileNames: 'checkout.js'
- }
- }
- }
+ entryFileNames: 'checkout.js',
+ },
+ },
+ },
});
diff --git a/vite.config.preview.ts b/vite.config.preview.ts
index 6508118b..e9096b56 100644
--- a/vite.config.preview.ts
+++ b/vite.config.preview.ts
@@ -1,3 +1,3 @@
export default {
- root: './dist'
+ root: './dist',
};