@haroldtran/react-native-pax 1.0.14 → 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.
@@ -76,22 +76,31 @@ class PaxPosLinkModule(
76
76
  this.port = port ?: PaxPosConstant.PORT
77
77
  this.timeout = timeout ?: PaxPosConstant.TIMEOUT
78
78
  }
79
- Log.i("TcpSetting", "tcpSetting info: ip=$ip, port=${tcpSetting.port}, timeout=${tcpSetting.timeout}")
79
+ val tcpSettingInfo = "=>: ip=$ip, port=${tcpSetting.port}, timeout=${tcpSetting.timeout}"
80
+ Log.i("TcpSetting", tcpSettingInfo)
80
81
  val map = Arguments.createMap()
81
82
 
82
83
  terminal = posLink?.getTerminal(reactContext, tcpSetting)
83
84
  Log.e("terminal", terminal.toString())
84
85
  return if (terminal != null) {
85
- Log.d("Success Init", "Create terminal success")
86
- map.putString("message", "Create terminal success")
87
- map.putBoolean("status", true)
88
- map.putMap("serialNumber", getTerminalInfo())
89
- promise.resolve(map)
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
+ }
90
101
  } else {
91
102
  Log.d("Failed Init", "Create terminal failed!")
92
- map.putString("message", "Create terminal failed!")
93
- map.putBoolean("status", false)
94
- promise.resolve(map)
103
+ promise.reject("Create terminal failed!", tcpSettingInfo)
95
104
  }
96
105
  }
97
106
 
@@ -551,17 +560,22 @@ class PaxPosLinkModule(
551
560
  // } else 0
552
561
  // }
553
562
 
554
- private fun getTerminalInfo(): WritableMap {
555
- val rs =
556
- terminal?.manage?.init()?.let {
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 {
557
570
  PaxTerminalInfoModel(
558
- serialNumber = it.response().sn(),
559
- modelName = it.response().modelName(),
560
- appName = it.response().appName(),
561
- )
571
+ serialNumber = response.sn().orEmpty(),
572
+ modelName = response.modelName().orEmpty(),
573
+ appName = response.appName().orEmpty(),
574
+ ).toWritableMap()
562
575
  }
563
- return rs?.toWritableMap() ?: PaxTerminalInfoModel().toWritableMap()
564
- }
576
+ } catch (e: Exception) {
577
+ PaxTerminalInfoModel().toWritableMap()
578
+ }
565
579
 
566
580
  private fun getAmountReq(transType: TransactionType?): AmountRequest =
567
581
  AmountRequest().apply {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haroldtran/react-native-pax",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "React Native native module for PAX devices",
5
5
  "main": "./src/index.ts",
6
6
  "files": [