capacitor-stripe-terminal 2.1.0 → 2.1.1-beta.1
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/ios/Plugin/Plugin.swift +68 -39
- package/package.json +1 -1
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -15,6 +15,7 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
15
15
|
private var currentUpdate: ReaderSoftwareUpdate?
|
|
16
16
|
private var currentPaymentIntent: PaymentIntent?
|
|
17
17
|
private var isInitialized: Bool = false
|
|
18
|
+
private var thread = DispatchQueue.init(label: "CapacitorStripeTerminal")
|
|
18
19
|
|
|
19
20
|
private var readers: [Reader]?
|
|
20
21
|
|
|
@@ -194,6 +195,7 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
194
195
|
return
|
|
195
196
|
}
|
|
196
197
|
|
|
198
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
197
199
|
DispatchQueue.main.async {
|
|
198
200
|
Terminal.shared.disconnectReader { error in
|
|
199
201
|
if let error = error {
|
|
@@ -201,8 +203,10 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
201
203
|
} else {
|
|
202
204
|
call.resolve()
|
|
203
205
|
}
|
|
206
|
+
semaphore.signal()
|
|
204
207
|
}
|
|
205
208
|
}
|
|
209
|
+
_ = semaphore.wait(timeout: .now() + 10)
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
@objc func installAvailableUpdate(_ call: CAPPluginCall) {
|
|
@@ -252,15 +256,20 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
252
256
|
return
|
|
253
257
|
}
|
|
254
258
|
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
260
|
+
thread.async {
|
|
261
|
+
Terminal.shared.retrievePaymentIntent(clientSecret: clientSecret) { retrieveResult, retrieveError in
|
|
262
|
+
self.currentPaymentIntent = retrieveResult
|
|
257
263
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
264
|
+
if let error = retrieveError {
|
|
265
|
+
call.reject(error.localizedDescription, nil, error)
|
|
266
|
+
} else if let paymentIntent = retrieveResult {
|
|
267
|
+
call.resolve(["intent": StripeTerminalUtils.serializePaymentIntent(intent: paymentIntent)])
|
|
268
|
+
}
|
|
269
|
+
semaphore.signal()
|
|
262
270
|
}
|
|
263
271
|
}
|
|
272
|
+
_ = semaphore.wait(timeout: .now() + 10)
|
|
264
273
|
}
|
|
265
274
|
|
|
266
275
|
@objc func cancelCollectPaymentMethod(_ call: CAPPluginCall? = nil) {
|
|
@@ -298,23 +307,27 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
298
307
|
}
|
|
299
308
|
|
|
300
309
|
@objc func processPayment(_ call: CAPPluginCall) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
310
|
+
thread.async {
|
|
311
|
+
if let intent = self.currentPaymentIntent {
|
|
312
|
+
Terminal.shared.processPayment(intent) { paymentIntent, error in
|
|
313
|
+
if let error = error {
|
|
314
|
+
call.reject(error.localizedDescription, nil, error)
|
|
315
|
+
} else if let paymentIntent = paymentIntent {
|
|
316
|
+
self.currentPaymentIntent = paymentIntent
|
|
317
|
+
call.resolve(["intent": StripeTerminalUtils.serializePaymentIntent(intent: paymentIntent)])
|
|
318
|
+
}
|
|
308
319
|
}
|
|
320
|
+
} else {
|
|
321
|
+
call.reject("There is no active payment intent. Make sure you called retrievePaymentIntent first")
|
|
309
322
|
}
|
|
310
|
-
} else {
|
|
311
|
-
call.reject("There is no active payment intent. Make sure you called retrievePaymentIntent first")
|
|
312
323
|
}
|
|
313
324
|
}
|
|
314
325
|
|
|
315
326
|
@objc func clearCachedCredentials(_ call: CAPPluginCall) {
|
|
316
|
-
|
|
317
|
-
|
|
327
|
+
thread.async {
|
|
328
|
+
Terminal.shared.clearCachedCredentials()
|
|
329
|
+
call.resolve()
|
|
330
|
+
}
|
|
318
331
|
}
|
|
319
332
|
|
|
320
333
|
@objc func setReaderDisplay(_ call: CAPPluginCall) {
|
|
@@ -336,23 +349,33 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
336
349
|
|
|
337
350
|
cart.lineItems = lineItemsArray
|
|
338
351
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
352
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
353
|
+
thread.async {
|
|
354
|
+
Terminal.shared.setReaderDisplay(cart) { error in
|
|
355
|
+
if let error = error {
|
|
356
|
+
call.reject(error.localizedDescription, nil, error)
|
|
357
|
+
} else {
|
|
358
|
+
call.resolve()
|
|
359
|
+
}
|
|
360
|
+
semaphore.signal()
|
|
344
361
|
}
|
|
345
362
|
}
|
|
363
|
+
_ = semaphore.wait(timeout: .now() + 10)
|
|
346
364
|
}
|
|
347
365
|
|
|
348
366
|
@objc func clearReaderDisplay(_ call: CAPPluginCall) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
367
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
368
|
+
thread.async {
|
|
369
|
+
Terminal.shared.clearReaderDisplay { error in
|
|
370
|
+
if let error = error {
|
|
371
|
+
call.reject(error.localizedDescription, nil, error)
|
|
372
|
+
} else {
|
|
373
|
+
call.resolve()
|
|
374
|
+
}
|
|
375
|
+
semaphore.signal()
|
|
354
376
|
}
|
|
355
377
|
}
|
|
378
|
+
_ = semaphore.wait(timeout: .now() + 10)
|
|
356
379
|
}
|
|
357
380
|
|
|
358
381
|
@objc func listLocations(_ call: CAPPluginCall) {
|
|
@@ -367,21 +390,27 @@ public class StripeTerminal: CAPPlugin, ConnectionTokenProvider, DiscoveryDelega
|
|
|
367
390
|
endingBefore: endingBefore,
|
|
368
391
|
startingAfter: startingAfter)
|
|
369
392
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
let
|
|
375
|
-
(
|
|
376
|
-
|
|
377
|
-
|
|
393
|
+
|
|
394
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
395
|
+
thread.async {
|
|
396
|
+
Terminal.shared.listLocations(parameters: params) { locations, hasMore, error in
|
|
397
|
+
if let error = error {
|
|
398
|
+
call.reject(error.localizedDescription, nil, error)
|
|
399
|
+
} else {
|
|
400
|
+
let locationsJSON = locations?.map {
|
|
401
|
+
(location: Location) -> [String: Any] in
|
|
402
|
+
StripeTerminalUtils.serializeLocation(location: location)
|
|
403
|
+
}
|
|
378
404
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
405
|
+
call.resolve([
|
|
406
|
+
"hasMore": hasMore,
|
|
407
|
+
"locations": locationsJSON as Any,
|
|
408
|
+
])
|
|
409
|
+
}
|
|
410
|
+
semaphore.signal()
|
|
383
411
|
}
|
|
384
412
|
}
|
|
413
|
+
_ = semaphore.wait(timeout: .now() + 10)
|
|
385
414
|
}
|
|
386
415
|
|
|
387
416
|
@objc func getSimulatorConfiguration(_ call: CAPPluginCall) {
|