Skip to content

Commit

Permalink
Specifying type. Move card related, "is it a stored card" logic, out …
Browse files Browse the repository at this point in the history
…of UIElement
  • Loading branch information
sponglord committed Jan 29, 2024
1 parent 2bc791d commit c248b43
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
27 changes: 25 additions & 2 deletions packages/lib/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import ClickToPayWrapper from './components/ClickToPayWrapper';
import { ComponentFocusObject, PayButtonFunctionProps, UIElementStatus } from '../types';
import SRPanelProvider from '../../core/Errors/SRPanelProvider';
import PayButton from '../internal/PayButton';
import { ANALYTICS_FOCUS_STR, ANALYTICS_CONFIGURED_STR, ANALYTICS_UNFOCUS_STR, ANALYTICS_VALIDATION_ERROR_STR } from '../../core/Analytics/constants';
import {
ANALYTICS_FOCUS_STR,
ANALYTICS_CONFIGURED_STR,
ANALYTICS_UNFOCUS_STR,
ANALYTICS_VALIDATION_ERROR_STR,
ANALYTICS_RENDERED_STR
} from '../../core/Analytics/constants';
import { ALL_SECURED_FIELDS, ENCRYPTED } from '../internal/SecuredFields/lib/configuration/constants';
import { camelCaseToSnakeCase } from '../../utils/textUtils';
import { FieldErrorAnalyticsObject } from '../../core/Analytics/types';
import { FieldErrorAnalyticsObject, SendAnalyticsObject } from '../../core/Analytics/types';
import { hasOwnProperty } from '../../utils/hasOwnProperty';

export class CardElement extends UIElement<CardElementProps> {
public static type = 'scheme';
Expand Down Expand Up @@ -166,6 +173,22 @@ export class CardElement extends UIElement<CardElementProps> {
}
}

protected submitAnalytics(analyticsObj: SendAnalyticsObject) {
const { type } = analyticsObj;

if (type === ANALYTICS_RENDERED_STR || type === ANALYTICS_CONFIGURED_STR) {
// Check if it's a storedCard
if (this.constructor['type'] === 'scheme') {
if (hasOwnProperty(this.props, 'supportedShopperInteractions')) {
analyticsObj.isStoredPaymentMethod = true;
analyticsObj.brand = this.props.brand;
}
}
}

super.submitAnalytics(analyticsObj);
}

private fieldTypeToSnakeCase(fieldType) {
let str = camelCaseToSnakeCase(fieldType);
// SFs need their fieldType mapped to what the endpoint expects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface DoChallenge3DS2Props extends ChallengeData {
onCompleteChallenge: (resolveObject: ThreeDS2FlowObject) => void;
onErrorChallenge: (rejectObject: ThreeDS2FlowObject) => void;
onActionHandled: (rtnObj: ActionHandledReturnObject) => void;
onFormSubmit: (w) => void;
}

export interface DoChallenge3DS2State {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface DoFingerprint3DS2Props extends FingerPrintData {
onErrorFingerprint: (rejectObject: ThreeDS2FlowObject) => void;
showSpinner: boolean;
onActionHandled: (rtnObj: ActionHandledReturnObject) => void;
onFormSubmit: (w) => void;
}

export interface DoFingerprint3DS2State {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ThreeDS2FormProps {
target: string;
inputName: string;
inputValue: string;
onFormSubmit: (w) => void;
onFormSubmit: (msg: string) => void;
}

export default class ThreeDS2Form extends Component<ThreeDS2FormProps> {
Expand Down
2 changes: 2 additions & 0 deletions packages/lib/src/components/ThreeDS2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ChallengeData {
cReqData: CReqData;
iframeSizeArr: string[];
postMessageDomain: string;
onFormSubmit: (msg: string) => void;
}

export interface ResultObject {
Expand Down Expand Up @@ -58,6 +59,7 @@ export interface FingerPrintData {
threeDSMethodURL: string;
threeDSMethodNotificationURL: string;
postMessageDomain: string;
onFormSubmit: (msg: string) => void;
}

export type ThreeDS2FingerprintResponse = {
Expand Down
14 changes: 1 addition & 13 deletions packages/lib/src/components/UIElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { hasOwnProperty } from '../utils/hasOwnProperty';
import DropinElement from './Dropin';
import { CoreOptions } from '../core/types';
import Core from '../core';
import { ANALYTICS_CONFIGURED_STR, ANALYTICS_RENDERED_STR, ANALYTICS_SUBMIT_STR } from '../core/Analytics/constants';
import { ANALYTICS_SUBMIT_STR } from '../core/Analytics/constants';
import { AnalyticsInitialEvent, SendAnalyticsObject } from '../core/Analytics/types';

export class UIElement<P extends UIElementProps = any> extends BaseElement<P> implements IUIElement {
Expand Down Expand Up @@ -76,18 +76,6 @@ export class UIElement<P extends UIElementProps = any> extends BaseElement<P> im
component = this.constructor['type'] === 'scheme' || this.constructor['type'] === 'bcmc' ? this.constructor['type'] : this.props.type;
}

const { type } = analyticsObj;

if (type === ANALYTICS_RENDERED_STR || type === ANALYTICS_CONFIGURED_STR) {
// Check if it's a storedCard
if (component === 'scheme') {
if (hasOwnProperty(this.props, 'supportedShopperInteractions')) {
analyticsObj.isStoredPaymentMethod = true;
analyticsObj.brand = this.props.brand;
}
}
}

this.props.modules?.analytics.sendAnalytics(component, analyticsObj);
}

Expand Down

0 comments on commit c248b43

Please sign in to comment.