Skip to content

Commit 76c88ac

Browse files
SK-1853 README and sample for masking (#175)
1 parent 8e7f516 commit 76c88ac

5 files changed

Lines changed: 194 additions & 2 deletions

File tree

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ const options = {
321321
enableCopy: false, // Optional, enables the copy icon in collect and reveal elements to copy text to clipboard. Defaults to 'false').
322322
allowedFileType: string[], // Optional, allowed extensions for the file to be uploaded.
323323
cardMetadata: {}, // Optional, metadata to control card number element behavior. (only applicable for CARD_NUMBER ElementType).
324+
masking: true, // Optional, indicates whether the input should be masked. Defaults to 'false'.
325+
maskingChar: '*', // Optional, character used for masking input when masking is enabled. Defaults to '*'.
324326
}
325327
```
326328

@@ -371,6 +373,63 @@ const cardMetadata = {
371373
- `HIPERCARD`
372374
- `CARTES_BANCAIRES`
373375

376+
`masking` : A boolean value for whether to mask the input of the element. When masking is enabled, user input will be replaced with a masking character.
377+
The default masking character is `*`, but you can customize masking character using the maskingChar property.
378+
379+
`maskingChar`: A single character used to mask the input when masking is enabled. Defaults to `*`, but can be customized to any character of your choice.
380+
381+
***Collect Element Options examples for masking***:
382+
383+
Example for CVV:
384+
```jsx
385+
const options = {
386+
required: true,
387+
enableCopy: false,
388+
masking: true,
389+
maskingChar: '',
390+
}
391+
```
392+
User input: "1234"
393+
Value displayed in CVV: "••••"
394+
395+
Example for CARDHOLDER_NAME:
396+
```jsx
397+
const options = {
398+
required: true,
399+
enableCopy: false,
400+
masking: true,
401+
}
402+
```
403+
User input: "John Doe"
404+
Value displayed in CARDHOLDER_NAME: "********"
405+
406+
Example for CARD_NUMBER:
407+
```jsx
408+
const options = {
409+
required: true,
410+
enableCopy: false,
411+
masking: true,
412+
maskingChar: '#'
413+
}
414+
```
415+
User input: "4111 1111 1111 1111"
416+
Value displayed in CARD_NUMBER: "#### #### #### ####"
417+
418+
Example for PIN:
419+
```jsx
420+
const options = {
421+
required: true,
422+
enableCopy: false,
423+
masking: true,
424+
maskingChar: '&'
425+
}
426+
```
427+
User input: "98364721"
428+
Value displayed in PIN: "&&&&&&&&"
429+
430+
**Note**:
431+
- Unmasked data will be stored in the vault.
432+
374433
### Step 3: Collect data from Elements
375434

376435
When the form is ready to be submitted, call the `collect(options?)` method on the container object. The `options` parameter takes a object of optional parameters as shown below:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"webpack-merge": "^5.8.0"
8383
},
8484
"dependencies": {
85-
"skyflow-js": "^2.1.3",
85+
"skyflow-js": "^2.2.0",
8686
"uuid": "^9.0.0"
8787
},
8888
"peerDependencies": {

samples/SkyflowElements/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"dependencies": {
2525
"react": "^19.0.0",
2626
"react-dom": "^19.0.0",
27-
"skyflow-react-js": "^2.2.0"
27+
"skyflow-react-js": "^2.3.0"
2828
}
2929
}

samples/SkyflowElements/src/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import DynamicRevealElements from './components/DynamicRevealElements';
1515
import CardBrandChoice from './components/CardBrandChoice';
1616
import ThreeDSHelperFunctions from './components/3DSHelperFunctions';
1717
import OverrideDefaultErrors from './components/OverrideDefaultErrors'
18+
import Masking from './components/Masking';
1819

1920
const App = () => {
2021

@@ -107,6 +108,13 @@ const App = () => {
107108
</p>
108109
<OverrideDefaultErrors />
109110
</div>
111+
<br />
112+
<div id='Sample for masking'>
113+
<p>
114+
<b>Masking input</b>
115+
</p>
116+
<Masking />
117+
</div>
110118
</div>
111119
);
112120
};
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import React from 'react';
2+
import {
3+
CardNumberElement,
4+
useCollectContainer,
5+
useMakeSkyflowStyles,
6+
CardHolderNameElement,
7+
CVVElement,
8+
PinElement,
9+
InputFieldElement,
10+
} from 'skyflow-react-js';
11+
12+
const Masking = () => {
13+
const container = useCollectContainer();
14+
15+
const handleCollect = () => {
16+
const response = container.collect();
17+
response
18+
.then((res: unknown) => {
19+
console.log(JSON.stringify(res));
20+
})
21+
.catch((e: unknown) => {
22+
console.log(e);
23+
});
24+
};
25+
26+
const useStyles = useMakeSkyflowStyles({
27+
inputStyles: {
28+
base: {
29+
border: '1px solid black',
30+
borderRadius: '4px',
31+
color: '#1d1d1d',
32+
padding: '10px 16px',
33+
fontFamily: '"Roboto", sans-serif'
34+
},
35+
complete: {
36+
color: '#4caf50',
37+
},
38+
empty: {},
39+
focus: {},
40+
invalid: {
41+
color: '#f44336',
42+
},
43+
global: {
44+
'@import' :'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")',
45+
}
46+
},
47+
labelStyles: {
48+
base: {
49+
fontSize: '16px',
50+
fontWeight: 'bold',
51+
fontFamily: '"Roboto", sans-serif'
52+
},
53+
global: {
54+
'@import' :'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")',
55+
},
56+
requiredAsterisk:{
57+
color: 'red'
58+
}
59+
},
60+
errorTextStyles: {
61+
base: {
62+
color: 'red',
63+
fontFamily: '"Roboto", sans-serif'
64+
},
65+
global: {
66+
'@import' :'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")',
67+
},
68+
},
69+
});
70+
71+
const classes = useStyles();
72+
73+
return (
74+
<div>
75+
<CardNumberElement
76+
id={'collectCardNumber'}
77+
container={container}
78+
table={'cards'}
79+
classes={classes}
80+
column={'card_number'}
81+
label='Card number'
82+
options={{masking: true}}
83+
/>
84+
<CardHolderNameElement
85+
id={'collectCardholderName'}
86+
container={container}
87+
table={'cards'}
88+
classes={classes}
89+
column={'cardholder_name'}
90+
label='Name'
91+
options={{required: true, masking: false}}
92+
/>
93+
<CVVElement
94+
id={'collectCvv'}
95+
container={container}
96+
table={'cards'}
97+
classes={classes}
98+
column={'card_cvv'}
99+
label='cvv'
100+
options={{masking: true, maskingChar: "#"}}
101+
/>
102+
<PinElement
103+
id={'collectPin'}
104+
container={container}
105+
table={'cards'}
106+
classes={classes}
107+
column={'card_pin'}
108+
label='Pin'
109+
options={{masking: true, maskingChar: "&"}}
110+
/>
111+
<InputFieldElement
112+
id={'collectSSN'}
113+
container={container}
114+
table={'cards'}
115+
classes={classes}
116+
column={'ssn'}
117+
label='SSN'
118+
options={{format: 'XXX-XX-XXXX', masking: true}}
119+
/>
120+
<button onClick={handleCollect}>Collect</button>
121+
</div>
122+
);
123+
};
124+
125+
export default Masking;

0 commit comments

Comments
 (0)