@capacitor-community/stripe-terminal 6.0.2 → 6.1.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 +484 -14
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java +111 -8
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminalPlugin.java +31 -5
- package/android/src/main/java/com/getcapacitor/community/stripe/terminal/TerminalEvent.kt +11 -0
- package/dist/docs.json +930 -17
- package/dist/esm/definitions.d.ts +173 -10
- package/dist/esm/definitions.js +1 -8
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/events.enum.d.ts +12 -1
- package/dist/esm/events.enum.js +11 -0
- package/dist/esm/events.enum.js.map +1 -1
- package/dist/esm/stripe.enum.d.ts +103 -0
- package/dist/esm/stripe.enum.js +115 -0
- package/dist/esm/stripe.enum.js.map +1 -0
- package/dist/esm/web.d.ts +6 -1
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +120 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +120 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/StripeTerminal.swift +113 -14
- package/ios/Plugin/StripeTerminalPlugin.m +1 -0
- package/ios/Plugin/StripeTerminalPlugin.swift +4 -0
- package/ios/Plugin/TerminalEvents.swift +11 -0
- package/ios/Plugin/TerminalMappers.swift +142 -0
- package/package.json +1 -1
package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java
CHANGED
|
@@ -26,6 +26,7 @@ import com.stripe.stripeterminal.external.callable.ReaderCallback;
|
|
|
26
26
|
import com.stripe.stripeterminal.external.callable.ReaderListener;
|
|
27
27
|
import com.stripe.stripeterminal.external.callable.ReaderReconnectionListener;
|
|
28
28
|
import com.stripe.stripeterminal.external.callable.TerminalListener;
|
|
29
|
+
import com.stripe.stripeterminal.external.models.BatteryStatus;
|
|
29
30
|
import com.stripe.stripeterminal.external.models.CardPresentDetails;
|
|
30
31
|
import com.stripe.stripeterminal.external.models.CollectConfiguration;
|
|
31
32
|
import com.stripe.stripeterminal.external.models.ConnectionConfiguration.BluetoothConnectionConfiguration;
|
|
@@ -33,12 +34,20 @@ import com.stripe.stripeterminal.external.models.ConnectionConfiguration.Interne
|
|
|
33
34
|
import com.stripe.stripeterminal.external.models.ConnectionConfiguration.LocalMobileConnectionConfiguration;
|
|
34
35
|
import com.stripe.stripeterminal.external.models.ConnectionConfiguration.UsbConnectionConfiguration;
|
|
35
36
|
import com.stripe.stripeterminal.external.models.ConnectionStatus;
|
|
37
|
+
import com.stripe.stripeterminal.external.models.DisconnectReason;
|
|
36
38
|
import com.stripe.stripeterminal.external.models.DiscoveryConfiguration;
|
|
37
39
|
import com.stripe.stripeterminal.external.models.PaymentIntent;
|
|
38
40
|
import com.stripe.stripeterminal.external.models.PaymentMethod;
|
|
39
41
|
import com.stripe.stripeterminal.external.models.PaymentStatus;
|
|
40
42
|
import com.stripe.stripeterminal.external.models.Reader;
|
|
43
|
+
import com.stripe.stripeterminal.external.models.ReaderDisplayMessage;
|
|
44
|
+
import com.stripe.stripeterminal.external.models.ReaderEvent;
|
|
45
|
+
import com.stripe.stripeterminal.external.models.ReaderInputOptions;
|
|
41
46
|
import com.stripe.stripeterminal.external.models.ReaderSoftwareUpdate;
|
|
47
|
+
import com.stripe.stripeterminal.external.models.SimulateReaderUpdate;
|
|
48
|
+
import com.stripe.stripeterminal.external.models.SimulatedCard;
|
|
49
|
+
import com.stripe.stripeterminal.external.models.SimulatedCardType;
|
|
50
|
+
import com.stripe.stripeterminal.external.models.SimulatorConfiguration;
|
|
42
51
|
import com.stripe.stripeterminal.external.models.TerminalException;
|
|
43
52
|
import com.stripe.stripeterminal.log.LogLevel;
|
|
44
53
|
import java.util.ArrayList;
|
|
@@ -95,17 +104,23 @@ public class StripeTerminal extends Executor {
|
|
|
95
104
|
TerminalListener listener = new TerminalListener() {
|
|
96
105
|
@Override
|
|
97
106
|
public void onUnexpectedReaderDisconnect(@NonNull Reader reader) {
|
|
98
|
-
|
|
107
|
+
notifyListeners(
|
|
108
|
+
TerminalEnumEvent.UnexpectedReaderDisconnect.getWebEventName(),
|
|
109
|
+
new JSObject().put("reader", convertReaderInterface(reader))
|
|
110
|
+
);
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
@Override
|
|
102
114
|
public void onConnectionStatusChange(@NonNull ConnectionStatus status) {
|
|
103
|
-
|
|
115
|
+
notifyListeners(
|
|
116
|
+
TerminalEnumEvent.ConnectionStatusChange.getWebEventName(),
|
|
117
|
+
new JSObject().put("status", status.toString())
|
|
118
|
+
);
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
@Override
|
|
107
122
|
public void onPaymentStatusChange(@NonNull PaymentStatus status) {
|
|
108
|
-
|
|
123
|
+
notifyListeners(TerminalEnumEvent.PaymentStatusChange.getWebEventName(), new JSObject().put("status", status.toString()));
|
|
109
124
|
}
|
|
110
125
|
};
|
|
111
126
|
LogLevel logLevel = LogLevel.VERBOSE;
|
|
@@ -121,6 +136,24 @@ public class StripeTerminal extends Executor {
|
|
|
121
136
|
this.tokenProvider.setConnectionToken(call);
|
|
122
137
|
}
|
|
123
138
|
|
|
139
|
+
public void setSimulatorConfiguration(PluginCall call) {
|
|
140
|
+
try {
|
|
141
|
+
Terminal
|
|
142
|
+
.getInstance()
|
|
143
|
+
.setSimulatorConfiguration(
|
|
144
|
+
new SimulatorConfiguration(
|
|
145
|
+
SimulateReaderUpdate.valueOf(call.getString("update", "UPDATE_AVAILABLE")),
|
|
146
|
+
new SimulatedCard(SimulatedCardType.valueOf(call.getString("simulatedCard", "VISA"))),
|
|
147
|
+
call.getLong("simulatedTipAmount", null)
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
call.resolve();
|
|
152
|
+
} catch (Exception ex) {
|
|
153
|
+
call.reject(ex.getMessage());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
124
157
|
public void onDiscoverReaders(final PluginCall call) {
|
|
125
158
|
if (
|
|
126
159
|
ActivityCompat.checkSelfPermission(this.contextSupplier.get(), Manifest.permission.ACCESS_FINE_LOCATION) !=
|
|
@@ -161,7 +194,7 @@ public class StripeTerminal extends Executor {
|
|
|
161
194
|
|
|
162
195
|
int i = 0;
|
|
163
196
|
for (Reader reader : this.readers) {
|
|
164
|
-
readersJSObject.put(
|
|
197
|
+
readersJSObject.put(convertReaderInterface(reader).put("index", String.valueOf(i)));
|
|
165
198
|
}
|
|
166
199
|
this.notifyListeners(TerminalEnumEvent.DiscoveredReaders.getWebEventName(), new JSObject().put("readers", readersJSObject));
|
|
167
200
|
call.resolve(new JSObject().put("readers", readersJSObject));
|
|
@@ -205,7 +238,7 @@ public class StripeTerminal extends Executor {
|
|
|
205
238
|
if (reader == null) {
|
|
206
239
|
call.resolve(new JSObject().put("reader", JSObject.NULL));
|
|
207
240
|
} else {
|
|
208
|
-
call.resolve(new JSObject().put("reader",
|
|
241
|
+
call.resolve(new JSObject().put("reader", convertReaderInterface(reader)));
|
|
209
242
|
}
|
|
210
243
|
}
|
|
211
244
|
|
|
@@ -338,7 +371,7 @@ public class StripeTerminal extends Executor {
|
|
|
338
371
|
|
|
339
372
|
@Override
|
|
340
373
|
public void onFailure(@NonNull TerminalException e) {
|
|
341
|
-
call.reject(e.
|
|
374
|
+
call.reject(e.getLocalizedMessage());
|
|
342
375
|
}
|
|
343
376
|
}
|
|
344
377
|
);
|
|
@@ -443,16 +476,39 @@ public class StripeTerminal extends Executor {
|
|
|
443
476
|
@Override
|
|
444
477
|
public void onStartInstallingUpdate(@NotNull ReaderSoftwareUpdate update, @NotNull Cancelable cancelable) {
|
|
445
478
|
// Show UI communicating that a required update has started installing
|
|
479
|
+
notifyListeners(
|
|
480
|
+
TerminalEnumEvent.StartInstallingUpdate.getWebEventName(),
|
|
481
|
+
new JSObject().put("update", convertReaderSoftwareUpdate(update))
|
|
482
|
+
);
|
|
446
483
|
}
|
|
447
484
|
|
|
448
485
|
@Override
|
|
449
486
|
public void onReportReaderSoftwareUpdateProgress(float progress) {
|
|
450
487
|
// Update the progress of the install
|
|
488
|
+
notifyListeners(TerminalEnumEvent.ReaderSoftwareUpdateProgress.getWebEventName(), new JSObject().put("progress", progress));
|
|
451
489
|
}
|
|
452
490
|
|
|
453
491
|
@Override
|
|
454
|
-
public void onFinishInstallingUpdate(@Nullable ReaderSoftwareUpdate update, @Nullable TerminalException
|
|
455
|
-
|
|
492
|
+
public void onFinishInstallingUpdate(@Nullable ReaderSoftwareUpdate update, @Nullable TerminalException error) {
|
|
493
|
+
JSObject eventObject = new JSObject();
|
|
494
|
+
|
|
495
|
+
if (error != null) {
|
|
496
|
+
// note: Since errorCode cannot be obtained in iOS, use errorMessage for unification.
|
|
497
|
+
eventObject.put("error", error.getLocalizedMessage());
|
|
498
|
+
notifyListeners(TerminalEnumEvent.FinishInstallingUpdate.getWebEventName(), eventObject);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
eventObject.put("update", update == null ? null : convertReaderSoftwareUpdate(update));
|
|
503
|
+
notifyListeners(TerminalEnumEvent.FinishInstallingUpdate.getWebEventName(), eventObject);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
@Override
|
|
507
|
+
public void onBatteryLevelUpdate(float batteryLevel, @NonNull BatteryStatus batteryStatus, boolean isCharging) {
|
|
508
|
+
notifyListeners(
|
|
509
|
+
TerminalEnumEvent.BatteryLevel.getWebEventName(),
|
|
510
|
+
new JSObject().put("level", batteryLevel).put("charging", isCharging).put("status", batteryStatus.toString())
|
|
511
|
+
);
|
|
456
512
|
}
|
|
457
513
|
|
|
458
514
|
@Override
|
|
@@ -462,7 +518,54 @@ public class StripeTerminal extends Executor {
|
|
|
462
518
|
public void onReportAvailableUpdate(@NotNull ReaderSoftwareUpdate update) {
|
|
463
519
|
// An update is available for the connected reader. Show this update in your application.
|
|
464
520
|
// This update can be installed using `Terminal.getInstance().installAvailableUpdate`.
|
|
521
|
+
notifyListeners(
|
|
522
|
+
TerminalEnumEvent.ReportAvailableUpdate.getWebEventName(),
|
|
523
|
+
new JSObject().put("update", convertReaderSoftwareUpdate(update))
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
@Override
|
|
528
|
+
public void onReportReaderEvent(@NotNull ReaderEvent event) {
|
|
529
|
+
notifyListeners(TerminalEnumEvent.ReaderEvent.getWebEventName(), new JSObject().put("event", event.toString()));
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
@Override
|
|
533
|
+
public void onRequestReaderDisplayMessage(@NotNull ReaderDisplayMessage message) {
|
|
534
|
+
notifyListeners(
|
|
535
|
+
TerminalEnumEvent.RequestDisplayMessage.getWebEventName(),
|
|
536
|
+
new JSObject().put("messageType", message.name()).put("message", message.toString())
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
@Override
|
|
541
|
+
public void onRequestReaderInput(@NotNull ReaderInputOptions options) {
|
|
542
|
+
List<ReaderInputOptions.ReaderInputOption> optionsList = options.getOptions();
|
|
543
|
+
JSArray jsOptions = new JSArray();
|
|
544
|
+
for (ReaderInputOptions.ReaderInputOption optionType : optionsList) {
|
|
545
|
+
jsOptions.put(optionType.name());
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
notifyListeners(
|
|
549
|
+
TerminalEnumEvent.RequestReaderInput.getWebEventName(),
|
|
550
|
+
new JSObject().put("options", jsOptions).put("message", options.toString())
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
public void onDisconnect(@NotNull DisconnectReason reason) {
|
|
555
|
+
notifyListeners(TerminalEnumEvent.DisconnectedReader.getWebEventName(), new JSObject().put("reason", reason.toString()));
|
|
465
556
|
}
|
|
466
557
|
};
|
|
467
558
|
}
|
|
559
|
+
|
|
560
|
+
private JSObject convertReaderInterface(Reader reader) {
|
|
561
|
+
return new JSObject().put("serialNumber", reader.getSerialNumber());
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private JSObject convertReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
|
|
565
|
+
return new JSObject()
|
|
566
|
+
.put("version", update.getVersion())
|
|
567
|
+
.put("settingsVersion", update.getSettingsVersion())
|
|
568
|
+
.put("requiredAt", update.getRequiredAt().getTime())
|
|
569
|
+
.put("timeEstimate", update.getTimeEstimate().toString());
|
|
570
|
+
}
|
|
468
571
|
}
|
package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminalPlugin.java
CHANGED
|
@@ -3,7 +3,6 @@ package com.getcapacitor.community.stripe.terminal;
|
|
|
3
3
|
import android.Manifest;
|
|
4
4
|
import android.os.Build;
|
|
5
5
|
import android.util.Log;
|
|
6
|
-
|
|
7
6
|
import androidx.annotation.RequiresApi;
|
|
8
7
|
import com.getcapacitor.PermissionState;
|
|
9
8
|
import com.getcapacitor.Plugin;
|
|
@@ -13,7 +12,6 @@ import com.getcapacitor.annotation.CapacitorPlugin;
|
|
|
13
12
|
import com.getcapacitor.annotation.Permission;
|
|
14
13
|
import com.getcapacitor.annotation.PermissionCallback;
|
|
15
14
|
import com.stripe.stripeterminal.external.models.TerminalException;
|
|
16
|
-
|
|
17
15
|
import java.util.Objects;
|
|
18
16
|
|
|
19
17
|
@RequiresApi(api = Build.VERSION_CODES.S)
|
|
@@ -47,6 +45,11 @@ public class StripeTerminalPlugin extends Plugin {
|
|
|
47
45
|
this.implementation.setConnectionToken(call);
|
|
48
46
|
}
|
|
49
47
|
|
|
48
|
+
@PluginMethod
|
|
49
|
+
public void setSimulatorConfiguration(PluginCall call) {
|
|
50
|
+
this.implementation.setSimulatorConfiguration(call);
|
|
51
|
+
}
|
|
52
|
+
|
|
50
53
|
@PermissionCallback
|
|
51
54
|
private void locationPermsCallback(PluginCall call) throws TerminalException {
|
|
52
55
|
if (getPermissionState("location") == PermissionState.GRANTED) {
|
|
@@ -59,7 +62,11 @@ public class StripeTerminalPlugin extends Plugin {
|
|
|
59
62
|
@PermissionCallback
|
|
60
63
|
private void bluetoothOldPermsCallback(PluginCall call) throws TerminalException {
|
|
61
64
|
if (getPermissionState("bluetooth_old") == PermissionState.GRANTED) {
|
|
62
|
-
|
|
65
|
+
if (Objects.equals(call.getMethodName(), "discoverReaders")) {
|
|
66
|
+
this.discoverReaders(call);
|
|
67
|
+
} else {
|
|
68
|
+
this.connectReader(call);
|
|
69
|
+
}
|
|
63
70
|
} else {
|
|
64
71
|
requestPermissionForAlias("bluetooth_old", call, "bluetoothOldPermsCallback");
|
|
65
72
|
}
|
|
@@ -68,7 +75,11 @@ public class StripeTerminalPlugin extends Plugin {
|
|
|
68
75
|
@PermissionCallback
|
|
69
76
|
private void bluetoothPermsCallback(PluginCall call) throws TerminalException {
|
|
70
77
|
if (getPermissionState("bluetooth") == PermissionState.GRANTED) {
|
|
71
|
-
|
|
78
|
+
if (Objects.equals(call.getMethodName(), "discoverReaders")) {
|
|
79
|
+
this.discoverReaders(call);
|
|
80
|
+
} else {
|
|
81
|
+
this.connectReader(call);
|
|
82
|
+
}
|
|
72
83
|
} else {
|
|
73
84
|
requestPermissionForAlias("bluetooth", call, "bluetoothPermsCallback");
|
|
74
85
|
}
|
|
@@ -85,7 +96,22 @@ public class StripeTerminalPlugin extends Plugin {
|
|
|
85
96
|
|
|
86
97
|
@PluginMethod
|
|
87
98
|
public void discoverReaders(PluginCall call) {
|
|
88
|
-
|
|
99
|
+
if (
|
|
100
|
+
Objects.equals(call.getString("type"), TerminalConnectTypes.Bluetooth.getWebEventName()) ||
|
|
101
|
+
Objects.equals(call.getString("type"), TerminalConnectTypes.Simulated.getWebEventName())
|
|
102
|
+
) {
|
|
103
|
+
Log.d("Capacitor:permission bluetooth_old", getPermissionState("bluetooth_old").toString());
|
|
104
|
+
Log.d("Capacitor:permission bluetooth", getPermissionState("bluetooth").toString());
|
|
105
|
+
if (Build.VERSION.SDK_INT <= 30 && getPermissionState("bluetooth_old") != PermissionState.GRANTED) {
|
|
106
|
+
requestPermissionForAlias("bluetooth_old", call, "bluetoothOldPermsCallback");
|
|
107
|
+
} else if (Build.VERSION.SDK_INT > 30 && getPermissionState("bluetooth") != PermissionState.GRANTED) {
|
|
108
|
+
requestPermissionForAlias("bluetooth", call, "bluetoothPermsCallback");
|
|
109
|
+
} else {
|
|
110
|
+
this.implementation.onDiscoverReaders(call);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
this.implementation.onDiscoverReaders(call);
|
|
114
|
+
}
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
@PluginMethod
|
|
@@ -6,9 +6,20 @@ enum class TerminalEnumEvent(val webEventName: String) {
|
|
|
6
6
|
CancelDiscoveredReaders("terminalCancelDiscoveredReaders"),
|
|
7
7
|
ConnectedReader("terminalConnectedReader"),
|
|
8
8
|
DisconnectedReader("terminalDisconnectedReader"),
|
|
9
|
+
ConnectionStatusChange("terminalConnectionStatusChange"),
|
|
10
|
+
UnexpectedReaderDisconnect("terminalUnexpectedReaderDisconnect"),
|
|
9
11
|
ConfirmedPaymentIntent("terminalConfirmedPaymentIntent"),
|
|
10
12
|
CollectedPaymentIntent("terminalCollectedPaymentIntent"),
|
|
11
13
|
Canceled("terminalCanceled"),
|
|
12
14
|
Failed("terminalFailed"),
|
|
13
15
|
RequestedConnectionToken("terminalRequestedConnectionToken"),
|
|
16
|
+
ReportAvailableUpdate("terminalReportAvailableUpdate"),
|
|
17
|
+
StartInstallingUpdate("terminalStartInstallingUpdate"),
|
|
18
|
+
ReaderSoftwareUpdateProgress("terminalReaderSoftwareUpdateProgress"),
|
|
19
|
+
FinishInstallingUpdate("terminalFinishInstallingUpdate"),
|
|
20
|
+
BatteryLevel("terminalBatteryLevel"),
|
|
21
|
+
ReaderEvent("terminalReaderEvent"),
|
|
22
|
+
RequestDisplayMessage("terminalRequestDisplayMessage"),
|
|
23
|
+
RequestReaderInput("terminalRequestReaderInput"),
|
|
24
|
+
PaymentStatusChange("terminalPaymentStatusChange"),
|
|
14
25
|
}
|