@payyo/ptp-js 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payyo/ptp-js",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "JS library for Payyo Tokenization service (PTP)",
5
5
  "private": false,
6
6
  "author": "developers@payyo.ch",
package/src/form/index.js CHANGED
@@ -7,11 +7,13 @@ module.exports = function (config) {
7
7
 
8
8
  const EVENT_ON_CHANGE = 'change';
9
9
  const EVENT_ON_READY = 'ready';
10
+ const EVENT_ON_FOCUS = 'focus';
11
+ const EVENT_ON_BLUR = 'blur';
10
12
 
11
- let mainField = null;
13
+ let mainFieldName = null;
12
14
 
13
15
  function generateRandomId() {
14
- return Math.random().toString(36).substr(2, 9);
16
+ return Math.random().toString(36).substring(2, 9);
15
17
  }
16
18
 
17
19
  function log() {
@@ -48,11 +50,9 @@ module.exports = function (config) {
48
50
  fieldNames.push(fieldName);
49
51
  }
50
52
 
51
- mainField = fieldNames[0];
53
+ mainFieldName = fieldNames[0];
52
54
 
53
- for (let i = 0; i < fieldNames.length; i++) {
54
- createIframe(fields[fieldNames[i]]);
55
- }
55
+ createIframe(fields[mainFieldName]);
56
56
  };
57
57
 
58
58
  function createIframe(field) {
@@ -67,6 +67,7 @@ module.exports = function (config) {
67
67
  form_id: formId,
68
68
  field_name: field.fieldName,
69
69
  field_names: fieldNames,
70
+ main_field_name: mainFieldName,
70
71
  title: field.title,
71
72
  placeholder: field.placeholder,
72
73
  input_type: field.inputType,
@@ -74,7 +75,7 @@ module.exports = function (config) {
74
75
  })).toString(),
75
76
  frameborder: "0",
76
77
  scrolling: "no",
77
- style: 'width: 100%; height: 100%',
78
+ style: 'width: 100%; height: 100%; border: none;',
78
79
  },
79
80
  iframe = document.createElement('iframe');
80
81
 
@@ -90,6 +91,12 @@ module.exports = function (config) {
90
91
  field.iframe = iframe[0];
91
92
  }
92
93
 
94
+ function createRemainingIframes() {
95
+ for (let i = 1; i < fieldNames.length; i++) {
96
+ createIframe(fields[fieldNames[i]]);
97
+ }
98
+ }
99
+
93
100
  function postMessage(type, params = {}) {
94
101
  const message = {params: params, type: type, formId: formId, messageId: null};
95
102
 
@@ -99,7 +106,7 @@ module.exports = function (config) {
99
106
  message.messageId = messageId;
100
107
 
101
108
  log('send message', message);
102
- window.frames[fields[mainField].iFrameName].postMessage(message, '*');
109
+ window.frames[fields[mainFieldName].iFrameName].postMessage(message, '*');
103
110
  });
104
111
  }
105
112
 
@@ -112,6 +119,14 @@ module.exports = function (config) {
112
119
  handlers[EVENT_ON_READY] = handler;
113
120
  }
114
121
 
122
+ form.onFocus = function (handler) {
123
+ handlers[EVENT_ON_FOCUS] = handler;
124
+ }
125
+
126
+ form.onBlur = function (handler) {
127
+ handlers[EVENT_ON_BLUR] = handler;
128
+ }
129
+
115
130
  form.validate = function () {
116
131
  return postMessage('validateRequest');
117
132
  }
@@ -175,16 +190,28 @@ module.exports = function (config) {
175
190
  return;
176
191
  }
177
192
  fields[r.fieldName].isReady = true;
178
- const ready = Object.keys(fields)
193
+
194
+ if (r.fieldName === mainFieldName) {
195
+ createRemainingIframes();
196
+ }
197
+
198
+ const areAllReady = Object.keys(fields)
179
199
  .map((key) => fields[key].isReady)
180
200
  .reduce((a, b) => a && b, true);
181
201
 
182
- if (ready) {
183
- emitEvent('ready');
202
+ if (areAllReady) {
203
+ addOnTouchedEventListener();
204
+ emitEvent(EVENT_ON_READY);
184
205
  }
185
206
  },
186
207
  fieldChanged: function (response) {
187
- emitEvent('change', response);
208
+ emitEvent(EVENT_ON_CHANGE, response);
209
+ },
210
+ fieldFocused: function (response) {
211
+ emitEvent(EVENT_ON_FOCUS, response);
212
+ },
213
+ fieldBlurred: function (response) {
214
+ emitEvent(EVENT_ON_BLUR, response);
188
215
  },
189
216
  };
190
217
 
package/README.doc.md DELETED
@@ -1,98 +0,0 @@
1
- # PTP Form/Field
2
-
3
- This repository is part of the PTP project. The goal of this JS library to provide a secure way for non-PCI compliant
4
- applications to collect CHD (card holder data), tokenize it and use the tokens to make a payment via regular Payyo API
5
-
6
- This library consists of two parts:
7
-
8
- 1. Form - manages a form of secure fields
9
- 2. and Field - secure field itself
10
-
11
- Each field which is may contain CHD is an HTML IFrame and JS code hosted on PCI-compliant environment. Field and Form
12
- components are communicates with each other by message passing. The Field component avoids exposing CHD from IFrame to
13
- the Form component which is supposed to be running on client (non-PCI -compliant environment).
14
-
15
- ## Development
16
-
17
- ### Requirements
18
-
19
- Before you start please make sure that you have installed and configured the following tools and utils:
20
-
21
- 1. [Docker](https://docs.docker.com/engine/install/)
22
-
23
- ### Install project dependencies
24
-
25
- Project requirements are managed by [Yarn](https://yarnpkg.com/) which is running inside Docker container.
26
- You can install all the dependencies with the command:
27
-
28
- ```shell
29
- make inastall
30
- ```
31
-
32
- To run arbitrary Yarn command you can use Makefile target like this:
33
-
34
- ```shell
35
- make yarn <command> [arguments]
36
- ```
37
-
38
- ### Dev Server
39
-
40
- Webpack dev server is used for development. To run it execute the following command
41
-
42
- ```shell
43
- make serve
44
- ```
45
-
46
- The dev server serves the test page with example form. The page used PTP project as backend to tokenize the card holder
47
- data (CHD). To have a fully functional application please make sure:
48
-
49
- 1. you need to have PTP project up and running locally
50
- 2. or adjust the project settings to use PTP SANDBOX/PROD environment as backend by adjusting `PTP_BASE_URL` variable in `package.json`
51
-
52
- ## CI/CD
53
-
54
- The project CI/DC is AWS Code Tools. See CI configuration in `buildspec.yml` and `buildspec-npm.yml`.
55
- See details in [Deployment](#deployment) and [NPM package publishing](#npm-package-publishing) sections.
56
-
57
- ## Deployment
58
-
59
- ### Field component
60
-
61
- Each push to the repository produces a build which can be deployed to with AWS Code Tools. The `fielld` component is
62
- deployed to AWS S3 and distributed with AWS CloudFront. The client part is published to npm registry.
63
- See [NPM package publishing](#npm-package-publishing) section for more details.
64
-
65
- ### Form component
66
-
67
- Form component is distributed via [NPM](https://www.npmjs.com/) to let the library easily pulled and used by Payyo team
68
- as well as other integrators.
69
-
70
- ## NPM package publishing
71
-
72
- > ⚠ **Note**: Before publishing the package ensure that the package version is updated in `package.json`.
73
-
74
- To make the library available to the public and used in other Payyo projects and other user you need to publish it to NPM.
75
- We have the NPM account registered to `developers@payyo.ch` email and organization `payyo` defined there.
76
-
77
- ### Init the package
78
-
79
- This needs to be run once when package is created or renamed:
80
-
81
- ```shell
82
- npm init --scope=<your_org_name>
83
- ```
84
-
85
- For example:
86
-
87
- ```shell
88
- npm init --scope=payyo
89
- ```
90
-
91
- The command will create a `package.json` file with the provided package details.
92
-
93
- ### Publish NPM package
94
-
95
- Run the following commands to publish the package to NPM and make it public:
96
-
97
- 1. `make npmlogin` and provide your credentials
98
- 2. `make publish` to publish the package