@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.
@@ -5,7 +5,7 @@ import com.facebook.react.bridge.WritableMap
5
5
  object PaxPosConstant {
6
6
  const val DEFAULT_ID: String = ""
7
7
  const val PORT: String = "10009"
8
- const val TIMEOUT: Int = 300000
8
+ const val TIMEOUT: Int = 3000
9
9
  }
10
10
 
11
11
  // Data holder for PAX request parameters
@@ -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
- 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)
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
- Log.d("Success Init", "Create terminal success")
84
- map.putString("message", "Create terminal success")
85
- map.putBoolean("status", true)
86
- map.putMap("serialNumber", getTerminalInfo())
87
- 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
+ }
88
101
  } else {
89
102
  Log.d("Failed Init", "Create terminal failed!")
90
- map.putString("message", "Create terminal failed!")
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
- val rs =
554
- 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 {
555
570
  PaxTerminalInfoModel(
556
- serialNumber = it.response().sn(),
557
- modelName = it.response().modelName(),
558
- appName = it.response().appName(),
559
- )
571
+ serialNumber = response.sn().orEmpty(),
572
+ modelName = response.modelName().orEmpty(),
573
+ appName = response.appName().orEmpty(),
574
+ ).toWritableMap()
560
575
  }
561
- return rs?.toWritableMap() ?: PaxTerminalInfoModel().toWritableMap()
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haroldtran/react-native-pax",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "React Native native module for PAX devices",
5
5
  "main": "./src/index.ts",
6
6
  "files": [
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(ip: string): Promise<PaxInitModel> {
44
- return PaxPosLink.initPOSLink(ip);
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
  /**