All files / app/payment/checkoutcomFieldsets getCheckoutcomFieldsetValidationSchemas.tsx

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  25x 25x                                                       25x   3x                                                       3x                   2x                                         25x 8x 8x     8x    
import { LanguageService } from '@bigcommerce/checkout-sdk';
import { memoize } from '@bigcommerce/memoize';
import { boolean, object, string, ObjectSchema } from 'yup';
 
export type checkoutcomCustomPaymentMethods = 'fawry' | 'sepa';
export type documentPaymentMethods = 'oxxo' | 'qpay' | 'boleto' | 'ideal';
export type checkoutcomPaymentMethods = documentPaymentMethods | checkoutcomCustomPaymentMethods;
export interface CustomValidationSchemaOptions {
    paymentMethod: checkoutcomPaymentMethods;
    language: LanguageService;
}
 
export interface DocumentOnlyCustomFormFieldsetValues {
    ccDocument?: string;
}
export interface SepaCustomFormFieldsetValues {
    iban: string;
    sepaMandate: boolean;
}
export interface IdealCustomFormFieldsetValues {
    bic: string;
}
 
export interface FawryCustomFormFieldsetValues {
    customerMobile: string;
    customerEmail: string;
}
 
const checkoutComShemas: {
    [key in checkoutcomPaymentMethods]: (language: LanguageService) => {}
} = {
 
    oxxo: (language: LanguageService) => ({
        ccDocument: string()
            .required(language.translate('payment.checkoutcom_document_invalid_error_oxxo'))
            .length(
                18,
                language.translate('payment.checkoutcom_document_invalid_error_oxxo')
            ),
    }),
    qpay: (language: LanguageService) => ({
        ccDocument: string()
            .notRequired()
            .max(
                32,
                language.translate('payment.checkoutcom_document_invalid_error_qpay')
            ),
    }),
    boleto: (language: LanguageService) => ({
        ccDocument: string()
            .required(language.translate('payment.checkoutcom_document_invalid_error_boleto'))
            .min(
                11,
                language.translate('payment.checkoutcom_document_invalid_error_boleto')
            )
            .max(
                14,
                language.translate('payment.checkoutcom_document_invalid_error_boleto')
            ),
    }),
    sepa: (language: LanguageService) => ({
        iban: string()
            .required(
                language.translate('payment.sepa_account_number_required')
            ),
        sepaMandate: boolean()
            .required(
                language.translate('payment.sepa_mandate_required')
            ),
    }),
    ideal: (language: LanguageService) => ({
        bic: string()
            .required(
                language.translate('payment.ideal_bic_required')
            ),
    }),
    fawry: (language: LanguageService) => ({
        customerMobile: string()
            .required(language.translate('payment.checkoutcom_fawry_customer_mobile_invalid_error'))
            .matches(
                new RegExp(`^\\d{11}$`),
                language.translate('payment.checkoutcom_fawry_customer_mobile_invalid_error')
            ),
        customerEmail: string()
            .required(language.translate('payment.checkoutcom_fawry_customer_email_invalid_error'))
            .email(
                language.translate('payment.checkoutcom_fawry_customer_email_invalid_error')
            ),
    }),
};
 
export default memoize(function getCheckoutcomValidationSchemas({
    paymentMethod,
    language,
}: CustomValidationSchemaOptions): ObjectSchema<DocumentOnlyCustomFormFieldsetValues | FawryCustomFormFieldsetValues | IdealCustomFormFieldsetValues | SepaCustomFormFieldsetValues> {
 
    return object(checkoutComShemas[paymentMethod](language));
});