capacitor-stripe-terminal 2.1.1-beta.1 → 3.0.0-beta.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.
@@ -8,7 +8,7 @@
8
8
  s.author = 'eventOne Labs <opensource@event1.io>'
9
9
  s.source = { :git => 'https://github.com/eventOneHQ/capacitor-stripe-terminal', :tag => s.version.to_s }
10
10
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
11
- s.ios.deployment_target = '12.0'
11
+ s.ios.deployment_target = '13.0'
12
12
  s.dependency 'Capacitor'
13
- s.dependency 'StripeTerminal', '2.8.0'
13
+ s.dependency 'StripeTerminal', '2.14.0'
14
14
  end
@@ -55,6 +55,6 @@ dependencies {
55
55
  testImplementation "junit:junit:$junitVersion"
56
56
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
57
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
- implementation "com.stripe:stripeterminal:2.10.0"
58
+ implementation "com.stripe:stripeterminal:2.15.0"
59
59
  implementation "com.google.code.gson:gson:2.8.8"
60
60
  }
@@ -4,5 +4,7 @@
4
4
 
5
5
  <uses-permission android:name="android.permission.BLUETOOTH" />
6
6
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
7
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
8
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
7
9
  </manifest>
8
10
 
@@ -20,15 +20,21 @@ import com.stripe.stripeterminal.external.callable.Cancelable;
20
20
  import com.stripe.stripeterminal.external.callable.ConnectionTokenCallback;
21
21
  import com.stripe.stripeterminal.external.callable.ConnectionTokenProvider;
22
22
  import com.stripe.stripeterminal.external.callable.DiscoveryListener;
23
+ import com.stripe.stripeterminal.external.callable.HandoffReaderListener;
23
24
  import com.stripe.stripeterminal.external.callable.LocationListCallback;
24
25
  import com.stripe.stripeterminal.external.callable.PaymentIntentCallback;
25
26
  import com.stripe.stripeterminal.external.callable.ReaderCallback;
26
27
  import com.stripe.stripeterminal.external.callable.TerminalListener;
28
+ import com.stripe.stripeterminal.external.callable.UsbReaderListener;
27
29
  import com.stripe.stripeterminal.external.models.BatteryStatus;
28
30
  import com.stripe.stripeterminal.external.models.Cart;
29
31
  import com.stripe.stripeterminal.external.models.CartLineItem;
30
32
  import com.stripe.stripeterminal.external.models.ConnectionConfiguration.BluetoothConnectionConfiguration;
33
+ import com.stripe.stripeterminal.external.models.ConnectionConfiguration.EmbeddedConnectionConfiguration;
34
+ import com.stripe.stripeterminal.external.models.ConnectionConfiguration.HandoffConnectionConfiguration;
31
35
  import com.stripe.stripeterminal.external.models.ConnectionConfiguration.InternetConnectionConfiguration;
36
+ import com.stripe.stripeterminal.external.models.ConnectionConfiguration.LocalMobileConnectionConfiguration;
37
+ import com.stripe.stripeterminal.external.models.ConnectionConfiguration.UsbConnectionConfiguration;
32
38
  import com.stripe.stripeterminal.external.models.ConnectionStatus;
33
39
  import com.stripe.stripeterminal.external.models.ConnectionTokenException;
34
40
  import com.stripe.stripeterminal.external.models.DiscoveryConfiguration;
@@ -75,6 +81,8 @@ public class StripeTerminal
75
81
  ConnectionTokenProvider,
76
82
  TerminalListener,
77
83
  DiscoveryListener,
84
+ UsbReaderListener,
85
+ HandoffReaderListener,
78
86
  BluetoothReaderListener {
79
87
 
80
88
  Cancelable pendingDiscoverReaders = null;
@@ -321,6 +329,22 @@ public class StripeTerminal
321
329
  return selectedReader;
322
330
  }
323
331
 
332
+ private ReaderCallback createReaderCallback(final PluginCall call) {
333
+ return new ReaderCallback() {
334
+ @Override
335
+ public void onSuccess(@NonNull Reader reader) {
336
+ JSObject ret = new JSObject();
337
+ ret.put("reader", TerminalUtils.serializeReader(reader));
338
+ call.resolve(ret);
339
+ }
340
+
341
+ @Override
342
+ public void onFailure(@NonNull TerminalException e) {
343
+ call.reject(e.getErrorMessage(), e);
344
+ }
345
+ };
346
+ }
347
+
324
348
  @PluginMethod
325
349
  public void connectInternetReader(final PluginCall call) {
326
350
  Reader reader = getReaderFromDiscovered(call);
@@ -342,19 +366,7 @@ public class StripeTerminal
342
366
  .connectInternetReader(
343
367
  reader,
344
368
  connectionConfig,
345
- new ReaderCallback() {
346
- @Override
347
- public void onSuccess(@NonNull Reader reader) {
348
- JSObject ret = new JSObject();
349
- ret.put("reader", TerminalUtils.serializeReader(reader));
350
- call.resolve(ret);
351
- }
352
-
353
- @Override
354
- public void onFailure(@NonNull TerminalException e) {
355
- call.reject(e.getErrorMessage(), e);
356
- }
357
- }
369
+ this.createReaderCallback(call)
358
370
  );
359
371
  }
360
372
 
@@ -383,19 +395,121 @@ public class StripeTerminal
383
395
  reader,
384
396
  connectionConfig,
385
397
  this,
386
- new ReaderCallback() {
387
- @Override
388
- public void onSuccess(@NonNull Reader reader) {
389
- JSObject ret = new JSObject();
390
- ret.put("reader", TerminalUtils.serializeReader(reader));
391
- call.resolve(ret);
392
- }
398
+ this.createReaderCallback(call)
399
+ );
400
+ }
393
401
 
394
- @Override
395
- public void onFailure(@NonNull TerminalException e) {
396
- call.reject(e.getErrorMessage(), e);
397
- }
398
- }
402
+ @PluginMethod
403
+ public void connectUsbReader(final PluginCall call) {
404
+ Reader reader = getReaderFromDiscovered(call);
405
+
406
+ if (reader == null) {
407
+ return;
408
+ }
409
+
410
+ String locationId = call.getString("locationId");
411
+
412
+ if (locationId == null) {
413
+ call.reject("Must provide a location ID");
414
+ return;
415
+ }
416
+
417
+ UsbConnectionConfiguration connectionConfig = new UsbConnectionConfiguration(
418
+ locationId
419
+ );
420
+
421
+ Terminal
422
+ .getInstance()
423
+ .connectUsbReader(
424
+ reader,
425
+ connectionConfig,
426
+ this,
427
+ this.createReaderCallback(call)
428
+ );
429
+ }
430
+
431
+ @PluginMethod
432
+ public void connectLocalMobileReader(final PluginCall call) {
433
+ Reader reader = getReaderFromDiscovered(call);
434
+
435
+ if (reader == null) {
436
+ return;
437
+ }
438
+
439
+ String locationId = call.getString("locationId");
440
+
441
+ if (locationId == null) {
442
+ call.reject("Must provide a location ID");
443
+ return;
444
+ }
445
+
446
+ LocalMobileConnectionConfiguration connectionConfig = new LocalMobileConnectionConfiguration(
447
+ locationId
448
+ );
449
+
450
+ Terminal
451
+ .getInstance()
452
+ .connectLocalMobileReader(
453
+ reader,
454
+ connectionConfig,
455
+ this.createReaderCallback(call)
456
+ );
457
+ }
458
+
459
+ @PluginMethod
460
+ public void connectEmbeddedReader(final PluginCall call) {
461
+ Reader reader = getReaderFromDiscovered(call);
462
+
463
+ if (reader == null) {
464
+ return;
465
+ }
466
+
467
+ String locationId = call.getString("locationId");
468
+
469
+ if (locationId == null) {
470
+ call.reject("Must provide a location ID");
471
+ return;
472
+ }
473
+
474
+ EmbeddedConnectionConfiguration connectionConfig = new EmbeddedConnectionConfiguration(
475
+ locationId
476
+ );
477
+
478
+ Terminal
479
+ .getInstance()
480
+ .connectEmbeddedReader(
481
+ reader,
482
+ connectionConfig,
483
+ this.createReaderCallback(call)
484
+ );
485
+ }
486
+
487
+ @PluginMethod
488
+ public void connectHandoffReader(final PluginCall call) {
489
+ Reader reader = getReaderFromDiscovered(call);
490
+
491
+ if (reader == null) {
492
+ return;
493
+ }
494
+
495
+ String locationId = call.getString("locationId");
496
+
497
+ if (locationId == null) {
498
+ call.reject("Must provide a location ID");
499
+ return;
500
+ }
501
+
502
+ HandoffConnectionConfiguration connectionConfig = new HandoffConnectionConfiguration(
503
+ locationId
504
+ );
505
+
506
+ Terminal
507
+ .getInstance()
508
+ .connectHandoffReader(
509
+ reader,
510
+ connectionConfig,
511
+ this,
512
+ this.createReaderCallback(call)
399
513
  );
400
514
  }
401
515
 
@@ -426,7 +540,13 @@ public class StripeTerminal
426
540
  public void getConnectedReader(PluginCall call) {
427
541
  Reader reader = Terminal.getInstance().getConnectedReader();
428
542
  JSObject ret = new JSObject();
429
- ret.put("reader", TerminalUtils.serializeReader(reader));
543
+
544
+ if (reader == null) {
545
+ ret.put("reader", JSObject.NULL);
546
+ } else {
547
+ ret.put("reader", TerminalUtils.serializeReader(reader));
548
+ }
549
+
430
550
  call.resolve(ret);
431
551
  }
432
552
 
@@ -17,74 +17,80 @@ import com.stripe.stripeterminal.external.models.SimulatorConfiguration;
17
17
 
18
18
  public class TerminalUtils {
19
19
 
20
- public static JSObject serializeReader(Reader reader) {
20
+ public static Object serializeReader(Reader reader) {
21
+ if (reader == null) {
22
+ return JSObject.NULL;
23
+ }
24
+
21
25
  JSObject object = new JSObject();
22
26
 
23
- if (reader != null) {
24
- // device type
25
- object.put(
26
- "deviceType",
27
- translateDeviceTypeToJS(reader.getDeviceType().ordinal())
28
- );
29
-
30
- // simulated
31
- object.put("simulated", reader.isSimulated());
32
-
33
- // stripe id
34
- object.put("stripeId", reader.getId());
35
-
36
- // location id
37
- String locationId = null;
38
- if (reader.getLocation() != null) locationId =
39
- reader.getLocation().getId();
40
- object.put("locationId", locationId);
41
-
42
- // location status
43
- object.put("locationStatus", reader.getLocationStatus().ordinal());
44
-
45
- // serial number
46
- String serial = null;
47
- if (reader.getSerialNumber() != null) serial = reader.getSerialNumber();
48
- object.put("serialNumber", serial);
49
-
50
- //
51
- // BLUETOOTH READER PROPS
52
- //
53
-
54
- // software version
55
- object.put("deviceSoftwareVersion", reader.getSoftwareVersion());
56
-
57
- // is update available
58
- object.put("isAvailableUpdate", reader.getAvailableUpdate() != null);
59
-
60
- // battery level
61
- Float level = reader.getBatteryLevel();
62
- double batteryLevel = 0;
63
- if (level != null) batteryLevel = (double) level;
64
- object.put("batteryLevel", batteryLevel);
65
-
66
- //
67
- // INTERNET READER PROPS
68
- //
69
-
70
- // status
71
- int status = Reader.NetworkStatus.OFFLINE.ordinal();
72
- if (reader.getNetworkStatus() != null) status =
73
- reader.getNetworkStatus().ordinal();
74
- object.put("status", translateNetworkStatusToJS(status));
75
-
76
- // label
77
- String label = null;
78
- if (reader.getLabel() != null) label = reader.getLabel();
79
- object.put("label", label);
80
- }
27
+ // device type
28
+ object.put(
29
+ "deviceType",
30
+ translateDeviceTypeToJS(reader.getDeviceType().ordinal())
31
+ );
32
+
33
+ // simulated
34
+ object.put("simulated", reader.isSimulated());
35
+
36
+ // stripe id
37
+ object.put("stripeId", reader.getId());
38
+
39
+ // location id
40
+ String locationId = null;
41
+ if (reader.getLocation() != null) locationId = reader.getLocation().getId();
42
+ object.put("locationId", locationId);
43
+
44
+ // location status
45
+ object.put("locationStatus", reader.getLocationStatus().ordinal());
46
+
47
+ // serial number
48
+ String serial = null;
49
+ if (reader.getSerialNumber() != null) serial = reader.getSerialNumber();
50
+ object.put("serialNumber", serial);
51
+
52
+ //
53
+ // BLUETOOTH READER PROPS
54
+ //
55
+
56
+ // software version
57
+ object.put("deviceSoftwareVersion", reader.getSoftwareVersion());
58
+
59
+ // is update available
60
+ object.put("isAvailableUpdate", reader.getAvailableUpdate() != null);
61
+
62
+ // battery level
63
+ Float level = reader.getBatteryLevel();
64
+ double batteryLevel = 0;
65
+ if (level != null) batteryLevel = (double) level;
66
+ object.put("batteryLevel", batteryLevel);
67
+
68
+ //
69
+ // INTERNET READER PROPS
70
+ //
71
+
72
+ // status
73
+ int status = Reader.NetworkStatus.OFFLINE.ordinal();
74
+ if (reader.getNetworkStatus() != null) status =
75
+ reader.getNetworkStatus().ordinal();
76
+ object.put("status", translateNetworkStatusToJS(status));
77
+
78
+ // label
79
+ String label = null;
80
+ if (reader.getLabel() != null) label = reader.getLabel();
81
+ object.put("label", label);
82
+
81
83
  return object;
82
84
  }
83
85
 
84
- public static JSObject serializePaymentIntent(
86
+ public static Object serializePaymentIntent(
85
87
  PaymentIntent paymentIntent,
86
88
  String currency
87
89
  ) {
90
+ if (paymentIntent == null) {
91
+ return JSObject.NULL;
92
+ }
93
+
88
94
  JSObject object = new JSObject();
89
95
 
90
96
  object.put("stripeId", paymentIntent.getId());
@@ -107,55 +113,61 @@ public class TerminalUtils {
107
113
  return object;
108
114
  }
109
115
 
110
- public static JSObject serializeUpdate(
116
+ public static Object serializeUpdate(
111
117
  ReaderSoftwareUpdate readerSoftwareUpdate
112
118
  ) {
119
+ if (readerSoftwareUpdate == null) {
120
+ return JSObject.NULL;
121
+ }
122
+
113
123
  JSObject object = new JSObject();
114
124
 
115
- if (readerSoftwareUpdate != null) {
116
- ReaderSoftwareUpdate.UpdateTimeEstimate updateTimeEstimate = readerSoftwareUpdate.getTimeEstimate();
117
-
118
- object.put(
119
- "estimatedUpdateTimeString",
120
- updateTimeEstimate.getDescription()
121
- );
122
- object.put("estimatedUpdateTime", updateTimeEstimate.ordinal());
123
- object.put("deviceSoftwareVersion", readerSoftwareUpdate.getVersion());
124
- object.put("components", readerSoftwareUpdate.getComponents());
125
- object.put("requiredAt", readerSoftwareUpdate.getRequiredAt().getTime());
126
- }
125
+ ReaderSoftwareUpdate.UpdateTimeEstimate updateTimeEstimate = readerSoftwareUpdate.getTimeEstimate();
126
+
127
+ object.put(
128
+ "estimatedUpdateTimeString",
129
+ updateTimeEstimate.getDescription()
130
+ );
131
+ object.put("estimatedUpdateTime", updateTimeEstimate.ordinal());
132
+ object.put("deviceSoftwareVersion", readerSoftwareUpdate.getVersion());
133
+ object.put("components", readerSoftwareUpdate.getComponents());
134
+ object.put("requiredAt", readerSoftwareUpdate.getRequiredAt().getTime());
127
135
 
128
136
  return object;
129
137
  }
130
138
 
131
- public static JSObject serializeLocation(Location location) {
139
+ public static Object serializeLocation(Location location) {
140
+ if (location == null) {
141
+ return JSObject.NULL;
142
+ }
143
+
132
144
  JSObject object = new JSObject();
133
145
 
134
- if (location != null) {
135
- object.put("stripeId", location.getId());
136
- object.put("displayName", location.getDisplayName());
137
- object.put("livemode", location.getLivemode());
146
+ object.put("stripeId", location.getId());
147
+ object.put("displayName", location.getDisplayName());
148
+ object.put("livemode", location.getLivemode());
138
149
 
139
- Address address = location.getAddress();
140
- if (address != null) {
141
- object.put("address", serializeAddress(address));
142
- }
150
+ Address address = location.getAddress();
151
+ if (address != null) {
152
+ object.put("address", serializeAddress(address));
143
153
  }
144
154
 
145
155
  return object;
146
156
  }
147
157
 
148
- public static JSObject serializeAddress(Address address) {
158
+ public static Object serializeAddress(Address address) {
159
+ if (address == null) {
160
+ return JSObject.NULL;
161
+ }
162
+
149
163
  JSObject object = new JSObject();
150
164
 
151
- if (address != null) {
152
- object.put("city", address.getCity());
153
- object.put("country", address.getCountry());
154
- object.put("line1", address.getLine1());
155
- object.put("line2", address.getLine2());
156
- object.put("postalCode", address.getPostalCode());
157
- object.put("state", address.getState());
158
- }
165
+ object.put("city", address.getCity());
166
+ object.put("country", address.getCountry());
167
+ object.put("line1", address.getLine1());
168
+ object.put("line2", address.getLine2());
169
+ object.put("postalCode", address.getPostalCode());
170
+ object.put("state", address.getState());
159
171
 
160
172
  return object;
161
173
  }
@@ -165,10 +177,8 @@ public class TerminalUtils {
165
177
  ) {
166
178
  JSObject object = new JSObject();
167
179
 
168
- if (config != null) {
169
- object.put("availableReaderUpdate", config.getUpdate().ordinal());
170
- // object.put("simulatedCard", config.getSimulatedCard().getEmvBlob().toString());
171
- }
180
+ object.put("availableReaderUpdate", config.getUpdate().ordinal());
181
+ // object.put("simulatedCard", config.getSimulatedCard().getEmvBlob().toString());
172
182
 
173
183
  return object;
174
184
  }
@@ -180,6 +190,14 @@ public class TerminalUtils {
180
190
  return DiscoveryMethod.BLUETOOTH_SCAN;
181
191
  } else if (method == 2) {
182
192
  return DiscoveryMethod.INTERNET;
193
+ } else if (method == 4) {
194
+ return DiscoveryMethod.USB;
195
+ } else if (method == 5) {
196
+ return DiscoveryMethod.EMBEDDED;
197
+ } else if (method == 6) {
198
+ return DiscoveryMethod.HANDOFF;
199
+ } else if (method == 7) {
200
+ return DiscoveryMethod.LOCAL_MOBILE;
183
201
  } else {
184
202
  return DiscoveryMethod.BLUETOOTH_SCAN;
185
203
  }
@@ -197,8 +215,10 @@ public class TerminalUtils {
197
215
  return 2;
198
216
  } else if (type == DeviceType.WISEPOS_E.ordinal()) {
199
217
  return 4;
218
+ } else if (type == DeviceType.STRIPE_S700.ordinal()) {
219
+ return 9;
200
220
  } else {
201
- return 5;
221
+ return 6;
202
222
  }
203
223
  }
204
224