Skip to content

Commit 07e1668

Browse files
authored
adding storedCard story (#2823)
* adding storedCard story * Better markup for storedCard info * Adjusted font size in info panel
1 parent db1a712 commit 07e1668

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

packages/lib/storybook/stories/cards/Card.stories.tsx

+58
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Card } from '../../../src';
55
import { Container } from '../Container';
66
import { searchFunctionExample } from '../../../../playground/src/utils';
77
import { CardWith3DS2Redirect } from './cardStoryHelpers/CardWith3DS2Redirect';
8+
import './cardStoryHelpers/storedCard.style.scss';
89

910
type CardStory = StoryConfiguration<CardConfiguration>;
1011

@@ -20,6 +21,53 @@ const createComponent = (args: PaymentMethodStoryProps<CardConfiguration>, conte
2021
return <Container element={card} />;
2122
};
2223

24+
const createStoredCardComponent = (args: PaymentMethodStoryProps<CardConfiguration>, context) => {
25+
const { componentConfiguration } = args;
26+
const checkout = getStoryContextCheckout(context);
27+
28+
if (checkout.paymentMethodsResponse.storedPaymentMethods && checkout.paymentMethodsResponse.storedPaymentMethods.length > 0) {
29+
// We are only interested in card based storedPaymentMethods that support Ecommerce - a quick way to distinguish these is if they have a brand property
30+
let storedCardData;
31+
let storedPM;
32+
for (let i = 0; i < checkout.paymentMethodsResponse.storedPaymentMethods.length; i++) {
33+
storedPM = checkout.paymentMethodsResponse.storedPaymentMethods[i];
34+
if (storedPM.brand && storedPM.supportedShopperInteractions.includes('Ecommerce')) {
35+
storedCardData = checkout.paymentMethodsResponse.storedPaymentMethods[i];
36+
break; // exit, now we've found the first storedCard
37+
}
38+
}
39+
40+
if (storedCardData) {
41+
const card = new Card(checkout, { ...storedCardData, ...componentConfiguration });
42+
43+
return (
44+
<div>
45+
<div className={'stored-card-info'}>
46+
<p>
47+
<i>Stored card info:</i>
48+
</p>
49+
<div className={'info-container'}>
50+
<div>
51+
<div>Brand:</div>
52+
<img src={card.icon} alt={'stored-card-brand-icon'} />
53+
</div>
54+
<div className={'info-extra-item'}>
55+
<div>Last four digits:</div>
56+
<div className={'info-last-four-digits'}>{storedPM.lastFour}</div>
57+
</div>
58+
</div>
59+
</div>
60+
<Container element={card} />
61+
</div>
62+
);
63+
} else {
64+
return <div>No stored cards found</div>;
65+
}
66+
} else {
67+
return <div>No stored payment methods found</div>;
68+
}
69+
};
70+
2371
export const Default: CardStory = {
2472
render: createComponent,
2573
args: {
@@ -160,4 +208,14 @@ export const CardWith_3DS2_Redirect: CardStory = {
160208
}
161209
};
162210

211+
export const StoredCard: CardStory = {
212+
render: createStoredCardComponent,
213+
args: {
214+
componentConfiguration: {
215+
_disableClickToPay: true,
216+
hideCVC: false
217+
}
218+
}
219+
};
220+
163221
export default meta;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.stored-card-info{
2+
font-size: 0.9em;
3+
}
4+
5+
.info-container{
6+
display:flex;
7+
}
8+
9+
.info-extra-item{
10+
margin-left:30px;
11+
}
12+
13+
.info-last-four-digits{
14+
margin-top: 3px;
15+
}

0 commit comments

Comments
 (0)