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

Added CustomCard story to Storybook #2806

Merged
merged 27 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
046559d
Added CustomCard story
sponglord Aug 22, 2024
fda7267
Moved CustomCardContainer
sponglord Aug 22, 2024
193a049
Created payment related utils file for the customCard
sponglord Aug 22, 2024
ff34bb6
Fixing linting errors
sponglord Aug 22, 2024
8f97d40
Fixing linting errors, still!
sponglord Aug 22, 2024
492cc47
Fixing linting errors, still, still
sponglord Aug 22, 2024
fb6fbf6
Excluding customCard.style.scss from linting
sponglord Aug 22, 2024
be52afe
Excluding customCard.style.scss from linting
sponglord Aug 22, 2024
60b7c01
Excluding customCard.style.scss from linting
sponglord Aug 22, 2024
e6e27c7
Merge branch 'refs/heads/main' into feature/adding_CustomCard_story
sponglord Aug 22, 2024
e4d2149
Expose customCard to top level widow object
sponglord Aug 23, 2024
b87f07e
Merge branch 'refs/heads/main' into feature/adding_CustomCard_story
sponglord Aug 23, 2024
34fbc8e
Adding brands to CustomCard story to test dual branding
sponglord Aug 23, 2024
800d320
Just pass args to container instead of whole context
sponglord Aug 26, 2024
0f95bce
Changed title of story to indicate it also does native 3DS2
sponglord Aug 28, 2024
505761c
Merge branch 'refs/heads/main' into feature/adding_CustomCard_story
sponglord Aug 28, 2024
8c146d5
Fixing merge error
sponglord Aug 28, 2024
70daab2
Reverting title
sponglord Aug 28, 2024
6a28354
Replacing CustomCardContainer.tsx with CustomCardHelper.tsx
sponglord Aug 28, 2024
eb2c200
Allow possibility to uss sessions (which will lead to a redirect 3DS2…
sponglord Aug 28, 2024
957311c
Upped securedFields to v5.3.0
sponglord Aug 28, 2024
b1170a2
CustomCard always adds origin when formatting data
sponglord Aug 29, 2024
1c378e0
Rationalised what happens with 3DS2 in both sessions & advanced flow …
sponglord Aug 29, 2024
aeb22a2
Added ts-ignore
sponglord Aug 29, 2024
d840f40
created type so we can dispense with ts-ignore
sponglord Aug 29, 2024
531f3f8
Fixed multiple imports from same file
sponglord Aug 30, 2024
849cd69
Added comment
sponglord Aug 30, 2024
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
6 changes: 3 additions & 3 deletions packages/lib/src/components/CustomCard/CustomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import collectBrowserInfo from '../../utils/browserInfo';
import triggerBinLookUp from '../internal/SecuredFields/binLookup/triggerBinLookUp';
import { CbObjOnBinLookup, CbObjOnFocus } from '../internal/SecuredFields/lib/types';
import { BrandObject } from '../Card/types';
import { getCardImageUrl } from '../internal/SecuredFields/utils';
import { getCardImageUrl, fieldTypeToSnakeCase } from '../internal/SecuredFields/utils';
import { TxVariants } from '../tx-variants';
import { CustomCardConfiguration } from './types';
import { fieldTypeToSnakeCase } from '../internal/SecuredFields/utils';
import { ANALYTICS_FOCUS_STR, ANALYTICS_UNFOCUS_STR } from '../../core/Analytics/constants';
import { SendAnalyticsObject } from '../../core/Analytics/types';

Expand Down Expand Up @@ -47,7 +46,8 @@ export class CustomCard extends UIElement<CustomCardConfiguration> {
...this.state.data,
...(sfBrand && { brand: sfBrand })
},
browserInfo: this.browserInfo
browserInfo: this.browserInfo,
origin: !!window && window.location.origin
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ENCRYPTED_SECURITY_CODE_4_DIGITS = 'encryptedSecurityCode4digits';

export const GIFT_CARD = 'giftcard';

export const SF_VERSION = '5.2.1';
export const SF_VERSION = '5.3.0';

export const DEFAULT_CARD_GROUP_TYPES = ['amex', 'mc', 'visa'];

Expand Down
40 changes: 40 additions & 0 deletions packages/lib/storybook/stories/cards/CustomCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { CustomCardStoryConfiguration, MetaConfiguration } from '../types';
import { CustomCardConfiguration } from '../../../src/components/CustomCard/types';
import './customCardHelpers/customCard.style.scss';
import { styles, setFocus, onBrand, onConfigSuccess, onBinLookup, onChange, setCCErrors } from './customCardHelpers/customCard.config';
import { CustomCardHelper } from './customCardHelpers/CustomCardHelper';

type customCardStory = CustomCardStoryConfiguration<CustomCardConfiguration>;

const meta: MetaConfiguration<CustomCardConfiguration> = {
title: 'Cards/Custom Card'
};

export const Default: customCardStory = {
render: args => {
return <CustomCardHelper contextArgs={args} />;
},
args: {
componentConfiguration: {
brands: ['mc', 'visa', 'amex', 'bcmc', 'maestro', 'cartebancaire', 'synchrony_plcc'],
styles,
onConfigSuccess,
onBrand,
// onBinValue: cbObj => {
// if (cbObj.encryptedBin) {
// console.log('onBinValue', cbObj);
// }
// },
onFocus: setFocus,
onBinLookup,
onChange,
onValidationError: errors => {
errors.forEach(setCCErrors);
}
},
useSessions: false,
force3DS2Redirect: false
}
};

export default meta;
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { useEffect, useRef, useState } from 'preact/hooks';
import { createAdvancedFlowCheckout } from '../../../helpers/create-advanced-checkout';
import { createSessionsCheckout } from '../../../helpers/create-sessions-checkout';
import { CustomCard } from '../../../../src';
import { setUpUtils, createPayButton } from './customCard.utils';

export const CustomCardHelper = ({ contextArgs }) => {
const container = useRef(null);
const checkout = useRef(null);
const [element, setElement] = useState(null);
const [errorMessage, setErrorMessage] = useState(null);

const createCheckout = async () => {
const { useSessions, showPayButton, countryCode, shopperLocale, amount } = contextArgs;

checkout.current = useSessions
? await createSessionsCheckout({ showPayButton, countryCode, shopperLocale, amount })
: await createAdvancedFlowCheckout({
showPayButton,
countryCode,
shopperLocale,
amount
});

const customCard = new CustomCard(checkout.current, { ...contextArgs.componentConfiguration });

setElement(customCard);

// Custom card specific
globalThis.customCard = customCard; // customCard..config & customCard.utils access the component through Storybook's globalThis
globalThis.parent.window['customCard'] = customCard; // expose to top level window, so a user can access window.customCard

setUpUtils(contextArgs, container);
globalThis.payBtn = createPayButton('.secured-fields', customCard, 'customcard');
};

useEffect(() => {
void createCheckout();
}, [contextArgs]);

useEffect(() => {
if (element?.isAvailable) {
element
.isAvailable()
.then(() => {
element.mount(container.current);
})
.catch(error => {
setErrorMessage(error.toString());
});
} else if (element) {
element.mount(container.current);
}
}, [element]);

return (
<div>
{errorMessage ? (
<div>{errorMessage}</div>
) : (
<div id={'topLevelHolder'}>
<div
ref={container}
id="component-root"
className="component-wrapper secured-fields"
// @ts-ignore just hiding for better UX experience
style={'display:none;'}
>
<span className="pm-image">
<img
className="pm-image-1"
width="40"
src="https://checkoutshopper-test.adyen.com/checkoutshopper/images/logos/nocard.svg"
alt="card"
/>
</span>
<span className="pm-image-dual">
<img className="pm-image-dual-1" width="40" alt="" />
<img className="pm-image-dual-2" width="40" alt="" />
</span>
<div className="pm-form-label">
<span className="pm-form-label__text">Card number:</span>
<span className="pm-input-field" data-cse="encryptedCardNumber" data-uid="adyen-checkout-encryptedCardNumber-1"></span>
<span className="pm-form-label__error-text">Please enter a valid credit card number</span>
</div>
<div className="pm-form-label pm-form-label--exp-month">
<span className="pm-form-label__text">Expiry month:</span>
<span className="pm-input-field" data-cse="encryptedExpiryMonth" data-uid="adyen-checkout-encryptedExpiryMonth-2"></span>
<span className="pm-form-label__error-text">Date error text</span>
</div>
<div className="pm-form-label pm-form-label--exp-year">
<span className="pm-form-label__text">Expiry year:</span>
<span className="pm-input-field" data-cse="encryptedExpiryYear" data-uid="adyen-checkout-encryptedExpiryYear-3"></span>
<span className="pm-form-label__error-text">Date error text</span>
</div>
<div className="pm-form-label pm-form-label--cvc">
<span className="pm-form-label__text">CVV/CVC:</span>
<span className="pm-input-field" data-cse="encryptedSecurityCode"></span>
<span className="pm-form-label__error-text">CVC Error text</span>
</div>
</div>
<div className="card-input__spinner__holder">
<div className="card-input__spinner card-input__spinner--active">
<div className="adyen-checkout__spinner__wrapper ">
<div className="adyen-checkout__spinner adyen-checkout__spinner--large"></div>
</div>
</div>
</div>
</div>
)}
</div>
);
};
Loading
Loading