@haroldtran/react-native-pax 1.0.14 → 1.0.16

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.
@@ -70,29 +70,43 @@ class PaxPosLinkModule(
70
70
  timeout: Int?,
71
71
  promise: Promise,
72
72
  ) {
73
- val tcpSetting =
74
- TcpSetting().apply {
75
- this.ip = ip
76
- this.port = port ?: PaxPosConstant.PORT
77
- this.timeout = timeout ?: PaxPosConstant.TIMEOUT
73
+ Thread {
74
+ try {
75
+ val tcpSetting =
76
+ TcpSetting().apply {
77
+ this.ip = ip
78
+ this.port = port ?: PaxPosConstant.PORT
79
+ this.timeout = timeout ?: PaxPosConstant.TIMEOUT
80
+ }
81
+ val tcpSettingInfo = "=>: ip=$ip, port=${tcpSetting.port}, timeout=${tcpSetting.timeout}"
82
+ Log.i("TcpSetting", tcpSettingInfo)
83
+ val map = Arguments.createMap()
84
+ terminal = posLink?.getTerminal(reactContext, tcpSetting)
85
+ Log.e("terminal", terminal.toString())
86
+ if (terminal != null) {
87
+ val info = getTerminalInfo()
88
+ val serialNumber = info.getString("serialNumber") ?: ""
89
+ if (serialNumber.isEmpty()) {
90
+ Log.d("Failed Init", "Create terminal failed!")
91
+ promise.reject(
92
+ "Create terminal failed!",
93
+ tcpSettingInfo,
94
+ )
95
+ } else {
96
+ Log.d("Success Init", "Create terminal success")
97
+ map.putString("message", "Create terminal success! $tcpSettingInfo")
98
+ map.putBoolean("status", true)
99
+ map.putMap("serialNumber", info)
100
+ promise.resolve(map)
101
+ }
102
+ } else {
103
+ Log.d("Failed Init", "Create terminal failed!")
104
+ promise.reject("Create terminal failed!", tcpSettingInfo)
105
+ }
106
+ } catch (e: Exception) {
107
+ promise.reject("INIT_ERROR", e)
78
108
  }
79
- Log.i("TcpSetting", "tcpSetting info: ip=$ip, port=${tcpSetting.port}, timeout=${tcpSetting.timeout}")
80
- val map = Arguments.createMap()
81
-
82
- terminal = posLink?.getTerminal(reactContext, tcpSetting)
83
- Log.e("terminal", terminal.toString())
84
- 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)
90
- } else {
91
- Log.d("Failed Init", "Create terminal failed!")
92
- map.putString("message", "Create terminal failed!")
93
- map.putBoolean("status", false)
94
- promise.resolve(map)
95
- }
109
+ }.start()
96
110
  }
97
111
 
98
112
  @ReactMethod
@@ -551,17 +565,22 @@ class PaxPosLinkModule(
551
565
  // } else 0
552
566
  // }
553
567
 
554
- private fun getTerminalInfo(): WritableMap {
555
- val rs =
556
- terminal?.manage?.init()?.let {
568
+ private fun getTerminalInfo(): WritableMap =
569
+ try {
570
+ val initResult = terminal?.manage?.init()
571
+ val response = initResult?.response()
572
+ if (response == null) {
573
+ PaxTerminalInfoModel().toWritableMap()
574
+ } else {
557
575
  PaxTerminalInfoModel(
558
- serialNumber = it.response().sn(),
559
- modelName = it.response().modelName(),
560
- appName = it.response().appName(),
561
- )
576
+ serialNumber = response.sn().orEmpty(),
577
+ modelName = response.modelName().orEmpty(),
578
+ appName = response.appName().orEmpty(),
579
+ ).toWritableMap()
562
580
  }
563
- return rs?.toWritableMap() ?: PaxTerminalInfoModel().toWritableMap()
564
- }
581
+ } catch (e: Exception) {
582
+ PaxTerminalInfoModel().toWritableMap()
583
+ }
565
584
 
566
585
  private fun getAmountReq(transType: TransactionType?): AmountRequest =
567
586
  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.16",
4
4
  "description": "React Native native module for PAX devices",
5
5
  "main": "./src/index.ts",
6
6
  "files": [