Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlabo committed Aug 11, 2024
1 parent a9c6144 commit 65eb3f6
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ public void initialize(final PluginCall call) throws TerminalException {
TerminalListener listener = new TerminalListener() {
@Override
public void onUnexpectedReaderDisconnect(@NonNull Reader reader) {
notifyListeners(TerminalEnumEvent.UnexpectedReaderDisconnect.getWebEventName(), new JSObject().put("reader", convertReaderInterface(reader)));
notifyListeners(
TerminalEnumEvent.UnexpectedReaderDisconnect.getWebEventName(),
new JSObject().put("reader", convertReaderInterface(reader))
);
}

@Override
public void onConnectionStatusChange(@NonNull ConnectionStatus status) {
notifyListeners(TerminalEnumEvent.ConnectionStatusChange.getWebEventName(), new JSObject().put("status", status.toString()));
notifyListeners(
TerminalEnumEvent.ConnectionStatusChange.getWebEventName(),
new JSObject().put("status", status.toString())
);
}

@Override
Expand All @@ -132,11 +138,15 @@ public void setConnectionToken(PluginCall call) {

public void setSimulatorConfiguration(PluginCall call) {
try {
Terminal.getInstance().setSimulatorConfiguration(new SimulatorConfiguration(
SimulateReaderUpdate.valueOf(call.getString("update", "UPDATE_AVAILABLE")),
new SimulatedCard(SimulatedCardType.valueOf(call.getString("simulatedCard", "VISA"))),
call.getLong("simulatedTipAmount", null)
));
Terminal
.getInstance()
.setSimulatorConfiguration(
new SimulatorConfiguration(
SimulateReaderUpdate.valueOf(call.getString("update", "UPDATE_AVAILABLE")),
new SimulatedCard(SimulatedCardType.valueOf(call.getString("simulatedCard", "VISA"))),
call.getLong("simulatedTipAmount", null)
)
);

call.resolve();
} catch (Exception ex) {
Expand Down Expand Up @@ -466,7 +476,10 @@ private ReaderListener readerListener() {
@Override
public void onStartInstallingUpdate(@NotNull ReaderSoftwareUpdate update, @NotNull Cancelable cancelable) {
// Show UI communicating that a required update has started installing
notifyListeners(TerminalEnumEvent.StartInstallingUpdate.getWebEventName(), new JSObject().put("update", convertReaderSoftwareUpdate(update)));
notifyListeners(
TerminalEnumEvent.StartInstallingUpdate.getWebEventName(),
new JSObject().put("update", convertReaderSoftwareUpdate(update))
);
}

@Override
Expand All @@ -492,11 +505,10 @@ public void onFinishInstallingUpdate(@Nullable ReaderSoftwareUpdate update, @Nul

@Override
public void onBatteryLevelUpdate(float batteryLevel, @NonNull BatteryStatus batteryStatus, boolean isCharging) {
notifyListeners(TerminalEnumEvent.BatteryLevel.getWebEventName(), new JSObject()
.put("level", batteryLevel)
.put("charging", isCharging)
.put("status", batteryStatus.toString()
));
notifyListeners(
TerminalEnumEvent.BatteryLevel.getWebEventName(),
new JSObject().put("level", batteryLevel).put("charging", isCharging).put("status", batteryStatus.toString())
);
}

@Override
Expand All @@ -515,9 +527,9 @@ public void onReportReaderEvent(@NotNull ReaderEvent event) {

@Override
public void onRequestReaderDisplayMessage(@NotNull ReaderDisplayMessage message) {
notifyListeners(TerminalEnumEvent.RequestDisplayMessage.getWebEventName(), new JSObject()
.put("messageType", message.name())
.put("message", message.toString())
notifyListeners(
TerminalEnumEvent.RequestDisplayMessage.getWebEventName(),
new JSObject().put("messageType", message.name()).put("message", message.toString())
);
}

Expand All @@ -529,23 +541,20 @@ public void onRequestReaderInput(@NotNull ReaderInputOptions options) {
jsOptions.put(optionType.name());
}

notifyListeners(TerminalEnumEvent.RequestReaderInput.getWebEventName(), new JSObject()
.put("options", jsOptions)
.put("message", options.toString())
notifyListeners(
TerminalEnumEvent.RequestReaderInput.getWebEventName(),
new JSObject().put("options", jsOptions).put("message", options.toString())
);
}

public void onDisconnect(@NotNull DisconnectReason reason) {
notifyListeners(TerminalEnumEvent.DisconnectedReader.getWebEventName(), new JSObject()
.put("reason", reason.toString())
);
notifyListeners(TerminalEnumEvent.DisconnectedReader.getWebEventName(), new JSObject().put("reason", reason.toString()));
}
};
}

private JSObject convertReaderInterface(Reader reader) {
return new JSObject()
.put("serialNumber", reader.getSerialNumber());
return new JSObject().put("serialNumber", reader.getSerialNumber());
}

private JSObject convertReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.Manifest;
import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;
import com.getcapacitor.PermissionState;
import com.getcapacitor.Plugin;
Expand All @@ -13,7 +12,6 @@
import com.getcapacitor.annotation.Permission;
import com.getcapacitor.annotation.PermissionCallback;
import com.stripe.stripeterminal.external.models.TerminalException;

import java.util.Objects;

@RequiresApi(api = Build.VERSION_CODES.S)
Expand Down
59 changes: 29 additions & 30 deletions packages/terminal/ios/Plugin/StripeTerminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
call.reject("PaymentIntent not found for confirmPaymentIntent. Use collect method first and try again.")
}
}

public func setSimulatorConfiguration(_ call: CAPPluginCall) {
// { update?: SimulateReaderUpdate; simulatedCard?: SimulatedCardType; simulatedTipAmount?: number; }
Terminal.shared.simulatorConfiguration.availableReaderUpdate = self.mapToSimulateReaderUpdate(call.getString("update", "UPDATE_AVAILABLE"))
Terminal.shared.simulatorConfiguration.simulatedCard = SimulatedCard(type: SimulatedCardType(rawValue: self.mapToCardType(type: call.getString("simulatedCard", "VISA")))!);
Terminal.shared.simulatorConfiguration.simulatedCard = SimulatedCard(type: SimulatedCardType(rawValue: self.mapToCardType(type: call.getString("simulatedCard", "VISA")))!)
if let tipAmount = call.getInt("simulatedTipAmount") {
Terminal.shared.simulatorConfiguration.simulatedTipAmount = (tipAmount) as NSNumber;
Terminal.shared.simulatorConfiguration.simulatedTipAmount = (tipAmount) as NSNumber
}
call.resolve([:])
}

private func mapToSimulateReaderUpdate(_ update: String) -> SimulateReaderUpdate {
switch update {
case "UpdateAvailable": return SimulateReaderUpdate.available
Expand All @@ -261,7 +261,7 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
default: return SimulateReaderUpdate.none
}
}

private func mapToCardType(type: String) -> UInt {
switch type {
case "VISA": return 0
Expand Down Expand Up @@ -296,20 +296,20 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
return 0
}
}

/*
* Terminal
*/
public func terminal(_ terminal: Terminal, didChangePaymentStatus status: PaymentStatus) {
self.plugin?.notifyListeners(TerminalEvents.PaymentStatusChange.rawValue, data: ["status": status.rawValue])
}

public func terminal(_ terminal: Terminal, didChangeConnectionStatus status: ConnectionStatus) {
self.plugin?.notifyListeners(TerminalEvents.ConnectionStatusChange.rawValue, data: ["status": status.rawValue])
}

public func terminal(_ terminal: Terminal, didReportUnexpectedReaderDisconnect reader: Reader) {
self.plugin?.notifyListeners(TerminalEvents.UnexpectedReaderDisconnect.rawValue, data: ["reader":self.convertReaderInterface(reader: reader)])
self.plugin?.notifyListeners(TerminalEvents.UnexpectedReaderDisconnect.rawValue, data: ["reader": self.convertReaderInterface(reader: reader)])
}

/*
Expand All @@ -325,14 +325,14 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
}

public func localMobileReader(_ reader: Reader, didFinishInstallingUpdate update: ReaderSoftwareUpdate?, error: Error?) {
if ((error) != nil) {
if (error) != nil {
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
"error": error!.localizedDescription,
"error": error!.localizedDescription
])
return;
return
}
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
"update":self.convertReaderSoftwareUpdate(update: update!)
"update": self.convertReaderSoftwareUpdate(update: update!)
])
}

Expand All @@ -348,18 +348,17 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
if inputOptions.contains(.tapCard) {
readersJSObject.append(String(ReaderInputOptions.tapCard.rawValue))
}

self.plugin?.notifyListeners(TerminalEvents.RequestReaderInput.rawValue, data: ["options": [:], "message": inputOptions.rawValue])
}

public func localMobileReader(_ reader: Reader, didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage) {
self.plugin?.notifyListeners(TerminalEvents.RequestDisplayMessage.rawValue, data: [
"messageType": displayMessage.rawValue,
"message": displayMessage.rawValue,
"message": displayMessage.rawValue
])
}


/*
* bluetooth
*/
Expand All @@ -377,14 +376,14 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
}

public func reader(_: Reader, didFinishInstallingUpdate update: ReaderSoftwareUpdate?, error: Error?) {
if ((error) != nil) {
if (error) != nil {
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
"error": error!.localizedDescription,
"error": error!.localizedDescription
])
return;
return
}
self.plugin?.notifyListeners(TerminalEvents.FinishInstallingUpdate.rawValue, data: [
"update":self.convertReaderSoftwareUpdate(update: update!)
"update": self.convertReaderSoftwareUpdate(update: update!)
])
}

Expand All @@ -400,42 +399,42 @@ public class StripeTerminal: NSObject, DiscoveryDelegate, LocalMobileReaderDeleg
if inputOptions.contains(.tapCard) {
readersJSObject.append(String(ReaderInputOptions.tapCard.rawValue))
}

self.plugin?.notifyListeners(TerminalEvents.RequestReaderInput.rawValue, data: ["options": readersJSObject, "message": inputOptions.rawValue])
}

public func reader(_: Reader, didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage) {
self.plugin?.notifyListeners(TerminalEvents.RequestDisplayMessage.rawValue, data: [
"messageType": displayMessage.rawValue,
"message": displayMessage.rawValue,
"message": displayMessage.rawValue
])
}

public func reader(_ reader: Reader, didReportBatteryLevel batteryLevel: Float, status: BatteryStatus, isCharging: Bool) {
self.plugin?.notifyListeners(TerminalEvents.BatteryLevel.rawValue, data: [
"level": batteryLevel,
"charging": isCharging,
"status": status.rawValue
])
}
public func reader(_ reader: Reader, didReportReaderEvent event: ReaderEvent, info: [AnyHashable : Any]?) {

public func reader(_ reader: Reader, didReportReaderEvent event: ReaderEvent, info: [AnyHashable: Any]?) {
self.plugin?.notifyListeners(TerminalEvents.ReaderEvent.rawValue, data: [
"event": event.rawValue,
"event": event.rawValue
])
}

private func convertReaderInterface(reader: Reader) -> [String: String] {
return ["serialNumber": reader.serialNumber];
return ["serialNumber": reader.serialNumber]
}

private func convertReaderSoftwareUpdate(update: ReaderSoftwareUpdate) -> [String: String] {
return [
"version": update.deviceSoftwareVersion,
"settingsVersion": update.deviceSoftwareVersion,
"requiredAt": update.requiredAt.description,
"timeEstimate": String(update.estimatedUpdateTime.rawValue),
];
"timeEstimate": String(update.estimatedUpdateTime.rawValue)
]
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal/ios/Plugin/StripeTerminalPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class StripeTerminalPlugin: CAPPlugin {
call.reject("discoverReaders throw error.")
}
}

@objc func setSimulatorConfiguration(_ call: CAPPluginCall) {
self.implementation.setSimulatorConfiguration(call)
}
Expand Down
Loading

0 comments on commit 65eb3f6

Please sign in to comment.