Skip to content

Commit

Permalink
feat(teminal): set device type
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlabo committed Aug 12, 2024
1 parent 1b294e0 commit adca78f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 50 deletions.
23 changes: 22 additions & 1 deletion packages/terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ addListener(eventName: TerminalEventsEnum.ReaderReconnectFailed, listenerFunc: (
#### ReaderInterface
<code>{ /** * The unique serial number is primary identifier inner plugin. */ serialNumber: string; label: string; batteryLevel: number; batteryStatus: <a href="#batterystatus">BatteryStatus</a>; simulated: boolean; id: number; availableUpdate: <a href="#readersoftwareupdateinterface">ReaderSoftwareUpdateInterface</a>; locationId: string; ipAddress: string; status: <a href="#networkstatus">NetworkStatus</a>; location: <a href="#locationinterface">LocationInterface</a>; locationStatus: <a href="#locationstatus">LocationStatus</a>; deviceType: string; // TODO enum deviceSoftwareVersion: string; // iOS only isCharging: number; // Android only baseUrl: string; // Android only bootloaderVersion: string; // Android only configVersion: string; // Android only emvKeyProfileId: string; // Android only firmwareVersion: string; // Android only hardwareVersion: string; // Android only macKeyProfileId: string; // Android only pinKeyProfileId: string; // Android only trackKeyProfileId: string; // Android only settingsVersion: string; // Android only pinKeysetId: string; /** * @deprecated This property has been deprecated and should use the `serialNumber` property. */ index?: number; }</code>
<code>{ /** * The unique serial number is primary identifier inner plugin. */ serialNumber: string; label: string; batteryLevel: number; batteryStatus: <a href="#batterystatus">BatteryStatus</a>; simulated: boolean; id: number; availableUpdate: <a href="#readersoftwareupdateinterface">ReaderSoftwareUpdateInterface</a>; locationId: string; ipAddress: string; status: <a href="#networkstatus">NetworkStatus</a>; location: <a href="#locationinterface">LocationInterface</a>; locationStatus: <a href="#locationstatus">LocationStatus</a>; deviceType: <a href="#devicetype">DeviceType</a>; deviceSoftwareVersion: string; /** * iOS Only properties. These properties are not available on Android. */ isCharging: number; /** * Android Only properties. These properties are not available on iOS. */ baseUrl: string; bootloaderVersion: string; configVersion: string; emvKeyProfileId: string; firmwareVersion: string; hardwareVersion: string; macKeyProfileId: string; pinKeyProfileId: string; trackKeyProfileId: string; settingsVersion: string; pinKeysetId: string; /** * @deprecated This property has been deprecated and should use the `serialNumber` property. */ index?: number; }</code>
#### ReaderSoftwareUpdateInterface
Expand Down Expand Up @@ -867,6 +867,27 @@ addListener(eventName: TerminalEventsEnum.ReaderReconnectFailed, listenerFunc: (
| **`Unknown`** | <code>'UNKNOWN'</code> |
#### DeviceType
| Members | Value |
| ---------------------- | ------------------------------- |
| **`cotsDevice`** | <code>"cotsDevice"</code> |
| **`wisePad3s`** | <code>"wisePad3s"</code> |
| **`appleBuiltIn`** | <code>"appleBuiltIn"</code> |
| **`chipper1X`** | <code>"chipper1X"</code> |
| **`chipper2X`** | <code>"chipper2X"</code> |
| **`etna`** | <code>"etna"</code> |
| **`stripeM2`** | <code>"stripeM2"</code> |
| **`stripeS700`** | <code>"stripeS700"</code> |
| **`stripeS700DevKit`** | <code>"stripeS700Devkit"</code> |
| **`verifoneP400`** | <code>"verifoneP400"</code> |
| **`wiseCube`** | <code>"wiseCube"</code> |
| **`wisePad3`** | <code>"wisePad3"</code> |
| **`wisePosE`** | <code>"wisePosE"</code> |
| **`wisePosEDevKit`** | <code>"wisePosEDevkit"</code> |
| **`unknown`** | <code>"unknown"</code> |
#### TerminalConnectTypes
| Members | Value |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public JSObject mapFromLocation(Location location) {

if (location.getAddress() != null) {
address
.put("country", location.getAddress().getCountry())
.put("city", location.getAddress().getCity())
.put("postalCode", location.getAddress().getPostalCode())
.put("line1", location.getAddress().getLine1())
.put("line2", location.getAddress().getLine2())
.put("state", location.getAddress().getState());
.put("country", location.getAddress().getCountry())
.put("city", location.getAddress().getCity())
.put("postalCode", location.getAddress().getPostalCode())
.put("line1", location.getAddress().getLine1())
.put("line2", location.getAddress().getLine2())
.put("state", location.getAddress().getState());
}

return new JSObject()
.put("id", location.getId())
.put("displayName", location.getDisplayName())
.put("address", address)
.put("livemode", location.getLivemode());
.put("id", location.getId())
.put("displayName", location.getDisplayName())
.put("address", address)
.put("livemode", location.getLivemode());
}

public JSObject mapFromReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
Expand All @@ -39,9 +39,9 @@ public JSObject mapFromReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
}

return new JSObject()
.put("deviceSoftwareVersion", update.getVersion())
.put("estimatedUpdateTime", update.getTimeEstimate().toString())
.put("requiredAt", update.getRequiredAt().getTime());
.put("deviceSoftwareVersion", update.getVersion())
.put("estimatedUpdateTime", update.getTimeEstimate().toString())
.put("requiredAt", update.getRequiredAt().getTime());
}

public String mapFromLocationStatus(LocationStatus status) {
Expand Down Expand Up @@ -70,42 +70,27 @@ public String mapFromNetworkStatus(Reader.NetworkStatus status) {
}

public String mapFromDeviceType(DeviceType type) {
switch (type) {
case CHIPPER_1X:
return "chipper1X";
case CHIPPER_2X:
return "chipper2X";
case COTS_DEVICE:
return "cotsDevice";
case ETNA:
return "etna";
case STRIPE_M2:
return "stripeM2";
case STRIPE_S700:
return "stripeS700";
case STRIPE_S700_DEVKIT:
return "stripeS700Devkit";
return switch (type) {
case CHIPPER_1X -> "chipper1X";
case CHIPPER_2X -> "chipper2X";
case COTS_DEVICE -> "cotsDevice";
case ETNA -> "etna";
case STRIPE_M2 -> "stripeM2";
case STRIPE_S700 -> "stripeS700";
case STRIPE_S700_DEVKIT -> "stripeS700Devkit";
// React Native has this model. deprecated?
// case STRIPE_S710:
// return "stripeS710";
// case STRIPE_S710_DEVKIT:
// return "stripeS710Devkit";
case UNKNOWN:
return "unknown";
case VERIFONE_P400:
return "verifoneP400";
case WISECUBE:
return "wiseCube";
case WISEPAD_3:
return "wisePad3";
case WISEPAD_3S:
return "wisePad3s";
case WISEPOS_E:
return "wisePosE";
case WISEPOS_E_DEVKIT:
return "wisePosEDevkit";
default:
throw new IllegalArgumentException("Unknown DeviceType: " + type);
}
case UNKNOWN -> "unknown";
case VERIFONE_P400 -> "verifoneP400";
case WISECUBE -> "wiseCube";
case WISEPAD_3 -> "wisePad3";
case WISEPAD_3S -> "wisePad3s";
case WISEPOS_E -> "wisePosE";
case WISEPOS_E_DEVKIT -> "wisePosEDevkit";
default -> throw new IllegalArgumentException("Unknown DeviceType: " + type);
};
}
}
10 changes: 6 additions & 4 deletions packages/terminal/src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PluginListenerHandle } from '@capacitor/core';

import type { TerminalEventsEnum } from './events.enum';
import {
import type {
TerminalConnectTypes,
UpdateTimeEstimate,
SimulateReaderUpdate,
Expand All @@ -12,7 +12,10 @@ import {
ReaderInputOption,
PaymentStatus,
DisconnectReason,
ConnectionStatus, NetworkStatus, LocationStatus,
ConnectionStatus,
NetworkStatus,
LocationStatus,
DeviceType,
} from './stripe.enum';

export type ReaderInterface = {
Expand All @@ -32,10 +35,9 @@ export type ReaderInterface = {
status: NetworkStatus;
location: LocationInterface;
locationStatus: LocationStatus;
deviceType: string; // TODO enum
deviceType: DeviceType;
deviceSoftwareVersion: string;


/**
* iOS Only properties. These properties are not available on Android.
*/
Expand Down
21 changes: 21 additions & 0 deletions packages/terminal/src/stripe.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ export enum TerminalConnectTypes {
TapToPay = 'tap-to-pay',
}

/**
* Note: Don't need to use this enum. It's just for reference.
*/
export enum DeviceType {
cotsDevice = 'cotsDevice',
wisePad3s = 'wisePad3s',
appleBuiltIn = 'appleBuiltIn',
chipper1X = 'chipper1X',
chipper2X = 'chipper2X',
etna = 'etna',
stripeM2 = 'stripeM2',
stripeS700 = 'stripeS700',
stripeS700DevKit = 'stripeS700Devkit',
verifoneP400 = 'verifoneP400',
wiseCube = 'wiseCube',
wisePad3 = 'wisePad3',
wisePosE = 'wisePosE',
wisePosEDevKit = 'wisePosEDevkit',
unknown = 'unknown',
}

export enum UpdateTimeEstimate {
LessThanOneMinute = 'LESS_THAN_ONE_MINUTE',
OneToTwoMinutes = 'ONE_TO_TWO_MINUTES',
Expand Down

0 comments on commit adca78f

Please sign in to comment.