@capturebridge/sdk 0.12.1 → 0.14.2

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/Verifone.js CHANGED
@@ -1,192 +1,239 @@
1
- import SignatureTablet from './SignatureTablet.js'
2
- import { BASE_URL, checkResponse } from './Common.js'
3
-
4
- /**
5
- * ControlProperty
6
- * @classdesc Form Control Properties
7
- * @see {@link Verifone#renderForm} Render a form and update control properties
8
- */
9
- export class ControlProperty {
10
- id
11
- name
12
- value
13
-
14
- /**
15
- * Instantiate a Control Property
16
- * @constructor
17
- * @param {number} id - ID of the Control on the Form
18
- * @param {string} name - Name of the property to update
19
- * @param {number|string|boolean} value - property value
20
- * @example
21
- * // A property to make a control hidden
22
- * const prop = new ControlProperty(1, "visible", false)
23
- *
24
- * // A property to change the text of a control
25
- * const prop = new ControlProperty(1, "caption", "Cancel Operation")
26
- *
27
- * // A property to change the background color of a control
28
- * const prop = new ControlProperty(1, "bg_color", "#EB9534")
29
- */
30
- constructor (id, name, value) {
31
- this.id = id
32
- this.name = name
33
- this.value = value
34
- }
35
-
36
- toJSON () {
37
- return {
38
- id: this.id,
39
- name: this.name,
40
- value: this.value
41
- }
42
- }
43
- }
44
-
45
- /**
46
- * DeviceForm
47
- * @classdesc Form to be rendered on a tablet device.
48
- * @see {@link Verifone#renderForm} Render a form
49
- */
50
- export class DeviceForm {
51
- id
52
- waitForEvents
53
- timeout
54
-
55
- /**
56
- * Instantiate a Form to be Rendered
57
- * @constructor
58
- * @param {string} id - ID of the Form
59
- * @param {bool} [waitForEvents=false] - If `true` will wait for event data to
60
- * be received on the form.
61
- * @param {number} [timeout=15] - How long, in seconds, to wait for events from
62
- * the form.
63
- * @example
64
- * // Form with no input data
65
- * const form = new DeviceForm("FP_DISPLAY")
66
- *
67
- * // Form with buttons, wait 15 seconds for event data
68
- * const form = new DeviceForm("FP_GEN_DISPLAY", true, 25)
69
- */
70
- constructor (id, waitForEvents = false, timeout = 15) {
71
- this.id = id
72
- this.waitForEvents = waitForEvents
73
- this.timeout = timeout
74
- }
75
-
76
- toJSON () {
77
- return {
78
- id: this.id,
79
- wait_for_events: this.waitForEvents,
80
- timeout: this.timeout
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Verifone
87
- * @classdesc Captures a signature and renders forms on Verifone devices.
88
- * @extends SignatureTablet
89
- * @see {@link SignatureTablet}
90
- */
91
- export class Verifone extends SignatureTablet {
92
- /**
93
- * Instantiate a Verifone Class
94
- * @constructor
95
- * @param {string} [baseURL] - Protocol, domain, and port for the service.
96
- * @example
97
- * const tablet = new Verifone()
98
- *
99
- */
100
- constructor (baseUrl = BASE_URL) {
101
- super('capture_signature_verifone', baseUrl)
102
- }
103
-
104
- /**
105
- * Not currently supported for this plugin.
106
- * @throws Not implemented error
107
- * @example
108
- * // Not currently supported for this plugin
109
- * @override
110
- */
111
- async streamUrl () {
112
- throw new Error('streamUrl() is not implemented for the Verifone Plugin')
113
- }
114
-
115
- /**
116
- * Not currently supported for this plugin.
117
- * @throws Not implemented error
118
- * @example
119
- * // Not currently supported for this plugin
120
- * @override
121
- */
122
- async getMostRecentFrame () {
123
- throw new Error('getMostRecentFrame() is not implemented for the Verifone Plugin')
124
- }
125
-
126
- /**
127
- * Not currently supported for this plugin.
128
- * @throws Not implemented error
129
- * @example
130
- * // Not currently supported for this plugin
131
- * @override
132
- */
133
- async stopFeed () {
134
- throw new Error('stopFeed() is not implemented for the Verifone Plugin')
135
- }
136
-
137
- /**
138
- * Not supported for this plugin. Use {@link Verifone#renderForm} instead.
139
- * @throws Not implemented error
140
- * @example
141
- * // Not currently supported for this plugin
142
- * @override
143
- * @see {@link Verifone#renderForm} Render a form
144
- */
145
- async displayObjects () {
146
- throw new Error('displayObjects() is not implemented for the Verifone Plugin')
147
- }
148
-
149
- /**
150
- * Render a form and get event data.
151
- *
152
- * @param {string|DeviceForm} form - ID of the form on the device or a DeviceForm
153
- * object with addtional configuration details.
154
- * @param {ControlProperty[]} [controlProps] - Array of {@link ControlProperty}
155
- * objects.
156
- * @param {string|object} [deviceOpt] - Clear the display of a either a
157
- * specific Device ID or a Device Object. The default is the first available
158
- * device.
159
- *
160
- * @override
161
- * @see {@link Verifone#renderForm} Render a form
162
- */
163
- async renderForm (form, controlProps, deviceOpt) {
164
- if (typeof form === 'string') {
165
- form = new DeviceForm(form)
166
- }
167
-
168
- const device = await this.setupDevice(deviceOpt)
169
- device.can('render_form')
170
-
171
- const body = JSON.stringify({
172
- form: form.id,
173
- wait_for_events: form.waitForEvents,
174
- timeout: form.timeout,
175
- control_properties: controlProps
176
- })
177
- const options = {
178
- method: 'POST',
179
- mode: 'cors',
180
- headers: {
181
- 'Content-Type': 'application/json'
182
- },
183
- body
184
- }
185
- const url = `${this.baseUrl}/plugin/${this.id}/device/${device.id}/form/${form.id}/render`
186
- const response = await fetch(url, options)
187
- await checkResponse(response)
188
- return await response.json()
189
- }
190
- }
191
-
192
- export default Verifone
1
+ import SignatureTablet from './SignatureTablet.js'
2
+ import { BASE_URL, checkResponse } from './Common.js'
3
+
4
+ /**
5
+ * ControlProperty
6
+ * @classdesc Form Control Properties
7
+ * @see {@link Verifone#renderForm} Render a form and update control properties
8
+ */
9
+ export class ControlProperty {
10
+ id
11
+ name
12
+ value
13
+
14
+ /**
15
+ * Instantiate a Control Property
16
+ * @constructor
17
+ * @param {number} id - ID of the Control on the Form
18
+ * @param {string} name - Name of the property to update
19
+ * @param {number|string|boolean} value - property value
20
+ * @example
21
+ * // A property to make a control hidden
22
+ * const prop = new ControlProperty(1, "visible", false)
23
+ *
24
+ * // A property to change the text of a control
25
+ * const prop = new ControlProperty(1, "caption", "Cancel Operation")
26
+ *
27
+ * // A property to change the background color of a control
28
+ * const prop = new ControlProperty(1, "bg_color", "#EB9534")
29
+ */
30
+ constructor (id, name, value) {
31
+ this.id = id
32
+ this.name = name
33
+ this.value = value
34
+ }
35
+
36
+ toJSON () {
37
+ return {
38
+ id: this.id,
39
+ name: this.name,
40
+ value: this.value
41
+ }
42
+ }
43
+ }
44
+
45
+ /**
46
+ * DeviceForm
47
+ * @classdesc Form to be rendered on a tablet device.
48
+ * @see {@link Verifone#renderForm} Render a form
49
+ */
50
+ export class DeviceForm {
51
+ id
52
+ waitForEvents
53
+ timeout
54
+
55
+ /**
56
+ * Instantiate a Form to be Rendered
57
+ * @constructor
58
+ * @param {string} id - ID of the Form
59
+ * @param {bool} [waitForEvents=false] - If `true` will wait for event data to
60
+ * be received on the form.
61
+ * @param {number} [timeout=15] - How long, in seconds, to wait for events from
62
+ * the form.
63
+ * @example
64
+ * // Form with no input data
65
+ * const form = new DeviceForm("FP_DISPLAY")
66
+ *
67
+ * // Form with buttons, wait 15 seconds for event data
68
+ * const form = new DeviceForm("FP_GEN_DISPLAY", true, 25)
69
+ */
70
+ constructor (id, waitForEvents = false, timeout = 15) {
71
+ this.id = id
72
+ this.waitForEvents = waitForEvents
73
+ this.timeout = timeout
74
+ }
75
+
76
+ toJSON () {
77
+ return {
78
+ id: this.id,
79
+ wait_for_events: this.waitForEvents,
80
+ timeout: this.timeout
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Verifone
87
+ * @classdesc Captures a signature and renders forms on Verifone devices.
88
+ * @extends SignatureTablet
89
+ * @see {@link SignatureTablet}
90
+ */
91
+ export class Verifone extends SignatureTablet {
92
+ /**
93
+ * Instantiate a Verifone Class
94
+ * @constructor
95
+ * @param {string} [baseURL] - Protocol, domain, and port for the service.
96
+ * @example
97
+ * const tablet = new Verifone()
98
+ *
99
+ */
100
+ constructor (baseUrl = BASE_URL) {
101
+ super('capture_signature_verifone', baseUrl)
102
+ }
103
+
104
+ /**
105
+ * Not currently supported for this plugin.
106
+ * @throws Not implemented error
107
+ * @example
108
+ * // Not currently supported for this plugin
109
+ * @override
110
+ */
111
+ async streamUrl () {
112
+ throw new Error('streamUrl() is not implemented for the Verifone Plugin')
113
+ }
114
+
115
+ /**
116
+ * Not currently supported for this plugin.
117
+ * @throws Not implemented error
118
+ * @example
119
+ * // Not currently supported for this plugin
120
+ * @override
121
+ */
122
+ async getMostRecentFrame () {
123
+ throw new Error('getMostRecentFrame() is not implemented for the Verifone Plugin')
124
+ }
125
+
126
+ /**
127
+ * Not currently supported for this plugin.
128
+ * @throws Not implemented error
129
+ * @example
130
+ * // Not currently supported for this plugin
131
+ * @override
132
+ */
133
+ async stopFeed () {
134
+ throw new Error('stopFeed() is not implemented for the Verifone Plugin')
135
+ }
136
+
137
+ /**
138
+ * Render an array of form controls.
139
+ *
140
+ * @description If any objects are Button types, the method will wait for one
141
+ * to be clicked.
142
+ *
143
+ * @param {object[]} objects An array of objects to display.
144
+ *
145
+ * @param {object} [formOpt] - Form configuration options.
146
+ * @param {string} [formOpt.background='#ffffff'] - Background color of form (hex or RGB.)
147
+ * @param {number} [formOpt.timeout=45] - Form timeout, in seconds.
148
+ *
149
+ * @param {string|object} [deviceOpt] - Display the objects on either a
150
+ * specific Device ID or a Device Object. The default is the first available
151
+ * device.
152
+ *
153
+ * @async
154
+ * @method
155
+ * @returns {string?} ID of the clicked object if any
156
+ * @example
157
+ * const result = await tablet.displayObjects([
158
+ * new Button("OK", 20, 200),
159
+ * new Button("Cancel", 80, 200)
160
+ * ], { background: 'rgb(10,100,10)'})
161
+ *
162
+ * console.log(result)
163
+ */
164
+ async displayObjects (objects, formOpt = {}, deviceOpt) {
165
+ const device = await this.setupDevice(deviceOpt)
166
+ return device.displayObjects(objects, formOpt)
167
+ }
168
+
169
+ /**
170
+ * Render a form and get event data.
171
+ *
172
+ * @param {string|DeviceForm} form - ID of the form on the device or a DeviceForm
173
+ * object with addtional configuration details.
174
+ * @param {ControlProperty[]} [controlProps] - Array of {@link ControlProperty}
175
+ * objects.
176
+ * @param {string|object} [deviceOpt] - Clear the display of a either a
177
+ * specific Device ID or a Device Object. The default is the first available
178
+ * device.
179
+ *
180
+ * @override
181
+ * @see {@link Verifone#renderForm} Render a form
182
+ */
183
+ async renderForm (form, controlProps, deviceOpt) {
184
+ if (typeof form === 'string') {
185
+ form = new DeviceForm(form)
186
+ }
187
+
188
+ const device = await this.setupDevice(deviceOpt)
189
+ device.can('render_form')
190
+
191
+ const body = JSON.stringify({
192
+ form: form.id,
193
+ wait_for_events: form.waitForEvents,
194
+ timeout: form.timeout,
195
+ control_properties: controlProps
196
+ })
197
+ const options = {
198
+ method: 'POST',
199
+ mode: 'cors',
200
+ headers: {
201
+ 'Content-Type': 'application/json'
202
+ },
203
+ body
204
+ }
205
+ const url = `${this.baseUrl}/plugin/${this.id}/device/${device.id}/form/${form.id}/render`
206
+ const response = await fetch(url, options)
207
+ await checkResponse(response)
208
+ return await response.json()
209
+ }
210
+
211
+ /**
212
+ * Read magstripe from a card reader
213
+ *
214
+ * @param {object} [readOpts] - Additional options for reading magstripe.
215
+ * @param {number} [readOpts.timeout=30] - Magstripe read timeout, in seconds.
216
+ *
217
+ * @param {string|object} [deviceOpt] - Read magstrip using a specific Device
218
+ * ID or a Device Object. The default is the first available device.
219
+ *
220
+ */
221
+ async readMagstripe (readOpts = { timeout: 30 }, deviceOpt) {
222
+ const device = await this.setupDevice(deviceOpt)
223
+ device.can('read_magstripe')
224
+
225
+ const options = {
226
+ method: 'GET',
227
+ mode: 'cors',
228
+ headers: {
229
+ 'Content-Type': 'application/json'
230
+ }
231
+ }
232
+ const url = `${this.baseUrl}/plugin/${this.id}/device/${device.id}/magstripe?timeout=${readOpts.timeout}`
233
+ const response = await fetch(url, options)
234
+ await checkResponse(response)
235
+ return await response.json()
236
+ }
237
+ }
238
+
239
+ export default Verifone