@capacitor-community/stripe-terminal 6.0.2 → 6.2.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/CapacitorCommunityStripeTerminal.podspec +1 -1
- package/README.md +767 -28
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java +372 -51
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminalPlugin.java +61 -5
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/TerminalEvent.kt +14 -0
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/helper/TerminalMappers.java +96 -0
- package/dist/docs.json +1389 -111
- package/dist/esm/definitions.d.ts +263 -11
- package/dist/esm/definitions.js +1 -8
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/events.enum.d.ts +15 -1
- package/dist/esm/events.enum.js +14 -0
- package/dist/esm/events.enum.js.map +1 -1
- package/dist/esm/stripe-types/proto.d.ts +501 -0
- package/dist/esm/stripe-types/proto.js +2 -0
- package/dist/esm/stripe-types/proto.js.map +1 -0
- package/dist/esm/stripe.enum.d.ts +154 -0
- package/dist/esm/stripe.enum.js +170 -0
- package/dist/esm/stripe.enum.js.map +1 -0
- package/dist/esm/terminalMappers.d.ts +23 -0
- package/dist/esm/terminalMappers.js +119 -0
- package/dist/esm/terminalMappers.js.map +1 -0
- package/dist/esm/web.d.ts +25 -2
- package/dist/esm/web.js +137 -13
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +428 -13
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +429 -15
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/StripeTerminal.swift +345 -61
- package/ios/Plugin/StripeTerminalPlugin.m +7 -0
- package/ios/Plugin/StripeTerminalPlugin.swift +29 -4
- package/ios/Plugin/TerminalEvents.swift +14 -0
- package/ios/Plugin/TerminalMappers.swift +269 -0
- package/package.json +4 -1
|
@@ -2,20 +2,24 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import StripeTerminal
|
|
4
4
|
|
|
5
|
-
public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDelegate, BluetoothReaderDelegate {
|
|
5
|
+
public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDelegate, BluetoothReaderDelegate, TerminalDelegate, ReconnectionDelegate {
|
|
6
6
|
|
|
7
7
|
weak var plugin: StripeTerminalPlugin?
|
|
8
8
|
private let apiClient = APIClient()
|
|
9
|
+
|
|
9
10
|
var discoverCancelable: Cancelable?
|
|
11
|
+
var collectCancelable: Cancelable?
|
|
12
|
+
var installUpdateCancelable: Cancelable?
|
|
13
|
+
var cancelReaderConnectionCancellable: Cancelable?
|
|
14
|
+
|
|
10
15
|
var discoverCall: CAPPluginCall?
|
|
11
16
|
var locationId: String?
|
|
12
17
|
var isTest: Bool?
|
|
13
|
-
var collectCancelable: Cancelable?
|
|
14
18
|
var type: DiscoveryMethod?
|
|
15
19
|
var isInitialize: Bool = false
|
|
16
20
|
var paymentIntent: PaymentIntent?
|
|
17
21
|
|
|
18
|
-
var
|
|
22
|
+
var discoveredReadersList: [Reader]?
|
|
19
23
|
|
|
20
24
|
@objc public func initialize(_ call: CAPPluginCall) {
|
|
21
25
|
self.isTest = call.getBool("isTest", true)
|
|
@@ -61,38 +65,21 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
61
65
|
call.reject(error.localizedDescription)
|
|
62
66
|
self.discoverCall = nil
|
|
63
67
|
} else {
|
|
68
|
+
// This call is passed to discoverCall. So not resolve.
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
func cancelDiscoverReaders(_ call: CAPPluginCall) {
|
|
69
|
-
|
|
70
|
-
if let cancelable = self.discoverCancelable {
|
|
71
|
-
cancelable.cancel { error in
|
|
72
|
-
if let error = error {
|
|
73
|
-
call.reject(error.localizedDescription)
|
|
74
|
-
} else {
|
|
75
|
-
self.collectCancelable = nil
|
|
76
|
-
call.resolve()
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
call.resolve()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
73
|
public func terminal(_ terminal: Terminal, didUpdateDiscoveredReaders readers: [Reader]) {
|
|
86
74
|
var readersJSObject: JSArray = []
|
|
87
75
|
var i = 0
|
|
88
76
|
for reader in readers {
|
|
89
77
|
readersJSObject.append([
|
|
90
|
-
"index": i
|
|
91
|
-
|
|
92
|
-
])
|
|
78
|
+
"index": i
|
|
79
|
+
].merging(self.convertReaderInterface(reader: reader)) { (_, new) in new })
|
|
93
80
|
i += 1
|
|
94
81
|
}
|
|
95
|
-
self.
|
|
82
|
+
self.discoveredReadersList = readers
|
|
96
83
|
|
|
97
84
|
self.plugin?.notifyListeners(TerminalEvents.DiscoveredReaders.rawValue, data: ["readers": readersJSObject])
|
|
98
85
|
self.discoverCall?.resolve([
|
|
@@ -113,9 +100,7 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
113
100
|
|
|
114
101
|
public func getConnectedReader(_ call: CAPPluginCall) {
|
|
115
102
|
if let reader = Terminal.shared.connectedReader {
|
|
116
|
-
call.resolve(["reader":
|
|
117
|
-
"serialNumber": reader.serialNumber
|
|
118
|
-
]])
|
|
103
|
+
call.resolve(["reader": self.convertReaderInterface(reader: reader)])
|
|
119
104
|
} else {
|
|
120
105
|
call.resolve(["reader": nil])
|
|
121
106
|
}
|
|
@@ -140,11 +125,25 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
140
125
|
}
|
|
141
126
|
|
|
142
127
|
private func connectLocalMobileReader(_ call: CAPPluginCall) {
|
|
143
|
-
let
|
|
128
|
+
let autoReconnectOnUnexpectedDisconnect = call.getBool("autoReconnectOnUnexpectedDisconnect", false)
|
|
129
|
+
let merchantDisplayName: String? = call.getString("merchantDisplayName")
|
|
130
|
+
let onBehalfOf: String? = call.getString("onBehalfOf")
|
|
144
131
|
let reader: JSObject = call.getObject("reader")!
|
|
145
|
-
let
|
|
132
|
+
let serialNumber: String = reader["serialNumber"] as! String
|
|
146
133
|
|
|
147
|
-
|
|
134
|
+
let connectionConfig = try! LocalMobileConnectionConfigurationBuilder.init(locationId: self.locationId!)
|
|
135
|
+
.setMerchantDisplayName(merchantDisplayName ?? nil)
|
|
136
|
+
.setOnBehalfOf(onBehalfOf ?? nil)
|
|
137
|
+
.setAutoReconnectOnUnexpectedDisconnect(autoReconnectOnUnexpectedDisconnect)
|
|
138
|
+
.setAutoReconnectionDelegate(autoReconnectOnUnexpectedDisconnect ? self : nil)
|
|
139
|
+
.build()
|
|
140
|
+
|
|
141
|
+
guard let foundReader = self.discoveredReadersList?.first(where: { $0.serialNumber == serialNumber }) else {
|
|
142
|
+
call.reject("reader is not match from descovered readers.")
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
Terminal.shared.connectLocalMobileReader(foundReader, delegate: self, connectionConfig: connectionConfig) { reader, error in
|
|
148
147
|
if let reader = reader {
|
|
149
148
|
self.plugin?.notifyListeners(TerminalEvents.ConnectedReader.rawValue, data: [:])
|
|
150
149
|
call.resolve()
|
|
@@ -155,13 +154,19 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
private func connectInternetReader(_ call: CAPPluginCall) {
|
|
157
|
+
let reader: JSObject = call.getObject("reader")!
|
|
158
|
+
let serialNumber: String = reader["serialNumber"] as! String
|
|
159
|
+
|
|
160
|
+
guard let foundReader = self.discoveredReadersList?.first(where: { $0.serialNumber == serialNumber }) else {
|
|
161
|
+
call.reject("reader is not match from descovered readers.")
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
|
|
158
165
|
let config = try! InternetConnectionConfigurationBuilder()
|
|
159
166
|
.setFailIfInUse(true)
|
|
160
167
|
.build()
|
|
161
|
-
let reader: JSObject = call.getObject("reader")!
|
|
162
|
-
let index: Int = reader["index"] as! Int
|
|
163
168
|
|
|
164
|
-
Terminal.shared.connectInternetReader(
|
|
169
|
+
Terminal.shared.connectInternetReader(foundReader, connectionConfig: config) { reader, error in
|
|
165
170
|
if let reader = reader {
|
|
166
171
|
self.plugin?.notifyListeners(TerminalEvents.ConnectedReader.rawValue, data: [:])
|
|
167
172
|
call.resolve()
|
|
@@ -172,11 +177,24 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
private func connectBluetoothReader(_ call: CAPPluginCall) {
|
|
175
|
-
let config = try! BluetoothConnectionConfigurationBuilder(locationId: self.locationId!).build()
|
|
176
180
|
let reader: JSObject = call.getObject("reader")!
|
|
177
|
-
let
|
|
181
|
+
let serialNumber: String = reader["serialNumber"] as! String
|
|
182
|
+
|
|
183
|
+
guard let foundReader = self.discoveredReadersList?.first(where: { $0.serialNumber == serialNumber }) else {
|
|
184
|
+
call.reject("reader is not match from descovered readers.")
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let autoReconnectOnUnexpectedDisconnect = call.getBool("autoReconnectOnUnexpectedDisconnect", false)
|
|
189
|
+
let merchantDisplayName: String? = call.getString("merchantDisplayName")
|
|
190
|
+
let onBehalfOf: String? = call.getString("onBehalfOf")
|
|
178
191
|
|
|
179
|
-
|
|
192
|
+
let config = try! BluetoothConnectionConfigurationBuilder(locationId: self.locationId!)
|
|
193
|
+
.setAutoReconnectOnUnexpectedDisconnect(autoReconnectOnUnexpectedDisconnect)
|
|
194
|
+
.setAutoReconnectionDelegate(autoReconnectOnUnexpectedDisconnect ? self : nil)
|
|
195
|
+
.build()
|
|
196
|
+
|
|
197
|
+
Terminal.shared.connectBluetoothReader(foundReader, delegate: self, connectionConfig: config) { reader, error in
|
|
180
198
|
if let reader = reader {
|
|
181
199
|
self.plugin?.notifyListeners(TerminalEvents.ConnectedReader.rawValue, data: [:])
|
|
182
200
|
call.resolve()
|
|
@@ -190,6 +208,7 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
190
208
|
Terminal.shared.retrievePaymentIntent(clientSecret: call.getString("paymentIntent")!) { retrieveResult, retrieveError in
|
|
191
209
|
if let error = retrieveError {
|
|
192
210
|
print("retrievePaymentIntent failed: \(error)")
|
|
211
|
+
call.reject(error.localizedDescription)
|
|
193
212
|
} else if let paymentIntent = retrieveResult {
|
|
194
213
|
self.collectCancelable = Terminal.shared.collectPaymentMethod(paymentIntent) { collectResult, collectError in
|
|
195
214
|
if let error = collectError {
|
|
@@ -205,14 +224,132 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
205
224
|
}
|
|
206
225
|
}
|
|
207
226
|
|
|
227
|
+
public func confirmPaymentIntent(_ call: CAPPluginCall) {
|
|
228
|
+
if let paymentIntent = self.paymentIntent {
|
|
229
|
+
Terminal.shared.confirmPaymentIntent(paymentIntent) { confirmResult, confirmError in
|
|
230
|
+
if let error = confirmError {
|
|
231
|
+
print("confirmPaymentIntent failed: \(error)")
|
|
232
|
+
self.plugin?.notifyListeners(TerminalEvents.Failed.rawValue, data: [:])
|
|
233
|
+
call.reject(error.localizedDescription)
|
|
234
|
+
} else if let confirmedIntent = confirmResult {
|
|
235
|
+
print("PaymentIntent confirmed: \(confirmedIntent)")
|
|
236
|
+
self.plugin?.notifyListeners(TerminalEvents.ConfirmedPaymentIntent.rawValue, data: [:])
|
|
237
|
+
call.resolve()
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
call.reject("PaymentIntent not found for confirmPaymentIntent. Use collect method first and try again.")
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public func setSimulatorConfiguration(_ call: CAPPluginCall) {
|
|
246
|
+
// { update?: SimulateReaderUpdate; simulatedCard?: SimulatedCardType; simulatedTipAmount?: number; }
|
|
247
|
+
Terminal.shared.simulatorConfiguration.availableReaderUpdate = TerminalMappers.mapToSimulateReaderUpdate(call.getString("update", "UPDATE_AVAILABLE"))
|
|
248
|
+
Terminal.shared.simulatorConfiguration.simulatedCard = SimulatedCard(type: SimulatedCardType(rawValue: TerminalMappers.mapToCardType(type: call.getString("simulatedCard", "VISA")))!)
|
|
249
|
+
if let tipAmount = call.getInt("simulatedTipAmount") {
|
|
250
|
+
Terminal.shared.simulatorConfiguration.simulatedTipAmount = (tipAmount) as NSNumber
|
|
251
|
+
}
|
|
252
|
+
call.resolve([:])
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public func installAvailableUpdate(_ call: CAPPluginCall) {
|
|
256
|
+
Terminal.shared.installAvailableUpdate()
|
|
257
|
+
call.resolve([:])
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public func setReaderDisplay(_ call: CAPPluginCall) {
|
|
261
|
+
guard let currency = call.getString("currency") else {
|
|
262
|
+
call.reject("You must provide a currency value")
|
|
263
|
+
return
|
|
264
|
+
}
|
|
265
|
+
guard let tax = call.getInt("tax") as? NSNumber else {
|
|
266
|
+
call.reject("You must provide a tax value")
|
|
267
|
+
return
|
|
268
|
+
}
|
|
269
|
+
guard let total = call.getInt("total") as? NSNumber else {
|
|
270
|
+
call.reject("You must provide a total value")
|
|
271
|
+
return
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let cartBuilder = CartBuilder(currency: currency)
|
|
275
|
+
.setTax(Int(truncating: tax))
|
|
276
|
+
.setTotal(Int(truncating: total))
|
|
277
|
+
|
|
278
|
+
let cartLineItems = TerminalMappers.mapToCartLineItems(call.getArray("lineItems") ?? JSArray())
|
|
279
|
+
|
|
280
|
+
cartBuilder.setLineItems(cartLineItems)
|
|
281
|
+
|
|
282
|
+
let cart: Cart
|
|
283
|
+
do {
|
|
284
|
+
cart = try cartBuilder.build()
|
|
285
|
+
} catch {
|
|
286
|
+
call.reject(error.localizedDescription)
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
Terminal.shared.setReaderDisplay(cart) { error in
|
|
291
|
+
if let error = error as NSError? {
|
|
292
|
+
call.reject(error.localizedDescription)
|
|
293
|
+
} else {
|
|
294
|
+
call.resolve([:])
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public func clearReaderDisplay(_ call: CAPPluginCall) {
|
|
301
|
+
Terminal.shared.clearReaderDisplay { error in
|
|
302
|
+
if let error = error as NSError? {
|
|
303
|
+
call.reject(error.localizedDescription)
|
|
304
|
+
} else {
|
|
305
|
+
call.resolve([:])
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public func rebootReader(_ call: CAPPluginCall) {
|
|
311
|
+
Terminal.shared.rebootReader { error in
|
|
312
|
+
if let error = error as NSError? {
|
|
313
|
+
call.reject(error.localizedDescription)
|
|
314
|
+
} else {
|
|
315
|
+
self.paymentIntent = nil
|
|
316
|
+
call.resolve([:])
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Cancelable
|
|
323
|
+
*/
|
|
324
|
+
public func cancelInstallUpdate(_ call: CAPPluginCall) {
|
|
325
|
+
if let cancelable = self.installUpdateCancelable {
|
|
326
|
+
if cancelable.completed {
|
|
327
|
+
call.resolve()
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
cancelable.cancel { error in
|
|
331
|
+
if let error = error as NSError? {
|
|
332
|
+
call.reject(error.localizedDescription)
|
|
333
|
+
} else {
|
|
334
|
+
call.resolve([:])
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return
|
|
338
|
+
}
|
|
339
|
+
call.resolve([:])
|
|
340
|
+
}
|
|
341
|
+
|
|
208
342
|
public func cancelCollectPaymentMethod(_ call: CAPPluginCall) {
|
|
209
343
|
if let cancelable = self.collectCancelable {
|
|
344
|
+
if cancelable.completed {
|
|
345
|
+
call.resolve()
|
|
346
|
+
return
|
|
347
|
+
}
|
|
210
348
|
cancelable.cancel { error in
|
|
211
349
|
if let error = error {
|
|
212
350
|
call.reject(error.localizedDescription)
|
|
213
351
|
} else {
|
|
214
352
|
self.plugin?.notifyListeners(TerminalEvents.Canceled.rawValue, data: [:])
|
|
215
|
-
self.collectCancelable = nil
|
|
216
353
|
self.paymentIntent = nil
|
|
217
354
|
call.resolve()
|
|
218
355
|
}
|
|
@@ -222,71 +359,208 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
|
|
|
222
359
|
call.resolve()
|
|
223
360
|
}
|
|
224
361
|
|
|
225
|
-
|
|
226
|
-
if let
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
362
|
+
func cancelDiscoverReaders(_ call: CAPPluginCall) {
|
|
363
|
+
if let cancelable = self.discoverCancelable {
|
|
364
|
+
if cancelable.completed {
|
|
365
|
+
call.resolve()
|
|
366
|
+
return
|
|
367
|
+
}
|
|
368
|
+
cancelable.cancel { error in
|
|
369
|
+
if let error = error {
|
|
231
370
|
call.reject(error.localizedDescription)
|
|
232
|
-
} else
|
|
233
|
-
print("PaymentIntent confirmed: \(confirmedIntent)")
|
|
234
|
-
self.plugin?.notifyListeners(TerminalEvents.ConfirmedPaymentIntent.rawValue, data: [:])
|
|
371
|
+
} else {
|
|
235
372
|
call.resolve()
|
|
236
373
|
}
|
|
237
374
|
}
|
|
238
|
-
|
|
239
|
-
call.reject("PaymentIntent not found for confirmPaymentIntent. Use collect method first and try again.")
|
|
375
|
+
return
|
|
240
376
|
}
|
|
377
|
+
|
|
378
|
+
call.resolve()
|
|
241
379
|
}
|
|
242
380
|
|
|
243
|
-
|
|
381
|
+
public func cancelReaderReconnection(_ call: CAPPluginCall) {
|
|
382
|
+
if let cancelable = self.cancelReaderConnectionCancellable {
|
|
383
|
+
if cancelable.completed {
|
|
384
|
+
call.resolve()
|
|
385
|
+
return
|
|
386
|
+
}
|
|
387
|
+
cancelable.cancel { error in
|
|
388
|
+
if let error = error as NSError? {
|
|
389
|
+
call.reject(error.localizedDescription)
|
|
390
|
+
} else {
|
|
391
|
+
call.resolve([:])
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
call.resolve()
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/*
|
|
401
|
+
* Terminal
|
|
402
|
+
*/
|
|
403
|
+
public func terminal(_ terminal: Terminal, didChangePaymentStatus status: PaymentStatus) {
|
|
404
|
+
self.plugin?.notifyListeners(TerminalEvents.PaymentStatusChange.rawValue, data: ["status": TerminalMappers.mapFromPaymentStatus(status)])
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
public func terminal(_ terminal: Terminal, didChangeConnectionStatus status: ConnectionStatus) {
|
|
408
|
+
self.plugin?.notifyListeners(TerminalEvents.ConnectionStatusChange.rawValue, data: ["status": TerminalMappers.mapFromConnectionStatus(status)])
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public func terminal(_ terminal: Terminal, didReportUnexpectedReaderDisconnect reader: Reader) {
|
|
412
|
+
self.plugin?.notifyListeners(TerminalEvents.UnexpectedReaderDisconnect.rawValue, data: ["reader": self.convertReaderInterface(reader: reader)])
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/*
|
|
416
|
+
* localMobile
|
|
417
|
+
*/
|
|
244
418
|
|
|
245
419
|
public func localMobileReader(_ reader: Reader, didStartInstallingUpdate update: ReaderSoftwareUpdate, cancelable: Cancelable?) {
|
|
246
|
-
|
|
420
|
+
self.installUpdateCancelable = cancelable
|
|
421
|
+
self.plugin?.notifyListeners(TerminalEvents.StartInstallingUpdate.rawValue, data: [
|
|
422
|
+
"update": self.convertReaderSoftwareUpdate(update: update)
|
|
423
|
+
])
|
|
247
424
|
}
|
|
248
425
|
|
|
249
426
|
public func localMobileReader(_ reader: Reader, didReportReaderSoftwareUpdateProgress progress: Float) {
|
|
250
|
-
|
|
427
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderSoftwareUpdateProgress.rawValue, data: ["progress": progress])
|
|
251
428
|
}
|
|
252
429
|
|
|
253
430
|
public func localMobileReader(_ reader: Reader, didFinishInstallingUpdate update: ReaderSoftwareUpdate?, error: Error?) {
|
|
254
|
-
|
|
431
|
+
if (error) != nil {
|
|
432
|
+
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
|
|
433
|
+
"error": error!.localizedDescription
|
|
434
|
+
])
|
|
435
|
+
return
|
|
436
|
+
}
|
|
437
|
+
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
|
|
438
|
+
"update": self.convertReaderSoftwareUpdate(update: update!)
|
|
439
|
+
])
|
|
255
440
|
}
|
|
256
441
|
|
|
257
442
|
public func localMobileReader(_ reader: Reader, didRequestReaderInput inputOptions: ReaderInputOptions = []) {
|
|
258
|
-
|
|
443
|
+
self.plugin?.notifyListeners(TerminalEvents.RequestReaderInput.rawValue, data: ["options": TerminalMappers.mapFromReaderInputOptions(inputOptions), "message": inputOptions.rawValue])
|
|
259
444
|
}
|
|
260
445
|
|
|
261
446
|
public func localMobileReader(_ reader: Reader, didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage) {
|
|
262
|
-
|
|
447
|
+
let result = TerminalMappers.mapFromReaderDisplayMessage(displayMessage)
|
|
448
|
+
|
|
449
|
+
self.plugin?.notifyListeners(TerminalEvents.RequestDisplayMessage.rawValue, data: [
|
|
450
|
+
"messageType": result,
|
|
451
|
+
"message": displayMessage.rawValue
|
|
452
|
+
])
|
|
263
453
|
}
|
|
264
454
|
|
|
265
|
-
|
|
455
|
+
/*
|
|
456
|
+
* bluetooth
|
|
457
|
+
*/
|
|
266
458
|
|
|
267
459
|
public func reader(_: Reader, didReportAvailableUpdate update: ReaderSoftwareUpdate) {
|
|
268
|
-
|
|
460
|
+
self.plugin?.notifyListeners(TerminalEvents.ReportAvailableUpdate.rawValue, data: [
|
|
461
|
+
"update": self.convertReaderSoftwareUpdate(update: update)
|
|
462
|
+
])
|
|
269
463
|
}
|
|
270
464
|
|
|
271
465
|
public func reader(_: Reader, didStartInstallingUpdate update: ReaderSoftwareUpdate, cancelable: Cancelable?) {
|
|
272
|
-
|
|
466
|
+
self.installUpdateCancelable = cancelable
|
|
467
|
+
self.plugin?.notifyListeners(TerminalEvents.StartInstallingUpdate.rawValue, data: [
|
|
468
|
+
"update": self.convertReaderSoftwareUpdate(update: update)
|
|
469
|
+
])
|
|
273
470
|
}
|
|
274
471
|
|
|
275
472
|
public func reader(_: Reader, didReportReaderSoftwareUpdateProgress progress: Float) {
|
|
276
|
-
|
|
473
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderSoftwareUpdateProgress.rawValue, data: ["progress": progress])
|
|
277
474
|
}
|
|
278
475
|
|
|
279
476
|
public func reader(_: Reader, didFinishInstallingUpdate update: ReaderSoftwareUpdate?, error: Error?) {
|
|
280
|
-
|
|
477
|
+
if (error) != nil {
|
|
478
|
+
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
|
|
479
|
+
"error": error!.localizedDescription
|
|
480
|
+
])
|
|
481
|
+
return
|
|
482
|
+
}
|
|
483
|
+
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
|
|
484
|
+
"update": self.convertReaderSoftwareUpdate(update: update!)
|
|
485
|
+
])
|
|
281
486
|
}
|
|
282
487
|
|
|
283
488
|
public func reader(_: Reader, didRequestReaderInput inputOptions: ReaderInputOptions = []) {
|
|
284
|
-
|
|
489
|
+
self.plugin?.notifyListeners(TerminalEvents.RequestReaderInput.rawValue, data: ["options": TerminalMappers.mapFromReaderInputOptions(inputOptions), "message": inputOptions.rawValue])
|
|
285
490
|
}
|
|
286
491
|
|
|
287
492
|
public func reader(_: Reader, didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage) {
|
|
288
|
-
|
|
493
|
+
let result = TerminalMappers.mapFromReaderDisplayMessage(displayMessage)
|
|
494
|
+
|
|
495
|
+
self.plugin?.notifyListeners(TerminalEvents.RequestDisplayMessage.rawValue, data: [
|
|
496
|
+
"messageType": result,
|
|
497
|
+
"message": displayMessage.rawValue
|
|
498
|
+
])
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public func reader(_ reader: Reader, didReportBatteryLevel batteryLevel: Float, status: BatteryStatus, isCharging: Bool) {
|
|
502
|
+
self.plugin?.notifyListeners(TerminalEvents.BatteryLevel.rawValue, data: [
|
|
503
|
+
"level": batteryLevel,
|
|
504
|
+
"charging": isCharging,
|
|
505
|
+
"status": TerminalMappers.mapFromBatteryStatus(status)
|
|
506
|
+
])
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
public func reader(_ reader: Reader, didReportReaderEvent event: ReaderEvent, info: [AnyHashable: Any]?) {
|
|
510
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderEvent.rawValue, data: [
|
|
511
|
+
"event": TerminalMappers.mapFromReaderEvent(event)
|
|
512
|
+
])
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
public func reader(_ reader: Reader, didDisconnect reason: DisconnectReason) {
|
|
516
|
+
self.plugin?.notifyListeners(TerminalEvents.DisconnectedReader.rawValue, data: [
|
|
517
|
+
"reason": TerminalMappers.mapFromReaderDisconnectReason(reason)
|
|
518
|
+
])
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/*
|
|
522
|
+
* Reconnection
|
|
523
|
+
*/
|
|
524
|
+
public func reader(_ reader: Reader, didStartReconnect cancelable: Cancelable, disconnectReason: DisconnectReason) {
|
|
525
|
+
self.cancelReaderConnectionCancellable = cancelable
|
|
526
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderReconnectStarted.rawValue, data: ["reader": self.convertReaderInterface(reader: reader), "reason": disconnectReason.rawValue])
|
|
289
527
|
}
|
|
528
|
+
|
|
529
|
+
public func readerDidSucceedReconnect(_ reader: Reader) {
|
|
530
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderReconnectSucceeded.rawValue, data: ["reader": self.convertReaderInterface(reader: reader)])
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
public func readerDidFailReconnect(_ reader: Reader) {
|
|
534
|
+
self.plugin?.notifyListeners(TerminalEvents.ReaderReconnectFailed.rawValue, data: ["reader": self.convertReaderInterface(reader: reader)])
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/*
|
|
538
|
+
* Private
|
|
539
|
+
*/
|
|
540
|
+
private func convertReaderInterface(reader: Reader) -> JSObject {
|
|
541
|
+
return [
|
|
542
|
+
"label": reader.label ?? NSNull(),
|
|
543
|
+
"batteryLevel": (reader.batteryLevel ?? 0).intValue,
|
|
544
|
+
"batteryStatus": TerminalMappers.mapFromBatteryStatus(reader.batteryStatus),
|
|
545
|
+
"simulated": reader.simulated,
|
|
546
|
+
"serialNumber": reader.serialNumber,
|
|
547
|
+
"isCharging": (reader.isCharging ?? 0).intValue,
|
|
548
|
+
"id": reader.stripeId ?? NSNull(),
|
|
549
|
+
"availableUpdate": TerminalMappers.mapFromReaderSoftwareUpdate(reader.availableUpdate),
|
|
550
|
+
"locationId": reader.locationId ?? NSNull(),
|
|
551
|
+
"ipAddress": reader.ipAddress ?? NSNull(),
|
|
552
|
+
"status": TerminalMappers.mapFromReaderNetworkStatus(reader.status),
|
|
553
|
+
"location": TerminalMappers.mapFromLocation(reader.location),
|
|
554
|
+
"locationStatus": TerminalMappers.mapFromLocationStatus(reader.locationStatus),
|
|
555
|
+
"deviceType": TerminalMappers.mapFromDeviceType(reader.deviceType),
|
|
556
|
+
"deviceSoftwareVersion": reader.deviceSoftwareVersion ?? NSNull()
|
|
557
|
+
]
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
private func convertReaderSoftwareUpdate(update: ReaderSoftwareUpdate) -> JSObject {
|
|
561
|
+
return TerminalMappers.mapFromReaderSoftwareUpdate(update)
|
|
562
|
+
}
|
|
563
|
+
|
|
290
564
|
}
|
|
291
565
|
|
|
292
566
|
class APIClient: ConnectionTokenProvider {
|
|
@@ -358,3 +632,13 @@ class APIClient: ConnectionTokenProvider {
|
|
|
358
632
|
}
|
|
359
633
|
}
|
|
360
634
|
}
|
|
635
|
+
|
|
636
|
+
extension UInt {
|
|
637
|
+
init(bitComponents: [UInt]) {
|
|
638
|
+
self = bitComponents.reduce(0, +)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
func bitComponents() -> [UInt] {
|
|
642
|
+
return (0 ..< 8*MemoryLayout<UInt>.size).map({ 1 << $0 }).filter({ self & $0 != 0 })
|
|
643
|
+
}
|
|
644
|
+
}
|
|
@@ -14,4 +14,11 @@ CAP_PLUGIN(StripeTerminalPlugin, "StripeTerminal",
|
|
|
14
14
|
CAP_PLUGIN_METHOD(collectPaymentMethod, CAPPluginReturnPromise);
|
|
15
15
|
CAP_PLUGIN_METHOD(cancelCollectPaymentMethod, CAPPluginReturnPromise);
|
|
16
16
|
CAP_PLUGIN_METHOD(confirmPaymentIntent, CAPPluginReturnPromise);
|
|
17
|
+
CAP_PLUGIN_METHOD(setSimulatorConfiguration, CAPPluginReturnPromise);
|
|
18
|
+
CAP_PLUGIN_METHOD(installAvailableUpdate, CAPPluginReturnPromise);
|
|
19
|
+
CAP_PLUGIN_METHOD(cancelInstallUpdate, CAPPluginReturnPromise);
|
|
20
|
+
CAP_PLUGIN_METHOD(setReaderDisplay, CAPPluginReturnPromise);
|
|
21
|
+
CAP_PLUGIN_METHOD(clearReaderDisplay, CAPPluginReturnPromise);
|
|
22
|
+
CAP_PLUGIN_METHOD(rebootReader, CAPPluginReturnPromise);
|
|
23
|
+
CAP_PLUGIN_METHOD(cancelReaderReconnection, CAPPluginReturnPromise);
|
|
17
24
|
)
|
|
@@ -3,10 +3,6 @@ import StripeTerminal
|
|
|
3
3
|
import Capacitor
|
|
4
4
|
import PassKit
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Please read the Capacitor iOS Plugin Development Guide
|
|
8
|
-
* here: https://capacitorjs.com/docs/plugins/ios
|
|
9
|
-
*/
|
|
10
6
|
@objc(StripeTerminalPlugin)
|
|
11
7
|
public class StripeTerminalPlugin: CAPPlugin {
|
|
12
8
|
private let implementation = StripeTerminal()
|
|
@@ -33,6 +29,10 @@ public class StripeTerminalPlugin: CAPPlugin {
|
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
|
|
32
|
+
@objc func setSimulatorConfiguration(_ call: CAPPluginCall) {
|
|
33
|
+
self.implementation.setSimulatorConfiguration(call)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
36
|
@objc func cancelDiscoverReaders(_ call: CAPPluginCall) {
|
|
37
37
|
self.implementation.cancelDiscoverReaders(call)
|
|
38
38
|
}
|
|
@@ -60,4 +60,29 @@ public class StripeTerminalPlugin: CAPPlugin {
|
|
|
60
60
|
@objc func confirmPaymentIntent(_ call: CAPPluginCall) {
|
|
61
61
|
self.implementation.confirmPaymentIntent(call)
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
@objc func installAvailableUpdate(_ call: CAPPluginCall) {
|
|
65
|
+
self.implementation.installAvailableUpdate(call)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@objc func cancelInstallUpdate(_ call: CAPPluginCall) {
|
|
69
|
+
self.implementation.cancelInstallUpdate(call)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@objc func setReaderDisplay(_ call: CAPPluginCall) {
|
|
73
|
+
self.implementation.setReaderDisplay(call)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@objc func clearReaderDisplay(_ call: CAPPluginCall) {
|
|
77
|
+
self.implementation.clearReaderDisplay(call)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@objc func rebootReader(_ call: CAPPluginCall) {
|
|
81
|
+
self.implementation.rebootReader(call)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@objc func cancelReaderReconnection(_ call: CAPPluginCall) {
|
|
85
|
+
self.implementation.cancelReaderReconnection(call)
|
|
86
|
+
}
|
|
87
|
+
|
|
63
88
|
}
|
|
@@ -3,9 +3,23 @@ public enum TerminalEvents: String {
|
|
|
3
3
|
case DiscoveredReaders = "terminalDiscoveredReaders"
|
|
4
4
|
case ConnectedReader = "terminalConnectedReader"
|
|
5
5
|
case DisconnectedReader = "terminalDisconnectedReader"
|
|
6
|
+
case ConnectionStatusChange = "terminalConnectionStatusChange"
|
|
7
|
+
case UnexpectedReaderDisconnect = "terminalUnexpectedReaderDisconnect"
|
|
6
8
|
case ConfirmedPaymentIntent = "terminalConfirmedPaymentIntent"
|
|
7
9
|
case CollectedPaymentIntent = "terminalCollectedPaymentIntent"
|
|
8
10
|
case Canceled = "terminalCanceled"
|
|
9
11
|
case Failed = "terminalFailed"
|
|
10
12
|
case RequestedConnectionToken = "terminalRequestedConnectionToken"
|
|
13
|
+
case ReportAvailableUpdate = "terminalReportAvailableUpdate"
|
|
14
|
+
case StartInstallingUpdate = "terminalStartInstallingUpdate"
|
|
15
|
+
case ReaderSoftwareUpdateProgress = "terminalReaderSoftwareUpdateProgress"
|
|
16
|
+
case FinishInstallingUpdate = "terminalFinishInstallingUpdate"
|
|
17
|
+
case BatteryLevel = "terminalBatteryLevel"
|
|
18
|
+
case ReaderEvent = "terminalReaderEvent"
|
|
19
|
+
case RequestDisplayMessage = "terminalRequestDisplayMessage"
|
|
20
|
+
case RequestReaderInput = "terminalRequestReaderInput"
|
|
21
|
+
case PaymentStatusChange = "terminalPaymentStatusChange"
|
|
22
|
+
case ReaderReconnectStarted = "terminalReaderReconnectStarted"
|
|
23
|
+
case ReaderReconnectSucceeded = "terminalReaderReconnectSucceeded"
|
|
24
|
+
case ReaderReconnectFailed = "terminalReaderReconnectFailed"
|
|
11
25
|
}
|