Skip to content

Commit 6e99553

Browse files
authored
Add integration with CMP (#72)
* add CMP integration * update CMP integration * improve CMP integration * fix linter * update readme + remove getAccessToken function * update examples, add default validations and year length * update readme * improve cmp bugs * update examples * mock access token * added missed type * remove console.log
1 parent 814152a commit 6e99553

31 files changed

+515
-352
lines changed

.circleci/config.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- run:
3939
name: Build
4040
command: |
41-
yarn build
41+
yarn build
4242
- run:
4343
name: Authenticate with NPM
4444
command: |
@@ -47,7 +47,7 @@ jobs:
4747
name: Publish package
4848
command: |
4949
npm publish --access public
50-
50+
5151
scan-sast-pr:
5252
parameters:
5353
default_branch:
@@ -62,7 +62,7 @@ jobs:
6262
steps:
6363
- checkout
6464
- run:
65-
name: "Semgrep diff scan"
65+
name: 'Semgrep diff scan'
6666
command: semgrep ci
6767

6868
scan-sast-full:
@@ -78,7 +78,7 @@ jobs:
7878
steps:
7979
- checkout
8080
- run:
81-
name: "Semgrep full scan"
81+
name: 'Semgrep full scan'
8282
command: semgrep ci
8383

8484
workflows:
@@ -101,7 +101,7 @@ workflows:
101101
- test:
102102
context:
103103
- frontend-deploy
104-
- circleci
104+
- circleci
105105
- test-react-17
106106
- publish:
107107
context: frontend-deploy
@@ -110,7 +110,7 @@ workflows:
110110
ignore: /.*/
111111
tags:
112112
only: /^v.*/
113-
113+
114114
scheduled-security-scan:
115115
when: << pipeline.parameters.nightly-security-scan >>
116116
jobs:
@@ -119,4 +119,3 @@ workflows:
119119
- security-tools
120120
- frontend-deploy
121121
- circleci
122-

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
"import/export": 0,
3333
"no-unused-vars": "off"
3434
}
35-
}
35+
}

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
2. Create your feature branch (`git checkout -b feaure/my-amazing-feature`)
55
3. Commit your changes (`git commit -m 'feature: added amazing feature'`)
66
4. Push to the branch (`git push origin feature/my-amazing-feature`)
7-
5. Open a Pull Request
7+
5. Open a Pull Request

.github/ISSUE_TEMPLATE.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
## Expected Behavior
2+
23
<!--- If you're describing a bug, tell us what should happen -->
34
<!--- If you're suggesting a change/improvement, tell us how it should work -->
45

56
## Current Behavior
7+
68
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
79
<!--- If suggesting a change/improvement, explain the difference from expected behavior -->
810

911
## Possible Solution
12+
1013
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
1114
<!--- or ideas how to implement the addition or change -->
1215

1316
## Steps to Reproduce (for bugs)
17+
1418
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
1519
<!--- reproduce this bug. Include code to reproduce, if relevant -->
20+
1621
1.
1722
2.
1823
3.
1924
4.
2025

2126
## Context
27+
2228
<!--- How has this issue affected you? What are you trying to accomplish? -->
2329
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
2430

2531
## Your Environment
32+
2633
<!--- Include as many relevant details about the environment you experienced the bug in -->
27-
* Version used:
28-
* Browser Name and version:
29-
* Operating System and version (desktop or mobile):
30-
* Link to your project:
34+
35+
- Version used:
36+
- Browser Name and version:
37+
- Operating System and version (desktop or mobile):
38+
- Link to your project:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
## Description
2+
23
<!--- Describe your changes in detail -->
34

45
## Motivation and Context
6+
57
<!--- Why is this change required? What problem does it solve? -->
68
<!--- If it fixes an open issue, please link to the issue here. -->
79

810
## How Has This Been Tested?
11+
912
<!--- Please describe in detail how you tested your changes. -->
1013
<!--- Include details of your testing environment, the tests you ran to -->
1114
<!--- see how your change affects other areas of the code, etc. -->
1215

1316
## Screenshots (if appropriate):
1417

1518
## Types of Changes
19+
1620
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
21+
1722
- [ ] Bug fix (non-breaking change that fixes an issue)
1823
- [ ] New feature (non-breaking change that adds functionality)
1924
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
2025

2126
## Checklist:
27+
2228
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
2329
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
30+
2431
- [ ] My code follows the code style of this project.
2532
- [ ] My change requires a change to the documentation.
2633
- [ ] I have updated the documentation accordingly.

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
If you have found a security issue, please do not open GitHub issues or pull requests - this makes the problem immediately visible to everyone, including malicious actors. Security issues in the SDK can be safely reported to VGS by email: [email protected]
44

5-
**Before reporting security issue please read this** [guide](https://www.verygoodsecurity.com/learn/reporting-security-vulnerability).
5+
**Before reporting security issue please read this** [guide](https://www.verygoodsecurity.com/learn/reporting-security-vulnerability).

README.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,22 @@ export default App;
9898

9999
<br/>
100100

101-
### 3. Define secure input fields:
102-
103-
| Collect.js input type | Collect.js React Component | Default Prop Values |
104-
| ---------------------- | ------------------------------------------- | ---------------------------------------------------------- |
105-
| `text` | `<VGSCollectForm.TextField/>` | ` {type: 'text', placeholder: 'Cardholder Name'}` |
106-
| `card-number` | `<VGSCollectForm.CardNumberField/>` | `{type: 'card-number', placeholder: 'Credit Card Number'}` |
107-
| `card-expiration-date` | `<VGSCollectForm.CardExpirationDateField/>` | `{type: 'card-expiration-date', placeholder: 'MM/YY'}` |
108-
| `card-security-code` | `<VGSCollectForm.CardSecurityCodeField/>` | `{type: 'card-security-code', placeholder: 'CVC/CVV'}` |
109-
| `password` | `<VGSCollectForm.PasswordField/>` | `{type: 'password', placeholder: 'Enter Password'}` |
110-
| `ssn` | `<VGSCollectForm.SSNField/>` | `{type: 'ssn', placeholder: 'SSN'}` |
111-
| `zip-code` | `<VGSCollectForm.ZipCodeField/>` | `{type: 'zip-code', placeholder: 'Zip Code'}` |
112-
| `number` | `<VGSCollectForm.NumberField/>` | `{type: 'number', placeholder: 'Number'}` |
113-
| `textarea` | `<VGSCollectForm/TextareaField/>` | `{type: 'textarea', placeholder: 'Comment'}` |
114-
| `file` | `<VGSCollectForm/FileField/>` | `{type: 'file', placeholder: ''}` |
115-
| `date` | `<VGSCollectForm/DateField/>` | `{type: 'date', placeholder: ''}` |
101+
### 3. Define secure input fields
102+
103+
| **Collect.js input type** | **Collect.js React Component** | **Default Prop Values** |
104+
|---------------------------|---------------------------------------------|------------------------------------------------------------------------------------------|
105+
| `text` | `<VGSCollectForm.TextField />` | `{ type: 'text', placeholder: 'Cardholder Name' }` |
106+
| `text` | `<VGSCollectForm.CardholderField />` | `{ type: 'text', name: 'cardholder', placeholder: 'Cardholder' }` |
107+
| `card-number` | `<VGSCollectForm.CardNumberField />` | `{ type: 'card-number', name: 'pan', validations: ['required', 'validCardNumber'], placeholder: 'Credit Card Number' }` |
108+
| `card-expiration-date` | `<VGSCollectForm.CardExpirationDateField />`| `{ type: 'card-expiration-date', name: 'exp-date', validations: ['required', 'validCardExpirationDate'], yearLength: 2, placeholder: 'MM/YY' }` |
109+
| `card-security-code` | `<VGSCollectForm.CardSecurityCodeField />` | `{ type: 'card-security-code', name: 'cvc', validations: ['required', 'validCardSecurityCode'], placeholder: 'CVC/CVV' }` |
110+
| `password` | `<VGSCollectForm.PasswordField />` | `{ type: 'password', placeholder: 'Enter Password' }` |
111+
| `ssn` | `<VGSCollectForm.SSNField />` | `{ type: 'ssn', placeholder: 'SSN' }` |
112+
| `zip-code` | `<VGSCollectForm.ZipCodeField />` | `{ type: 'zip-code', placeholder: 'Zip Code' }` |
113+
| `number` | `<VGSCollectForm.NumberField />` | `{ type: 'number', placeholder: 'Number' }` |
114+
| `textarea` | `<VGSCollectForm.TextareaField />` | `{ type: 'textarea', placeholder: 'Comment' }` |
115+
| `file` | `<VGSCollectForm.FileField />` | `{ type: 'file', placeholder: '' }` |
116+
| `date` | `<VGSCollectForm.DateField />` | `{ type: 'date', placeholder: '' }` |
116117

117118
The complete list of supported properties you can find here: https://www.verygoodsecurity.com/docs/api/collect/#api-formfield.
118119
All configuration properties available in the Reference Documentation can be passed in the component props using the same name.
@@ -122,8 +123,7 @@ _Example:_
122123
```javascript
123124
import { VGSCollectForm } from '@vgs/collect-js-react';
124125

125-
const { CardNumberField, CardExpirationDateField, CardSecurityCodeField } =
126-
VGSCollectForm;
126+
const { CardNumberField, CardExpirationDateField, CardSecurityCodeField } = VGSCollectForm;
127127

128128
const myApp = () => {
129129
const onSubmitCallback = (status, data) => {};
@@ -134,7 +134,7 @@ const myApp = () => {
134134
vaultId='<vault_id>'
135135
environment='<environment>'
136136
action='/post'
137-
submitParamethers={{
137+
submitParameters={{
138138
headers: {
139139
myHeader: 'MyHeader'
140140
}
@@ -192,12 +192,7 @@ The library exposes the following handlers: `onFocus`, `onBlur`, `onUpdate`, `on
192192
In order to access the form state and response from the hook, wrap consumer component with the form in `VGSCollectProvider` context provider.
193193

194194
```javascript
195-
import {
196-
VGSCollectProvider,
197-
useVGSCollectState,
198-
useVGSCollectResponse,
199-
VGSCollectForm
200-
} from '@vgs/collect-js-react';
195+
import { VGSCollectProvider, useVGSCollectState, useVGSCollectResponse, VGSCollectForm } from '@vgs/collect-js-react';
201196

202197
const { TextField } = VGSCollectForm;
203198

@@ -219,17 +214,43 @@ const VGSCollectSecureForm = () => {
219214
}
220215
}, [state]);
221216

217+
return (
218+
<VGSCollectForm vaultId='<vault_id>' environment='<environment>' action='/post'>
219+
<TextField name='cardholder-name' validations={['required']} placeholder='Cardholder name' />
220+
</VGSCollectForm>
221+
);
222+
};
223+
```
224+
225+
## Integration with Card Management Platform
226+
227+
You can create a predefined Collect.js form to integrate with the [VGS Card Management Platform](https://docs.verygoodsecurity.com/card-management/api)
228+
229+
```javascript
230+
import { VGSCollectForm } from '@vgs/collect-js-react';
231+
232+
const {CardholderField, CardNumberField, CardExpirationDateField, CardSecurityCodeField } = VGSCollectForm;
233+
234+
const myApp = () => {
235+
const onSubmitCallback = (status, data) => {};
236+
const onUpdateCallback = (state) => {};
237+
222238
return (
223239
<VGSCollectForm
224240
vaultId='<vault_id>'
225241
environment='<environment>'
226-
action='/post'
242+
submitParamethers={{
243+
createCard: {
244+
auth: <vgs_auth_token>
245+
}
246+
}}
247+
onUpdateCallback={onUpdateCallback}
248+
onSubmitCallback={onSubmitCallback}
227249
>
228-
<TextField
229-
name='cardholder-name'
230-
validations={['required']}
231-
placeholder='Cardholder name'
232-
/>
250+
<CardholderField css={{}} />
251+
<CardNumberField css={{}} />
252+
<CardExpirationDateField css={{}} />
253+
<CardSecurityCodeField css={{}} />
233254
</VGSCollectForm>
234255
);
235256
};

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ NOTE: Before start, make sure that you have configured `.env` file
1010
REACT_APP_VAULT_ID=<vault_id>
1111
REACT_APP_ENVIRONMENT=<env>
1212
REACT_APP_COLLECT_VERSION=<collect_version>
13-
```
13+
```

example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"devDependencies": {
2929
"@babel/plugin-syntax-object-rest-spread": "^7.8.3"
3030
},
31-
3231
"browserslist": {
3332
"production": [
3433
">0.2%",

example/public/index.html

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
7+
<meta name="theme-color" content="#000000" />
38

4-
<head>
5-
<meta charset="utf-8" />
6-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
7-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
8-
<meta name="theme-color" content="#000000" />
9-
10-
<!--
9+
<!--
1110
manifest.json provides metadata used when your web app is added to the
1211
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
1312
-->
14-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
13+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
1514

16-
<!--
15+
<!--
1716
Notice the use of %PUBLIC_URL% in the tags above.
1817
It will be replaced with the URL of the `public` folder during the build.
1918
Only files inside the `public` folder can be referenced from the HTML.
@@ -22,17 +21,15 @@
2221
work correctly both with client-side routing and a non-root public URL.
2322
Learn how to configure a non-root public URL by running `npm run build`.
2423
-->
25-
<title>collect-js-react</title>
26-
</head>
24+
<title>collect-js-react</title>
25+
</head>
2726

28-
<body>
29-
<noscript>
30-
You need to enable JavaScript to run this app.
31-
</noscript>
27+
<body>
28+
<noscript> You need to enable JavaScript to run this app. </noscript>
3229

33-
<div id="root"></div>
30+
<div id="root"></div>
3431

35-
<!--
32+
<!--
3633
This HTML file is a template.
3734
If you open it directly in the browser, you will see an empty page.
3835
@@ -42,6 +39,5 @@
4239
To begin the development, run `npm start` or `yarn start`.
4340
To create a production bundle, use `npm run build` or `yarn build`.
4441
-->
45-
</body>
46-
47-
</html>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)