Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CardInput stores the brand detected by the internal regEx #3036

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import useImage from '../../../../core/Context/useImage';
import { getArrayDifferences } from '../../../../utils/arrayUtils';
import FormInstruction from '../../../internal/FormInstruction';
import { AddressData } from '../../../../types/global-types';
import { CbObjOnFocus } from '../../../internal/SecuredFields/lib/types';
import { CbObjOnBrand, CbObjOnFocus } from '../../../internal/SecuredFields/lib/types';
import { FieldErrorAnalyticsObject } from '../../../../core/Analytics/types';
import { PREFIX } from '../../../internal/Icon/constants';
import useSRPanelForCardInputErrors from './useSRPanelForCardInputErrors';
Expand Down Expand Up @@ -92,6 +92,15 @@ const CardInput = (props: CardInputProps) => {
// or else the name of an internal, Adyen-web, element (like 'holderName')
const [iOSFocusedField, setIOSFocusedField] = useState(null);

/**
* This stores the brand as detected by the internal regEx.
* It eventually gets overwritten by the brand as detected by the /binLookup, but will revert back to the regEx detection
* if the PAN length drops below the /binLookup digit threshold.
* Default value, 'card', indicates no brand detected
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [internallyDetectedBrand, setInternallyDetectedBrand] = useState('card');

/**
* LOCAL VARS
*/
Expand Down Expand Up @@ -134,6 +143,11 @@ const CardInput = (props: CardInputProps) => {
props.onBlur({ fieldType: who, event: e });
};

const onBrand = useCallback((obj: CbObjOnBrand) => {
setInternallyDetectedBrand(obj.brand);
props.onBrand(obj);
}, []);

// Make SecuredFields aware of the focus & blur handlers
const handleFocus = getFocusHandler(setFocusedElement, onFieldFocusAnalytics, onFieldBlurAnalytics);

Expand Down Expand Up @@ -399,7 +413,7 @@ const CardInput = (props: CardInputProps) => {
koreanAuthenticationRequired={props.configuration.koreanAuthenticationRequired}
hasKoreanFields={!!(props.configuration.koreanAuthenticationRequired && props.countryCode === 'kr')}
onChange={handleSecuredFieldsChange}
onBrand={props.onBrand}
onBrand={onBrand}
onFocus={handleFocus}
type={props.brand}
disableIOSArrowKeys={props.disableIOSArrowKeys ? handleTouchstartIOS : null}
Expand Down
26 changes: 18 additions & 8 deletions packages/lib/src/components/Card/components/CardInput/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import Language from '../../../../language/Language';
import { BinLookupResponse, BrandConfiguration, CardBrandsConfiguration, CardBackendConfiguration, DualBrandSelectElement } from '../../types';
import { InstallmentOptions } from './components/types';
import { ValidationResult } from '../../../internal/PersonalDetails/types';
import { CVCPolicyType, DatePolicyType } from '../../../internal/SecuredFields/lib/types';
import {
CbObjOnAllValid,
CbObjOnAutoComplete,
CbObjOnBinValue,
CbObjOnBrand,
CbObjOnConfigSuccess,
CbObjOnFieldValid,
CbObjOnLoad,
CVCPolicyType,
DatePolicyType
} from '../../../internal/SecuredFields/lib/types';
import Specifications from '../../../internal/Address/Specifications';
import { AddressSchema } from '../../../internal/Address/types';
import { CbObjOnError, StylesObject } from '../../../internal/SecuredFields/lib/types';
Expand Down Expand Up @@ -104,17 +114,17 @@ export interface CardInputProps {
};
onAdditionalSFConfig?: () => {};
onAdditionalSFRemoved?: () => {};
onAllValid?: () => {};
onAutoComplete?: () => {};
onBinValue?: () => {};
onAllValid?: (o: CbObjOnAllValid) => {};
onAutoComplete?: (o: CbObjOnAutoComplete) => {};
onBinValue?: (o: CbObjOnBinValue) => {};
onBlur?: (e) => {};
onBrand?: () => {};
onConfigSuccess?: () => {};
onBrand?: (o: CbObjOnBrand) => {};
onConfigSuccess?: (O: CbObjOnConfigSuccess) => {};
onChange?: (state) => {};
onError?: () => {};
onFieldValid?: () => {};
onFieldValid?: (o: CbObjOnFieldValid) => {};
onFocus?: (e) => {};
onLoad?: () => {};
onLoad?: (o: CbObjOnLoad) => {};
handleKeyPress?: (obj: KeyboardEvent) => void;
onAddressLookup?: OnAddressLookupType;
onAddressSelected?: OnAddressSelectedType;
Expand Down
Loading