@@ -5,6 +5,7 @@ import { Card } from '../../../src';
5
5
import { Container } from '../Container' ;
6
6
import { searchFunctionExample } from '../../../../playground/src/utils' ;
7
7
import { CardWith3DS2Redirect } from './cardStoryHelpers/CardWith3DS2Redirect' ;
8
+ import './cardStoryHelpers/storedCard.style.scss' ;
8
9
9
10
type CardStory = StoryConfiguration < CardConfiguration > ;
10
11
@@ -20,6 +21,53 @@ const createComponent = (args: PaymentMethodStoryProps<CardConfiguration>, conte
20
21
return < Container element = { card } /> ;
21
22
} ;
22
23
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
+
23
71
export const Default : CardStory = {
24
72
render : createComponent ,
25
73
args : {
@@ -160,4 +208,14 @@ export const CardWith_3DS2_Redirect: CardStory = {
160
208
}
161
209
} ;
162
210
211
+ export const StoredCard : CardStory = {
212
+ render : createStoredCardComponent ,
213
+ args : {
214
+ componentConfiguration : {
215
+ _disableClickToPay : true ,
216
+ hideCVC : false
217
+ }
218
+ }
219
+ } ;
220
+
163
221
export default meta ;
0 commit comments