react-native-mesmart 0.7.3 → 1.0.0

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.
Files changed (107) hide show
  1. package/README.md +110 -31
  2. package/android/build.gradle +15 -10
  3. package/android/gradle.properties +6 -5
  4. package/android/src/main/java/com/mesmart/Packages.kt +4 -2
  5. package/android/src/main/java/com/mesmart/Utils.kt +107 -0
  6. package/android/src/main/java/com/pax/PaxImpl.kt +71 -40
  7. package/android/src/main/java/com/pax/PaxModule.kt +52 -29
  8. package/android/src/main/java/com/paystore/PaystoreImpl.kt +53 -0
  9. package/android/src/main/java/com/paystore/PaystoreModule.kt +24 -28
  10. package/android/src/main/java/com/paystore/utils/CredentialsUtils.kt +6 -4
  11. package/android/src/main/java/com/plugpag/PlugpagImpl.kt +66 -45
  12. package/android/src/main/java/com/plugpag/PlugpagModule.kt +49 -39
  13. package/android/src/main/java/com/plugpag/utils/PlugpagUtils.kt +23 -24
  14. package/android/src/main/java/com/stone/StoneImpl.kt +270 -0
  15. package/android/src/main/java/com/stone/StoneModule.kt +121 -0
  16. package/android/src/main/java/com/stone/utils/StoneUtils.kt +282 -0
  17. package/android/src/main/java/com/stone/utils/TransactionObjectMapper.kt +200 -0
  18. package/android/src/main/java/com/sunmi/SunmiImpl.kt +36 -12
  19. package/android/src/main/java/com/sunmi/SunmiModule.kt +49 -36
  20. package/android/src/main/java/com/sunmi/helpers/SunmiPrintHelper.kt +13 -17
  21. package/android/src/main/java/com/sunmi/helpers/SunmiRfidHelper.kt +8 -8
  22. package/android/src/main/java/com/{mesmart → sunmi}/utils/ESCUtil.kt +1 -1
  23. package/lib/commonjs/@types/{index.js → index.d.js} +16 -5
  24. package/lib/commonjs/@types/index.d.js.map +1 -0
  25. package/lib/commonjs/@types/pax.d.js +2 -0
  26. package/lib/commonjs/@types/{pax.js.map → pax.d.js.map} +1 -1
  27. package/lib/commonjs/@types/paystore.d.js +2 -0
  28. package/lib/commonjs/@types/{paystore.js.map → paystore.d.js.map} +1 -1
  29. package/lib/commonjs/@types/plugpag.d.js +36 -0
  30. package/lib/commonjs/@types/plugpag.d.js.map +1 -0
  31. package/lib/commonjs/@types/stone.d.js +6 -0
  32. package/lib/commonjs/@types/{sunmi.js.map → stone.d.js.map} +1 -1
  33. package/lib/commonjs/@types/sunmi.d.js +2 -0
  34. package/lib/{module/@types/pax.js.map → commonjs/@types/sunmi.d.js.map} +1 -1
  35. package/lib/commonjs/index.js +39 -60
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/pax.js +25 -0
  38. package/lib/commonjs/pax.js.map +1 -0
  39. package/lib/commonjs/paystore.js +21 -0
  40. package/lib/commonjs/paystore.js.map +1 -0
  41. package/lib/commonjs/sunmi.js +28 -0
  42. package/lib/commonjs/sunmi.js.map +1 -0
  43. package/lib/module/@types/{index.js → index.d.js} +4 -2
  44. package/lib/module/@types/index.d.js.map +1 -0
  45. package/lib/module/@types/pax.d.js +2 -0
  46. package/lib/module/@types/{sunmi.js.map → pax.d.js.map} +1 -1
  47. package/lib/module/@types/paystore.d.js +2 -0
  48. package/lib/module/@types/paystore.d.js.map +1 -0
  49. package/lib/module/@types/plugpag.d.js +30 -0
  50. package/lib/module/@types/{plugpag.js.map → plugpag.d.js.map} +1 -1
  51. package/lib/module/@types/stone.d.js +2 -0
  52. package/lib/module/@types/stone.d.js.map +1 -0
  53. package/lib/module/@types/sunmi.d.js +2 -0
  54. package/lib/module/@types/sunmi.d.js.map +1 -0
  55. package/lib/module/index.js +39 -47
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/pax.js +18 -0
  58. package/lib/module/pax.js.map +1 -0
  59. package/lib/module/paystore.js +14 -0
  60. package/lib/module/paystore.js.map +1 -0
  61. package/lib/module/sunmi.js +21 -0
  62. package/lib/module/sunmi.js.map +1 -0
  63. package/lib/typescript/src/index.d.ts +37 -24
  64. package/lib/typescript/src/index.d.ts.map +1 -1
  65. package/lib/typescript/src/pax.d.ts +2 -0
  66. package/lib/typescript/src/pax.d.ts.map +1 -0
  67. package/lib/typescript/src/paystore.d.ts +3 -0
  68. package/lib/typescript/src/paystore.d.ts.map +1 -0
  69. package/lib/typescript/src/sunmi.d.ts +2 -0
  70. package/lib/typescript/src/sunmi.d.ts.map +1 -0
  71. package/package.json +1 -1
  72. package/src/@types/index.d.ts +29 -0
  73. package/src/@types/pax.d.ts +8 -0
  74. package/src/@types/{paystore.ts → paystore.d.ts} +4 -2
  75. package/src/@types/{plugpag.ts → plugpag.d.ts} +16 -23
  76. package/src/@types/stone.d.ts +310 -0
  77. package/src/@types/sunmi.d.ts +13 -0
  78. package/src/index.ts +41 -107
  79. package/src/pax.ts +28 -0
  80. package/src/paystore.ts +32 -0
  81. package/src/sunmi.ts +29 -0
  82. package/android/src/main/java/com/mesmart/utils/Utils.kt +0 -65
  83. package/lib/commonjs/@types/index.js.map +0 -1
  84. package/lib/commonjs/@types/pax.js +0 -2
  85. package/lib/commonjs/@types/paystore.js +0 -2
  86. package/lib/commonjs/@types/plugpag.js +0 -36
  87. package/lib/commonjs/@types/plugpag.js.map +0 -1
  88. package/lib/commonjs/@types/sunmi.js +0 -2
  89. package/lib/module/@types/index.js.map +0 -1
  90. package/lib/module/@types/pax.js +0 -2
  91. package/lib/module/@types/paystore.js +0 -2
  92. package/lib/module/@types/paystore.js.map +0 -1
  93. package/lib/module/@types/plugpag.js +0 -30
  94. package/lib/module/@types/sunmi.js +0 -2
  95. package/lib/typescript/src/@types/index.d.ts +0 -5
  96. package/lib/typescript/src/@types/index.d.ts.map +0 -1
  97. package/lib/typescript/src/@types/pax.d.ts +0 -7
  98. package/lib/typescript/src/@types/pax.d.ts.map +0 -1
  99. package/lib/typescript/src/@types/paystore.d.ts +0 -34
  100. package/lib/typescript/src/@types/paystore.d.ts.map +0 -1
  101. package/lib/typescript/src/@types/plugpag.d.ts +0 -47
  102. package/lib/typescript/src/@types/plugpag.d.ts.map +0 -1
  103. package/lib/typescript/src/@types/sunmi.d.ts +0 -9
  104. package/lib/typescript/src/@types/sunmi.d.ts.map +0 -1
  105. package/src/@types/index.ts +0 -4
  106. package/src/@types/pax.ts +0 -6
  107. package/src/@types/sunmi.ts +0 -13
package/README.md CHANGED
@@ -1,36 +1,41 @@
1
1
  # react-native-mesmart
2
2
 
3
- Native methods to integrate with Sunmi P2, Pax A910, Plugpag payment SDK and Paystore payment SDK.
3
+ Métodos nativos para integrar com POS Sunmi P2, Pax A910/A920, SDK de pagamento Plugpag da Pagbank, SDK de pagamento da Stone e SDK de pagamento da Paystore.
4
4
 
5
5
  - [Plugpag](https://developer.pagbank.com.br/v1.0/reference/smart-pos-introducao)
6
- - [Paystore](https://backendphoebus.paystore.com.br/portal/api/docs/sdk/android/index.html)
6
+ - [Stone](https://sdkandroid.stone.com.br/reference/overview-da-sdk)
7
+ - [Paystore](http://177.69.97.18:6655/)
7
8
 
8
- ## Installation
9
+ ## Instalação
9
10
 
10
11
  ```sh
11
12
  npm install react-native-mesmart
12
13
  ```
13
14
 
14
- OR
15
+ OU
15
16
 
16
17
  ```sh
17
18
  yarn add react-native-mesmart
18
19
  ```
19
20
 
20
- Add those lines below in your android/build.gradle
21
+ ## Configurações para Sunmi P2
22
+
23
+ Adicione a seguinte permissão no AndroidManifest do seu app
21
24
 
22
25
  ```
23
- allprojects {
24
- repositories {
25
- ...
26
- maven {
27
- url 'https://github.com/pagseguro/PlugPagServiceWrapper/raw/master'
28
- }
29
- }
30
- }
26
+ <uses-permission android:name="com.sunmi.perm.CONTACTLESS_CARD" />
31
27
  ```
32
28
 
33
- In your android/app/build.gradle, you must add those configs below
29
+ ## Configurações para Pax A910/A920
30
+
31
+ Adicione as seguintes permissões no AndroidManifest do seu app
32
+
33
+ ```
34
+ <uses-permission android:name="com.pax.permission.PICC" />
35
+ <uses-permission android:name="com.pax.permission.PRINTER" />
36
+ ```
37
+
38
+ Adicione essas configurações em android/app/build.gradle do seu app
34
39
 
35
40
  ```
36
41
  android {
@@ -48,46 +53,120 @@ android {
48
53
  }
49
54
  }
50
55
  }
56
+ ```
51
57
 
52
- dependencies {
53
- ...
54
- implementation fileTree(dir: 'libs', include: ['*.aar'])
58
+ Crie um diretório android/app/src/main/jniLibs/armeabi-v7 e adicione o arquivo 'libDeviceConfig.so' que está presente no exemplo dessa biblioteca
59
+
60
+ ## Configurações para SDK Plugpag
61
+
62
+ Adicione a seguinte permissão no AndroidManifest do seu app
63
+
64
+ ```
65
+ <uses-permission android:name="br.com.uol.pagseguro.permission.MANAGE_PAYMENTS" />
66
+ ```
67
+
68
+ Adicione essa configuração em android/build.gradle do seu app
69
+
70
+ ```
71
+ allprojects {
72
+ repositories {
73
+ ...
74
+ maven {
75
+ url 'https://github.com/pagseguro/PlugPagServiceWrapper/raw/master'
76
+ }
77
+ }
55
78
  }
56
79
  ```
57
80
 
58
- Create a new directory at android/app/src/main/jniLibs/armeabi-v7a and add the file 'libDeviceConfig.so' to this new folder
81
+ ## Configurações para SDK Stone
59
82
 
60
- Create a new directory at android/app/libs/ and add the file 'paystore-api-v2.11.3.24.aar' to this new folder
83
+ Adicione as seguintes configurações no AndroidManifest do seu app
61
84
 
62
- ## Permissions
85
+ ```
86
+ <manifest
87
+ ...
88
+ xmlns:tools="http://schemas.android.com/tools"
89
+ >
90
+ ...
91
+ <application
92
+ ...
93
+ android:allowBackup="true"
94
+ tools:replace="android:allowBackup"
95
+ >
96
+ ...
97
+ </application>
98
+ </manifest>
99
+ ```
63
100
 
64
- Add those permissions in your AndroidManifest.xml
101
+ Adicione essas configurações em android/build.gradle do seu app
102
+
103
+ ```
104
+ buildscript {
105
+ ext {
106
+ ...
107
+ localProp = new Properties()
108
+ fileName = 'local.properties'
109
+ localProp.load(new FileInputStream(rootProject.file(fileName)))
110
+ stoneToken = System.env.PACKAGECLOUD_READ_TOKEN != null ? System.env.PACKAGECLOUD_READ_TOKEN : (localProp["packageCloudReadToken"] ?: "")
111
+ }
112
+ }
113
+
114
+ allprojects {
115
+ repositories {
116
+ ...
117
+ maven { url "https://packagecloud.io/priv/${stoneToken}/stone/pos-android/maven2" }
118
+ }
119
+ }
120
+ ```
121
+
122
+ Lembre-se de adicionar no arquivo local.properties do diretório android do seu app o valor packageCloudReadToken com sua chave ofericida pela Stone
123
+
124
+ ## Configurações para SDK Paystore
125
+
126
+ Adicione a seguinte permissão no AndroidManifest do seu app
65
127
 
66
128
  ```
67
- <uses-permission android:name="com.sunmi.perm.CONTACTLESS_CARD" />
68
- <uses-permission android:name="br.com.uol.pagseguro.permission.MANAGE_PAYMENTS" />
69
- <uses-permission android:name="com.pax.permission.PICC" />
70
- <uses-permission android:name="com.pax.permission.PRINTER" />
71
129
  <uses-permission android:name="br.com.phoebus.android.payments.provider.READ_PERMISSION" />
72
130
  ```
73
131
 
74
- ## Usage
132
+ Adicione essa configuração em android/app/build.gradle do seu app
133
+
134
+ ```
135
+ dependencies {
136
+ ...
137
+ implementation fileTree(dir: 'libs', include: ['*.aar'])
138
+ }
139
+ ```
140
+
141
+ Crie um diretório android/app/libs e adicione o arquivo 'paystore-api-v2.11.7.31.aar' que está presente no exemplo dessa biblioteca
142
+
143
+ ## Listeners
75
144
 
76
145
  ```ts
77
146
  import { DeviceEventEmitter } from 'react-native';
78
- import { Sunmi, Plugpag, Pax, Paystore } from 'react-native-mesmart';
147
+ import {
148
+ type PlugpagEventData,
149
+ type StoneEventData,
150
+ } from 'react-native-mesmart';
79
151
 
80
- // Register event listener to catch onPlugPagEventData
81
152
  useEffect(() => {
82
- const subscribe = DeviceEventEmitter.addListener(
83
- 'onPlugPagEventData',
153
+ const plugpagSubscribe = DeviceEventEmitter.addListener(
154
+ 'onPlugpagEventData',
84
155
  (plugpagEvent: PlugPagEventData) => {
85
156
  console.log(plugpagEvent);
86
157
  }
87
158
  );
88
159
 
160
+ const stoneSubscribe = DeviceEventEmitter.addListener(
161
+ 'onStoneEventData',
162
+ (event: StoneEventData) => {
163
+ console.log(event);
164
+ }
165
+ );
166
+
89
167
  return () => {
90
- subscribe.remove();
168
+ plugpagSubscribe.remove();
169
+ stoneSubscribe.remove();
91
170
  };
92
171
  }, []);
93
172
  ```
@@ -2,7 +2,7 @@ import com.android.Version
2
2
 
3
3
  buildscript {
4
4
  // Buildscript is evaluated before everything else so we can't use getExtOrDefault
5
- def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Plugpag_kotlinVersion"]
5
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["kotlinVersion"]
6
6
 
7
7
  repositories {
8
8
  google()
@@ -27,11 +27,11 @@ if (isNewArchitectureEnabled()) {
27
27
  }
28
28
 
29
29
  def getExtOrDefault(name) {
30
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Plugpag_" + name]
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties[name]
31
31
  }
32
32
 
33
33
  def getExtOrIntegerDefault(name) {
34
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Plugpag_" + name]).toInteger()
34
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[name]).toInteger()
35
35
  }
36
36
 
37
37
  static def supportsNamespace() {
@@ -84,11 +84,15 @@ android {
84
84
  }
85
85
 
86
86
  repositories {
87
+ def localProp = new Properties()
88
+ def fileName = 'local.properties'
89
+ localProp.load(new FileInputStream(rootProject.file(fileName)))
90
+ def stoneToken = System.env.PACKAGECLOUD_READ_TOKEN != null ? System.env.PACKAGECLOUD_READ_TOKEN : localProp["packageCloudReadToken"] ?: ""
91
+
87
92
  mavenCentral()
88
93
  google()
89
- // if you open in Android Studio uncomment the line below to code using Plugpag library
90
- // but leave it commented cause it needs to be imported in the main project
91
- // maven { url 'https://github.com/pagseguro/PlugPagServiceWrapper/raw/master' }
94
+ maven { url 'https://github.com/pagseguro/PlugPagServiceWrapper/raw/master' }
95
+ maven { url "https://packagecloud.io/priv/${stoneToken}/stone/pos-android/maven2" }
92
96
  }
93
97
 
94
98
  def kotlin_version = getExtOrDefault("kotlinVersion")
@@ -97,14 +101,15 @@ dependencies {
97
101
  implementation fileTree(dir: 'libs', include: ['*.jar'])
98
102
  implementation "com.facebook.react:react-android:0.75.0-rc.5"
99
103
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
100
- implementation "com.sunmi:PayLib-release:2.0.07"
101
104
  implementation "br.com.uol.pagseguro.plugpagservice.wrapper:wrapper:1.28.2"
102
- implementation "com.sunmi:printerlibrary:1.0.23"
103
105
  implementation "com.google.code.gson:gson:2.10.1"
106
+ implementation "br.com.stone:stone-sdk:$stone_sdk_version"
107
+ implementation "br.com.stone:stone-sdk-posandroid:$stone_sdk_version"
108
+ implementation "br.com.stone:stone-sdk-posandroid-sunmi:$stone_sdk_version"
104
109
  compileOnly(
105
- name: "paystore-api-v2.11.3.24",
110
+ name: "paystore-api-v2.11.7.31",
106
111
  ext: "aar",
107
- version: "v2.11.3.24",
112
+ version: "v2.11.7.31",
108
113
  group: "paystore"
109
114
  )
110
115
  }
@@ -11,9 +11,10 @@
11
11
  # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
12
12
  # org.gradle.parallel=true
13
13
  #Fri Jul 19 11:34:20 BRT 2024
14
- Plugpag_compileSdkVersion=31
15
- Plugpag_kotlinVersion=1.9.24
16
- Plugpag_minSdkVersion=23
17
- Plugpag_ndkversion=21.4.7075529
18
- Plugpag_targetSdkVersion=31
14
+ compileSdkVersion=android-31
15
+ kotlinVersion=1.9.24
16
+ minSdkVersion=23
17
+ ndkversion=21.4.7075529
18
+ targetSdkVersion=31
19
+ stone_sdk_version=4.9.5
19
20
  android.useAndroidX=true
@@ -7,15 +7,17 @@ import com.facebook.react.uimanager.ViewManager
7
7
  import com.pax.PaxModule
8
8
  import com.paystore.PaystoreModule
9
9
  import com.plugpag.PlugpagModule
10
+ import com.stone.StoneModule
10
11
  import com.sunmi.SunmiModule
11
12
 
12
13
  class Packages : ReactPackage {
13
14
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
14
15
  return listOf(
15
- PlugpagModule(reactContext),
16
16
  SunmiModule(reactContext),
17
+ PlugpagModule(reactContext),
17
18
  PaxModule(reactContext),
18
- PaystoreModule(reactContext)
19
+ PaystoreModule(reactContext),
20
+ StoneModule(reactContext)
19
21
  )
20
22
  }
21
23
 
@@ -0,0 +1,107 @@
1
+ package com.mesmart
2
+
3
+ import android.graphics.Bitmap
4
+ import android.graphics.BitmapFactory
5
+ import android.os.Build
6
+ import android.util.Base64
7
+ import java.text.SimpleDateFormat
8
+ import java.util.Date
9
+ import java.util.Locale
10
+
11
+ object Utils {
12
+ fun isSunmiP2(): Boolean {
13
+ return Build.MODEL.equals("P2-B", true)
14
+ }
15
+
16
+ fun isA910(): Boolean {
17
+ return Build.MODEL.equals("A910", true)
18
+ }
19
+
20
+ fun resolveRFID(value: String): String {
21
+ val length = value.length
22
+
23
+ val n = StringBuilder()
24
+ n.append(value.substring(0, 2)).append("-")
25
+
26
+ if (length >= 4) {
27
+ n.append(value.substring(2, 4))
28
+ if (length > 4) n.append("-")
29
+ }
30
+
31
+ if (length >= 6) {
32
+ n.append(value.substring(4, 6))
33
+ if (length > 6) n.append("-")
34
+ }
35
+
36
+ if (length >= 8) {
37
+ n.append(value.substring(6, 8))
38
+ if (length > 8) n.append("-")
39
+ }
40
+
41
+ if (length >= 10) {
42
+ n.append(value.substring(6, 10))
43
+ }
44
+
45
+ val split = n.toString().split("-")
46
+ val splitSize = split.size
47
+ val nova = StringBuilder()
48
+
49
+ when (splitSize) {
50
+ 4 -> nova.append(split[3]).append(split[2]).append(split[1]).append(split[0])
51
+ 3 -> nova.append(split[2]).append(split[1]).append(split[0])
52
+ 2 -> nova.append(split[1]).append(split[0])
53
+ else -> {}
54
+ }
55
+
56
+ val hexResult = nova.toString()
57
+ val converted = hexResult.toLong(16)
58
+
59
+ var id = converted.toString()
60
+
61
+ if (id.length < 10) {
62
+ id = "0$converted"
63
+ if (id.length < 10) id = "00$converted"
64
+ if (id.length < 10) id = "000$converted"
65
+ }
66
+
67
+ return id
68
+ }
69
+
70
+ fun convertStringToBitmap(data: String?): Bitmap? {
71
+ return try {
72
+ data?.let {
73
+ val decodedBytes = Base64.decode(it, Base64.DEFAULT)
74
+ BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.size)
75
+ }
76
+ } catch (e: Exception) {
77
+ e.printStackTrace()
78
+ null
79
+ }
80
+ }
81
+
82
+ fun convertStringToDate(dateString: String?): Date? {
83
+ return try {
84
+ val format = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
85
+ dateString?.let { format.parse(it) }
86
+ } catch (e: Exception) {
87
+ e.printStackTrace()
88
+ null
89
+ }
90
+ }
91
+
92
+ fun bitmapToBase64(bitmap: Bitmap?): String? {
93
+ return bitmap?.let {
94
+ val outputStream = java.io.ByteArrayOutputStream()
95
+ it.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
96
+ val byteArray = outputStream.toByteArray()
97
+ Base64.encodeToString(byteArray, Base64.DEFAULT)
98
+ }
99
+ }
100
+
101
+ fun dateToString(date: Date?): String? {
102
+ return date?.let {
103
+ val format = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
104
+ format.format(it)
105
+ }
106
+ }
107
+ }
@@ -7,7 +7,7 @@ import android.os.Looper
7
7
  import com.facebook.react.bridge.Promise
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.mesmart.R
10
- import com.mesmart.utils.Utils
10
+ import com.mesmart.Utils
11
11
  import com.pax.dal.IPicc
12
12
  import com.pax.dal.IPrinter
13
13
  import com.pax.dal.entity.EDetectMode
@@ -21,70 +21,102 @@ import com.pax.utils.PaxConverter
21
21
  class PaxImpl(
22
22
  private val reactContext: ReactApplicationContext
23
23
  ) {
24
- private val picc: IPicc = NeptuneLiteUser
25
- .getInstance()
26
- .getDal(reactContext)
27
- .getPicc(EPiccType.INTERNAL)
28
- private val printer: IPrinter = NeptuneLiteUser
29
- .getInstance()
30
- .getDal(reactContext)
31
- .printer
24
+ private var picc: IPicc? = null
25
+ private var printer: IPrinter? = null
32
26
  private val handler = Handler(Looper.getMainLooper())
33
27
  private var isSearchingCard = false
34
28
 
35
- fun searchRfid(promise: Promise) {
29
+ init {
30
+ if (Utils.isA910()) {
31
+ picc = NeptuneLiteUser
32
+ .getInstance()
33
+ .getDal(reactContext)
34
+ .getPicc(EPiccType.INTERNAL)
35
+ printer = NeptuneLiteUser
36
+ .getInstance()
37
+ .getDal(reactContext)
38
+ .printer
39
+ PaxConverter.instance?.setContext(reactContext)
40
+ }
41
+ }
42
+
43
+ private fun checkPax(instance: String) {
44
+ if (instance == "picc" && picc == null)
45
+ throw Exception("Picc da Pax não foi inicializado! Você deve utilizar esse método em um dispositivo Pax A910 ou ocorreu algum erro durante a inicialização!")
46
+ if (instance == "printer" && printer == null)
47
+ throw Exception("Printer da Pax não foi inicializado! Você deve utilizar esse método em um dispositivo Pax A910 ou ocorreu algum erro durante a inicialização!")
48
+ }
49
+
50
+ fun scanRfid(promise: Promise) {
51
+ checkPax("picc")
52
+
36
53
  isSearchingCard = true
37
54
  val timeoutRunnable = Runnable {
38
55
  if (isSearchingCard) {
39
56
  isSearchingCard = false
40
- promise.reject("TimeoutException", "Card not found within 30 seconds!")
57
+ promise.reject("Nenhum RFID encontrado em 30 segundos!")
41
58
  }
42
59
  }
43
60
 
44
61
  handler.postDelayed(timeoutRunnable, 30000)
45
62
 
46
63
  Thread {
47
- while (isSearchingCard) {
48
- picc.open()
49
- val cardInfo: PiccCardInfo? = picc.detect(EDetectMode.ONLY_M)
50
- if (cardInfo != null) {
51
- handler.removeCallbacks(timeoutRunnable)
52
- isSearchingCard = false
53
- promise.resolve(
54
- PaxConverter.instance?.bcdToStr(
55
- if ((cardInfo.serialInfo == null)) "".toByteArray()
56
- else cardInfo.serialInfo
57
- )?.let {
58
- Utils.resolveRFID(it)
59
- }
60
- )
61
- return@Thread
64
+ try {
65
+ while (isSearchingCard) {
66
+ picc?.open()
67
+ val cardInfo: PiccCardInfo? = picc?.detect(EDetectMode.ONLY_M)
68
+ if (cardInfo != null) {
69
+ handler.removeCallbacks(timeoutRunnable)
70
+ isSearchingCard = false
71
+ promise.resolve(
72
+ PaxConverter.instance?.bcdToStr(
73
+ if ((cardInfo.serialInfo == null)) "".toByteArray()
74
+ else cardInfo.serialInfo
75
+ )?.let {
76
+ Utils.resolveRFID(it)
77
+ }
78
+ )
79
+ return@Thread
80
+ }
81
+ picc?.close()
82
+ Thread.sleep(100)
62
83
  }
63
- picc.close()
64
- Thread.sleep(100)
84
+ } catch (e: Exception) {
85
+ e.printStackTrace()
86
+ promise.reject(e)
65
87
  }
66
88
  }.start()
67
89
  }
68
90
 
69
- fun cancelCardSearch() {
91
+ fun cancelScan() {
92
+ checkPax("picc")
70
93
  isSearchingCard = false
71
94
  handler.removeCallbacksAndMessages(null)
72
95
  }
73
96
 
74
- fun printText(
97
+ fun printerInit() {
98
+ checkPax("printer")
99
+ printer?.init()
100
+ }
101
+
102
+ fun printerStart() {
103
+ checkPax("printer")
104
+ printer?.start()
105
+ }
106
+
107
+ fun addText(
75
108
  str: String,
76
109
  fontSize: Int
77
110
  ) {
78
- printer.init()
79
- printer.spaceSet(0, 0)
80
- if (fontSize == 20) printer.fontSet(EFontTypeAscii.FONT_8_32, EFontTypeExtCode.FONT_16_16)
81
- else printer.fontSet(EFontTypeAscii.FONT_12_24, EFontTypeExtCode.FONT_16_16)
82
- printer.printStr(str, null)
83
- printer.start()
111
+ checkPax("printer")
112
+ printer?.spaceSet(0, 0)
113
+ if (fontSize == 20) printer?.fontSet(EFontTypeAscii.FONT_8_32, EFontTypeExtCode.FONT_16_16)
114
+ else printer?.fontSet(EFontTypeAscii.FONT_12_24, EFontTypeExtCode.FONT_16_16)
115
+ printer?.printStr(str, null)
84
116
  }
85
117
 
86
- fun printBpLogo() {
87
- printer.init()
118
+ fun addBpLogo() {
119
+ checkPax("printer")
88
120
  val options = BitmapFactory.Options().apply {
89
121
  inTargetDensity = 160
90
122
  inDensity = 160
@@ -94,9 +126,8 @@ class PaxImpl(
94
126
  R.drawable.logo_black,
95
127
  options
96
128
  )
97
- printer.printBitmap(
129
+ printer?.printBitmap(
98
130
  Bitmap.createScaledBitmap(bitmap, 375, 100, true)
99
131
  )
100
- printer.start()
101
132
  }
102
133
  }
@@ -4,59 +4,82 @@ import com.facebook.react.bridge.Promise
4
4
  import com.facebook.react.bridge.ReactApplicationContext
5
5
  import com.facebook.react.bridge.ReactContextBaseJavaModule
6
6
  import com.facebook.react.bridge.ReactMethod
7
- import com.mesmart.utils.Utils
8
- import com.pax.utils.PaxConverter
9
7
 
10
8
  class PaxModule(
11
9
  reactContext: ReactApplicationContext
12
10
  ) : ReactContextBaseJavaModule(reactContext) {
13
- var pax: PaxImpl? = null
14
-
15
- init {
16
- if (Utils.isA910()) {
17
- pax = PaxImpl(reactContext)
18
- PaxConverter.instance?.setContext(reactContext)
19
- }
20
- }
11
+ private var pax = PaxImpl(reactContext)
21
12
 
22
13
  override fun getName(): String {
23
14
  return "Pax"
24
15
  }
25
16
 
26
- private fun checkPax() {
27
- if (pax == null)
28
- throw Exception("Pax is null! You may not working in a Pax A910 or an error ocurred during the initialization!")
17
+ @ReactMethod
18
+ fun scanRfid(promise: Promise) {
19
+ try {
20
+ pax.scanRfid(promise)
21
+ } catch (e: Exception) {
22
+ e.printStackTrace()
23
+ promise.reject(e)
24
+ }
29
25
  }
30
26
 
31
27
  @ReactMethod
32
- fun searchRfid(promise: Promise) {
28
+ fun cancelScan(promise: Promise) {
33
29
  try {
34
- checkPax()
35
- pax?.searchRfid(promise)
30
+ pax.cancelScan()
31
+ promise.resolve(null)
36
32
  } catch (e: Exception) {
37
33
  e.printStackTrace()
38
34
  promise.reject(e)
39
35
  }
40
36
  }
41
37
 
42
- @ReactMethod(isBlockingSynchronousMethod = true)
43
- fun cancelCardSearch() {
44
- checkPax()
45
- pax?.cancelCardSearch()
38
+ @ReactMethod
39
+ fun printerInit(promise: Promise) {
40
+ try {
41
+ pax.printerInit()
42
+ promise.resolve(null)
43
+ } catch (e: Exception) {
44
+ e.printStackTrace()
45
+ promise.reject(e)
46
+ }
46
47
  }
47
48
 
48
- @ReactMethod(isBlockingSynchronousMethod = true)
49
- fun printText(
49
+ @ReactMethod
50
+ fun printerStart(promise: Promise) {
51
+ try {
52
+ pax.printerStart()
53
+ promise.resolve(null)
54
+ } catch (e: Exception) {
55
+ e.printStackTrace()
56
+ promise.reject(e)
57
+ }
58
+ }
59
+
60
+ @ReactMethod
61
+ fun addText(
50
62
  str: String,
51
- fontSize: Int
63
+ fontSize: Int,
64
+ promise: Promise
52
65
  ) {
53
- checkPax()
54
- pax?.printText(str, fontSize)
66
+ try {
67
+ pax.addText(str, fontSize)
68
+ promise.resolve(null)
69
+ } catch (e: Exception) {
70
+ e.printStackTrace()
71
+ promise.reject(e)
72
+ }
55
73
  }
56
74
 
57
- @ReactMethod(isBlockingSynchronousMethod = true)
58
- fun printBpLogo() {
59
- checkPax()
60
- pax?.printBpLogo()
75
+ @ReactMethod
76
+ fun addBpLogo(promise: Promise) {
77
+ try {
78
+ pax.addBpLogo()
79
+ promise.resolve(null)
80
+ } catch (e: Exception) {
81
+ e.printStackTrace()
82
+ promise.reject(e)
83
+ }
61
84
  }
62
85
  }