@capturebridge/sdk 0.10.1 → 0.11.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/CHANGELOG.md +8 -0
- package/README.md +2 -2
- package/Verifone.js +128 -4
- package/Version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.11.0] - 2024-06-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added `DeviceForms` and `ControlProperty` classes for configuring forms for
|
|
13
|
+
`Verifone`.
|
|
14
|
+
- Added `Verifone.renderForm()`
|
|
15
|
+
|
|
8
16
|
## [0.10.0] - 2024-06-17
|
|
9
17
|
|
|
10
18
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Capture Bridge JavaScript SDK
|
|
1
|
+
# Capture Bridge JavaScript SDK
|
|
2
2
|
|
|
3
|
-
See
|
|
3
|
+
See `CHANGELOG.md` for new features and breaking changes.
|
package/Verifone.js
CHANGED
|
@@ -1,13 +1,94 @@
|
|
|
1
1
|
import SignatureTablet from './SignatureTablet.js'
|
|
2
|
-
import { BASE_URL } from './Common.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
|
+
}
|
|
3
84
|
|
|
4
85
|
/**
|
|
5
86
|
* Verifone
|
|
6
|
-
* @classdesc Captures a signature on Verifone
|
|
87
|
+
* @classdesc Captures a signature and renders forms on Verifone devices.
|
|
7
88
|
* @extends SignatureTablet
|
|
8
89
|
* @see {@link SignatureTablet}
|
|
9
90
|
*/
|
|
10
|
-
class Verifone extends SignatureTablet {
|
|
91
|
+
export class Verifone extends SignatureTablet {
|
|
11
92
|
/**
|
|
12
93
|
* Instantiate a Verifone Class
|
|
13
94
|
* @constructor
|
|
@@ -54,15 +135,58 @@ class Verifone extends SignatureTablet {
|
|
|
54
135
|
}
|
|
55
136
|
|
|
56
137
|
/**
|
|
57
|
-
* Not
|
|
138
|
+
* Not supported for this plugin. Use {@link Verifone#renderForm} instead.
|
|
58
139
|
* @throws Not implemented error
|
|
59
140
|
* @example
|
|
60
141
|
* // Not currently supported for this plugin
|
|
61
142
|
* @override
|
|
143
|
+
* @see {@link Verifone#renderForm} Render a form
|
|
62
144
|
*/
|
|
63
145
|
async displayObjects () {
|
|
64
146
|
throw new Error('displayObjects() is not implemented for the Verifone Plugin')
|
|
65
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
|
+
}
|
|
66
190
|
}
|
|
67
191
|
|
|
68
192
|
export default Verifone
|
package/Version.js
CHANGED