@haroldtran/react-native-pax 1.0.13 → 1.0.15
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.
|
@@ -66,30 +66,41 @@ class PaxPosLinkModule(
|
|
|
66
66
|
@ReactMethod
|
|
67
67
|
fun initPOSLink(
|
|
68
68
|
ip: String,
|
|
69
|
+
port: String?,
|
|
70
|
+
timeout: Int?,
|
|
69
71
|
promise: Promise,
|
|
70
72
|
) {
|
|
71
73
|
val tcpSetting =
|
|
72
74
|
TcpSetting().apply {
|
|
73
75
|
this.ip = ip
|
|
74
|
-
this.port = PaxPosConstant.PORT
|
|
75
|
-
this.timeout = PaxPosConstant.TIMEOUT
|
|
76
|
+
this.port = port ?: PaxPosConstant.PORT
|
|
77
|
+
this.timeout = timeout ?: PaxPosConstant.TIMEOUT
|
|
76
78
|
}
|
|
77
|
-
|
|
79
|
+
val tcpSettingInfo = "=>: ip=$ip, port=${tcpSetting.port}, timeout=${tcpSetting.timeout}"
|
|
80
|
+
Log.i("TcpSetting", tcpSettingInfo)
|
|
78
81
|
val map = Arguments.createMap()
|
|
79
82
|
|
|
80
83
|
terminal = posLink?.getTerminal(reactContext, tcpSetting)
|
|
81
84
|
Log.e("terminal", terminal.toString())
|
|
82
85
|
return if (terminal != null) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
val info = getTerminalInfo()
|
|
87
|
+
val serialNumber = info.getString("serialNumber") ?: ""
|
|
88
|
+
if (serialNumber.isEmpty()) {
|
|
89
|
+
Log.d("Failed Init", "Create terminal failed!")
|
|
90
|
+
promise.reject(
|
|
91
|
+
"Create terminal failed!",
|
|
92
|
+
tcpSettingInfo,
|
|
93
|
+
)
|
|
94
|
+
} else {
|
|
95
|
+
Log.d("Success Init", "Create terminal success")
|
|
96
|
+
map.putString("message", "Create terminal success! $tcpSettingInfo")
|
|
97
|
+
map.putBoolean("status", true)
|
|
98
|
+
map.putMap("serialNumber", info)
|
|
99
|
+
promise.resolve(map)
|
|
100
|
+
}
|
|
88
101
|
} else {
|
|
89
102
|
Log.d("Failed Init", "Create terminal failed!")
|
|
90
|
-
|
|
91
|
-
map.putBoolean("status", false)
|
|
92
|
-
promise.resolve(map)
|
|
103
|
+
promise.reject("Create terminal failed!", tcpSettingInfo)
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
|
|
@@ -549,17 +560,22 @@ class PaxPosLinkModule(
|
|
|
549
560
|
// } else 0
|
|
550
561
|
// }
|
|
551
562
|
|
|
552
|
-
private fun getTerminalInfo(): WritableMap
|
|
553
|
-
|
|
554
|
-
terminal?.manage?.init()
|
|
563
|
+
private fun getTerminalInfo(): WritableMap =
|
|
564
|
+
try {
|
|
565
|
+
val initResult = terminal?.manage?.init()
|
|
566
|
+
val response = initResult?.response()
|
|
567
|
+
if (response == null) {
|
|
568
|
+
PaxTerminalInfoModel().toWritableMap()
|
|
569
|
+
} else {
|
|
555
570
|
PaxTerminalInfoModel(
|
|
556
|
-
serialNumber =
|
|
557
|
-
modelName =
|
|
558
|
-
appName =
|
|
559
|
-
)
|
|
571
|
+
serialNumber = response.sn().orEmpty(),
|
|
572
|
+
modelName = response.modelName().orEmpty(),
|
|
573
|
+
appName = response.appName().orEmpty(),
|
|
574
|
+
).toWritableMap()
|
|
560
575
|
}
|
|
561
|
-
|
|
562
|
-
|
|
576
|
+
} catch (e: Exception) {
|
|
577
|
+
PaxTerminalInfoModel().toWritableMap()
|
|
578
|
+
}
|
|
563
579
|
|
|
564
580
|
private fun getAmountReq(transType: TransactionType?): AmountRequest =
|
|
565
581
|
AmountRequest().apply {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,10 +38,16 @@ const PaxPosLink = isAndroid
|
|
|
38
38
|
/**
|
|
39
39
|
* Initializes the POSLink connection.
|
|
40
40
|
* @param {string} [ip] - The IP address of the POS device.
|
|
41
|
+
* @param {object} [options] - Optional parameters.
|
|
42
|
+
* @param {string} [options.port] - The port number of the POS device.
|
|
43
|
+
* @param {number} [options.timeout] - The timeout value for the connection.
|
|
41
44
|
* @returns {Promise<PaxInitModel>} A promise resolving to the initPOSLink result.
|
|
42
45
|
*/
|
|
43
|
-
export function initPOSLink(
|
|
44
|
-
|
|
46
|
+
export function initPOSLink(
|
|
47
|
+
ip: string,
|
|
48
|
+
options?: { port?: string; timeout?: number }
|
|
49
|
+
): Promise<PaxInitModel> {
|
|
50
|
+
return PaxPosLink.initPOSLink(ip, options?.port, options?.timeout);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|