@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.
Files changed (36) hide show
  1. package/CapacitorCommunityStripeTerminal.podspec +1 -1
  2. package/README.md +767 -28
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java +372 -51
  5. package/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminalPlugin.java +61 -5
  6. package/android/src/main/java/com/getcapacitor/community/stripe/terminal/TerminalEvent.kt +14 -0
  7. package/android/src/main/java/com/getcapacitor/community/stripe/terminal/helper/TerminalMappers.java +96 -0
  8. package/dist/docs.json +1389 -111
  9. package/dist/esm/definitions.d.ts +263 -11
  10. package/dist/esm/definitions.js +1 -8
  11. package/dist/esm/definitions.js.map +1 -1
  12. package/dist/esm/events.enum.d.ts +15 -1
  13. package/dist/esm/events.enum.js +14 -0
  14. package/dist/esm/events.enum.js.map +1 -1
  15. package/dist/esm/stripe-types/proto.d.ts +501 -0
  16. package/dist/esm/stripe-types/proto.js +2 -0
  17. package/dist/esm/stripe-types/proto.js.map +1 -0
  18. package/dist/esm/stripe.enum.d.ts +154 -0
  19. package/dist/esm/stripe.enum.js +170 -0
  20. package/dist/esm/stripe.enum.js.map +1 -0
  21. package/dist/esm/terminalMappers.d.ts +23 -0
  22. package/dist/esm/terminalMappers.js +119 -0
  23. package/dist/esm/terminalMappers.js.map +1 -0
  24. package/dist/esm/web.d.ts +25 -2
  25. package/dist/esm/web.js +137 -13
  26. package/dist/esm/web.js.map +1 -1
  27. package/dist/plugin.cjs.js +428 -13
  28. package/dist/plugin.cjs.js.map +1 -1
  29. package/dist/plugin.js +429 -15
  30. package/dist/plugin.js.map +1 -1
  31. package/ios/Plugin/StripeTerminal.swift +345 -61
  32. package/ios/Plugin/StripeTerminalPlugin.m +7 -0
  33. package/ios/Plugin/StripeTerminalPlugin.swift +29 -4
  34. package/ios/Plugin/TerminalEvents.swift +14 -0
  35. package/ios/Plugin/TerminalMappers.swift +269 -0
  36. package/package.json +4 -1
@@ -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
- this.connectReader(call);
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
- this.connectReader(call);
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
- this.implementation.onDiscoverReaders(call);
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
@@ -134,4 +160,34 @@ public class StripeTerminalPlugin extends Plugin {
134
160
  public void confirmPaymentIntent(PluginCall call) {
135
161
  this.implementation.confirmPaymentIntent(call);
136
162
  }
163
+
164
+ @PluginMethod
165
+ public void installAvailableUpdate(PluginCall call) {
166
+ this.implementation.installAvailableUpdate(call);
167
+ }
168
+
169
+ @PluginMethod
170
+ public void cancelInstallUpdate(PluginCall call) {
171
+ this.implementation.cancelInstallUpdate(call);
172
+ }
173
+
174
+ @PluginMethod
175
+ public void setReaderDisplay(PluginCall call) {
176
+ this.implementation.setReaderDisplay(call);
177
+ }
178
+
179
+ @PluginMethod
180
+ public void clearReaderDisplay(PluginCall call) {
181
+ this.implementation.clearReaderDisplay(call);
182
+ }
183
+
184
+ @PluginMethod
185
+ public void rebootReader(PluginCall call) {
186
+ this.implementation.rebootReader(call);
187
+ }
188
+
189
+ @PluginMethod
190
+ public void cancelReaderReconnection(PluginCall call) {
191
+ this.implementation.cancelReaderReconnection(call);
192
+ }
137
193
  }
@@ -6,9 +6,23 @@ 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"),
25
+ ReaderReconnectStarted("terminalReaderReconnectStarted"),
26
+ ReaderReconnectSucceeded("terminalReaderReconnectSucceeded"),
27
+ ReaderReconnectFailed("terminalReaderReconnectFailed"),
14
28
  }
@@ -0,0 +1,96 @@
1
+ package com.getcapacitor.community.stripe.terminal.helper;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.stripe.stripeterminal.external.models.DeviceType;
5
+ import com.stripe.stripeterminal.external.models.Location;
6
+ import com.stripe.stripeterminal.external.models.LocationStatus;
7
+ import com.stripe.stripeterminal.external.models.Reader;
8
+ import com.stripe.stripeterminal.external.models.ReaderSoftwareUpdate;
9
+
10
+ public class TerminalMappers {
11
+
12
+ public JSObject mapFromLocation(Location location) {
13
+ if (location == null) {
14
+ return new JSObject();
15
+ }
16
+
17
+ JSObject address = new JSObject();
18
+
19
+ if (location.getAddress() != null) {
20
+ address
21
+ .put("country", location.getAddress().getCountry())
22
+ .put("city", location.getAddress().getCity())
23
+ .put("postalCode", location.getAddress().getPostalCode())
24
+ .put("line1", location.getAddress().getLine1())
25
+ .put("line2", location.getAddress().getLine2())
26
+ .put("state", location.getAddress().getState());
27
+ }
28
+
29
+ return new JSObject()
30
+ .put("id", location.getId())
31
+ .put("displayName", location.getDisplayName())
32
+ .put("address", address)
33
+ .put("livemode", location.getLivemode());
34
+ }
35
+
36
+ public JSObject mapFromReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
37
+ if (update == null) {
38
+ return new JSObject();
39
+ }
40
+
41
+ return new JSObject()
42
+ .put("deviceSoftwareVersion", update.getVersion())
43
+ .put("estimatedUpdateTime", update.getTimeEstimate().toString())
44
+ .put("requiredAt", update.getRequiredAt().getTime());
45
+ }
46
+
47
+ public String mapFromLocationStatus(LocationStatus status) {
48
+ if (status == null) {
49
+ return "UNKNOWN";
50
+ }
51
+
52
+ return switch (status) {
53
+ case NOT_SET -> "NOT_SET";
54
+ case SET -> "SET";
55
+ case UNKNOWN -> "UNKNOWN";
56
+ default -> "UNKNOWN";
57
+ };
58
+ }
59
+
60
+ public String mapFromNetworkStatus(Reader.NetworkStatus status) {
61
+ if (status == null) {
62
+ return "unknown";
63
+ }
64
+
65
+ return switch (status) {
66
+ case OFFLINE -> "OFFLINE";
67
+ case ONLINE -> "ONLINE";
68
+ default -> "UNKNOWN";
69
+ };
70
+ }
71
+
72
+ public String mapFromDeviceType(DeviceType type) {
73
+ return switch (type) {
74
+ case CHIPPER_1X -> "chipper1X";
75
+ case CHIPPER_2X -> "chipper2X";
76
+ case COTS_DEVICE -> "cotsDevice";
77
+ case ETNA -> "etna";
78
+ case STRIPE_M2 -> "stripeM2";
79
+ case STRIPE_S700 -> "stripeS700";
80
+ case STRIPE_S700_DEVKIT -> "stripeS700Devkit";
81
+ // React Native has this model. deprecated?
82
+ // case STRIPE_S710:
83
+ // return "stripeS710";
84
+ // case STRIPE_S710_DEVKIT:
85
+ // return "stripeS710Devkit";
86
+ case UNKNOWN -> "unknown";
87
+ case VERIFONE_P400 -> "verifoneP400";
88
+ case WISECUBE -> "wiseCube";
89
+ case WISEPAD_3 -> "wisePad3";
90
+ case WISEPAD_3S -> "wisePad3s";
91
+ case WISEPOS_E -> "wisePosE";
92
+ case WISEPOS_E_DEVKIT -> "wisePosEDevkit";
93
+ default -> throw new IllegalArgumentException("Unknown DeviceType: " + type);
94
+ };
95
+ }
96
+ }