All files / app/payment/hostedCreditCard getHostedCreditCardValidationSchema.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 56 57 58 59 60 61 62 63 64 65  29x 29x                                 29x 9x   9x           8x       8x           8x       8x           8x           8x       8x            
import { LanguageService } from '@bigcommerce/checkout-sdk';
import { memoize } from '@bigcommerce/memoize';
import { object, string, ObjectSchema } from 'yup';
 
export interface HostedCreditCardValidationSchemaOptions {
    language: LanguageService;
}
 
export interface HostedCreditCardValidationSchemaShape {
    hostedForm: {
        errors: {
            cardCode: string;
            cardExpiry: string;
            cardName: string;
            cardNumber: string;
        };
    };
}
 
export default memoize(function getHostedCreditCardValidationSchema({
    language,
}: HostedCreditCardValidationSchemaOptions): ObjectSchema<HostedCreditCardValidationSchemaShape> {
    return object({
        hostedForm: object({
            errors: object({
                cardCode: 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',
                    }),
 
                cardExpiry: string()
                    .test({
                        message: language.translate('payment.credit_card_expiration_required_error'),
                        test: value => value !== 'required',
                    })
                    .test({
                        message: language.translate('payment.credit_card_expiration_invalid_error'),
                        test: value => value !== 'invalid_card_expiry',
                    }),
 
                cardName: string()
                    .test({
                        message: language.translate('payment.credit_card_name_required_error'),
                        test: value => value !== 'required',
                    }),
 
                cardNumber: 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',
                    }),
            }),
        }),
    });
});