All files / app/payment/hostedCreditCard getHostedInstrumentValidationSchema.ts

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  29x 29x                               29x 8x   8x                 7x       7x           7x       7x       7x            
import { LanguageService } from '@bigcommerce/checkout-sdk';
import { memoize } from '@bigcommerce/memoize';
import { object, string, ObjectSchema } from 'yup';
 
export interface HostedInstrumentValidationSchemaOptions {
    language: LanguageService;
}
 
export interface HostedInstrumentValidationSchemaShape {
    hostedForm: {
        errors: {
            cardCodeVerification: string;
            cardNumberVerification: string;
        };
    };
    instrumentId: string;
}
 
export default memoize(function getHostedInstrumentValidationSchema({
    language,
}: HostedInstrumentValidationSchemaOptions): ObjectSchema<HostedInstrumentValidationSchemaShape> {
    return object({
        instrumentId: string()
            .required(),
 
        hostedForm: object({
            errors: object({
                cardCodeVerification: string()
                    .test({
                        message: language.translate('payment.credit_card_cvv_required_error'),
                        test: value => value !== 'required',
                    })
                    .test({
                        message: language.translate('payment.credit_card_cvv_invalid_error'),
                        test: value => value !== 'invalid_card_code',
                    }),
 
                cardNumberVerification: string()
                    .test({
                        message: language.translate('payment.credit_card_number_required_error'),
                        test: value => value !== 'required',
                    })
                    .test({
                        message: language.translate('payment.credit_card_number_invalid_error'),
                        test: value => value !== 'invalid_card_number',
                    })
                    .test({
                        message: language.translate('payment.credit_card_number_mismatch_error'),
                        test: value => value !== 'mismatched_card_number',
                    }),
            }),
        }),
    });
});