react-native-mesmart 0.5.0 → 0.6.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.
- package/README.md +39 -56
- package/android/build.gradle +4 -3
- package/android/libs/NeptuneLiteApi_V4.08.00_20240701.jar +0 -0
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/mesmart/Packages.kt +3 -1
- package/android/src/main/java/com/{sunmi → mesmart}/utils/ESCUtil.kt +1 -1
- package/android/src/main/java/com/{sunmi/utils/SunmiUtils.kt → mesmart/utils/Utils.kt} +7 -3
- package/android/src/main/java/com/pax/PaxImpl.kt +102 -0
- package/android/src/main/java/com/pax/PaxModule.kt +62 -0
- package/android/src/main/java/com/pax/utils/PaxConverter.kt +505 -0
- package/android/src/main/java/com/plugpag/PlugpagModule.kt +5 -5
- package/android/src/main/java/com/sunmi/SunmiImpl.kt +2 -2
- package/android/src/main/java/com/sunmi/SunmiModule.kt +8 -8
- package/android/src/main/java/com/sunmi/{utils → helpers}/SunmiPrintHelper.kt +2 -1
- package/android/src/main/java/com/sunmi/{utils → helpers}/SunmiRfidHelper.kt +4 -3
- package/lib/commonjs/@types/index.js +11 -0
- package/lib/commonjs/@types/index.js.map +1 -1
- package/lib/commonjs/@types/pax.js +2 -0
- package/lib/commonjs/@types/pax.js.map +1 -0
- package/lib/commonjs/index.js +29 -30
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/@types/index.js +1 -0
- package/lib/module/@types/index.js.map +1 -1
- package/lib/module/@types/pax.js +2 -0
- package/lib/module/@types/pax.js.map +1 -0
- package/lib/module/index.js +29 -31
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/@types/index.d.ts +1 -0
- package/lib/typescript/src/@types/index.d.ts.map +1 -1
- package/lib/typescript/src/@types/pax.d.ts +7 -0
- package/lib/typescript/src/@types/pax.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/index.ts +1 -0
- package/src/@types/pax.ts +6 -0
- package/src/index.ts +90 -0
- package/src/index.tsx +0 -85
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
package com.pax.utils
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import java.io.UnsupportedEncodingException
|
|
6
|
+
import java.text.DecimalFormat
|
|
7
|
+
|
|
8
|
+
class PaxConverter private constructor() {
|
|
9
|
+
private var context: Context? = null
|
|
10
|
+
|
|
11
|
+
fun setContext(context: Context?) {
|
|
12
|
+
this.context = context
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Throws(IllegalArgumentException::class)
|
|
16
|
+
fun bcdToStr(b: ByteArray?): String {
|
|
17
|
+
if (b == null) {
|
|
18
|
+
Log.e(TAG, "bcdToStr input arg is null")
|
|
19
|
+
throw IllegalArgumentException("bcdToStr input arg is null")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
val HEX_DIGITS =
|
|
23
|
+
charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
|
|
24
|
+
val sb = StringBuilder(b.size * 2)
|
|
25
|
+
for (i in b.indices) {
|
|
26
|
+
sb.append(HEX_DIGITS[b[i].toInt() and 0xf0 ushr 4])
|
|
27
|
+
sb.append(HEX_DIGITS[b[i].toInt() and 0x0f])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return sb.toString()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Throws(IllegalArgumentException::class)
|
|
34
|
+
fun strToBcd(str: String?, paddingPosition: EPaddingPosition?): ByteArray {
|
|
35
|
+
var str = str
|
|
36
|
+
if (str == null || paddingPosition == null) {
|
|
37
|
+
Log.e(TAG, "strToBcd input arg is null")
|
|
38
|
+
throw IllegalArgumentException("strToBcd input arg is null")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var len = str.length
|
|
42
|
+
val mod = len % 2
|
|
43
|
+
if (mod != 0) {
|
|
44
|
+
str = if (paddingPosition == EPaddingPosition.PADDING_RIGHT) {
|
|
45
|
+
str + "0"
|
|
46
|
+
} else {
|
|
47
|
+
"0$str"
|
|
48
|
+
}
|
|
49
|
+
len = str.length
|
|
50
|
+
}
|
|
51
|
+
var abt = ByteArray(len)
|
|
52
|
+
if (len >= 2) {
|
|
53
|
+
len = len / 2
|
|
54
|
+
}
|
|
55
|
+
val bbt = ByteArray(len)
|
|
56
|
+
abt = str.toByteArray()
|
|
57
|
+
var j: Int
|
|
58
|
+
var k: Int
|
|
59
|
+
for (p in 0 until str.length / 2) {
|
|
60
|
+
j = if ((abt[2 * p] >= 'a'.code.toByte()) && (abt[2 * p] <= 'z'.code.toByte())) {
|
|
61
|
+
abt[2 * p] - 'a'.code.toByte() + 0x0a
|
|
62
|
+
} else if ((abt[2 * p] >= 'A'.code.toByte()) && (abt[2 * p] <= 'Z'.code.toByte())) {
|
|
63
|
+
abt[2 * p] - 'A'.code.toByte() + 0x0a
|
|
64
|
+
} else {
|
|
65
|
+
abt[2 * p] - '0'.code.toByte()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
k = if ((abt[2 * p + 1] >= 'a'.code.toByte()) && (abt[2 * p + 1] <= 'z'.code.toByte())) {
|
|
69
|
+
abt[2 * p + 1] - 'a'.code.toByte() + 0x0a
|
|
70
|
+
} else if ((abt[2 * p + 1] >= 'A'.code.toByte()) && (abt[2 * p + 1] <= 'Z'.code.toByte())) {
|
|
71
|
+
abt[2 * p + 1] - 'A'.code.toByte() + 0x0a
|
|
72
|
+
} else {
|
|
73
|
+
abt[2 * p + 1] - '0'.code.toByte()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
val a = (j shl 4) + k
|
|
77
|
+
val b = a.toByte()
|
|
78
|
+
bbt[p] = b
|
|
79
|
+
}
|
|
80
|
+
return bbt
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Throws(IllegalArgumentException::class)
|
|
84
|
+
fun longToByteArray(l: Long, to: ByteArray?, offset: Int, endian: EEndian?) {
|
|
85
|
+
if (to == null || endian == null) {
|
|
86
|
+
Log.e(TAG, "longToByteArray input arg is null")
|
|
87
|
+
throw IllegalArgumentException("longToByteArray input arg is null")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
91
|
+
to[offset] = ((l ushr 56) and 0xffL).toByte()
|
|
92
|
+
to[offset + 1] = ((l ushr 48) and 0xffL).toByte()
|
|
93
|
+
to[offset + 2] = ((l ushr 40) and 0xffL).toByte()
|
|
94
|
+
to[offset + 3] = ((l ushr 32) and 0xffL).toByte()
|
|
95
|
+
to[offset + 4] = ((l ushr 24) and 0xffL).toByte()
|
|
96
|
+
to[offset + 5] = ((l ushr 16) and 0xffL).toByte()
|
|
97
|
+
to[offset + 6] = ((l ushr 8) and 0xffL).toByte()
|
|
98
|
+
to[offset + 7] = (l and 0xffL).toByte()
|
|
99
|
+
} else {
|
|
100
|
+
to[offset + 7] = ((l ushr 56) and 0xffL).toByte()
|
|
101
|
+
to[offset + 6] = ((l ushr 48) and 0xffL).toByte()
|
|
102
|
+
to[offset + 5] = ((l ushr 40) and 0xffL).toByte()
|
|
103
|
+
to[offset + 4] = ((l ushr 32) and 0xffL).toByte()
|
|
104
|
+
to[offset + 3] = ((l ushr 24) and 0xffL).toByte()
|
|
105
|
+
to[offset + 2] = ((l ushr 16) and 0xffL).toByte()
|
|
106
|
+
to[offset + 1] = ((l ushr 8) and 0xffL).toByte()
|
|
107
|
+
to[offset] = (l and 0xffL).toByte()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Throws(IllegalArgumentException::class)
|
|
112
|
+
fun longToByteArray(l: Long, endian: EEndian?): ByteArray {
|
|
113
|
+
if (endian == null) {
|
|
114
|
+
Log.e(TAG, "longToByteArray input arg is null")
|
|
115
|
+
throw IllegalArgumentException("longToByteArray input arg is null")
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
val to = ByteArray(8)
|
|
119
|
+
|
|
120
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
121
|
+
to[0] = ((l ushr 56) and 0xffL).toByte()
|
|
122
|
+
to[1] = ((l ushr 48) and 0xffL).toByte()
|
|
123
|
+
to[2] = ((l ushr 40) and 0xffL).toByte()
|
|
124
|
+
to[3] = ((l ushr 32) and 0xffL).toByte()
|
|
125
|
+
to[4] = ((l ushr 24) and 0xffL).toByte()
|
|
126
|
+
to[5] = ((l ushr 16) and 0xffL).toByte()
|
|
127
|
+
to[6] = ((l ushr 8) and 0xffL).toByte()
|
|
128
|
+
to[7] = (l and 0xffL).toByte()
|
|
129
|
+
} else {
|
|
130
|
+
to[7] = ((l ushr 56) and 0xffL).toByte()
|
|
131
|
+
to[6] = ((l ushr 48) and 0xffL).toByte()
|
|
132
|
+
to[5] = ((l ushr 40) and 0xffL).toByte()
|
|
133
|
+
to[4] = ((l ushr 32) and 0xffL).toByte()
|
|
134
|
+
to[3] = ((l ushr 24) and 0xffL).toByte()
|
|
135
|
+
to[2] = ((l ushr 16) and 0xffL).toByte()
|
|
136
|
+
to[1] = ((l ushr 8) and 0xffL).toByte()
|
|
137
|
+
to[0] = (l and 0xffL).toByte()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return to
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Throws(IllegalArgumentException::class)
|
|
144
|
+
fun intToByteArray(i: Int, to: ByteArray?, offset: Int, endian: EEndian?) {
|
|
145
|
+
if (to == null || endian == null) {
|
|
146
|
+
Log.e(TAG, "longToByteArray input arg is null")
|
|
147
|
+
throw IllegalArgumentException("longToByteArray input arg is null")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
151
|
+
to[offset] = ((i ushr 24) and 0xff).toByte()
|
|
152
|
+
to[offset + 1] = ((i ushr 16) and 0xff).toByte()
|
|
153
|
+
to[offset + 2] = ((i ushr 8) and 0xff).toByte()
|
|
154
|
+
to[offset + 3] = (i and 0xff).toByte()
|
|
155
|
+
} else {
|
|
156
|
+
to[offset] = (i and 0xff).toByte()
|
|
157
|
+
to[offset + 1] = ((i ushr 8) and 0xff).toByte()
|
|
158
|
+
to[offset + 2] = ((i ushr 16) and 0xff).toByte()
|
|
159
|
+
to[offset + 3] = ((i ushr 24) and 0xff).toByte()
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@Throws(IllegalArgumentException::class)
|
|
164
|
+
fun intToByteArray(i: Int, endian: EEndian?): ByteArray {
|
|
165
|
+
if (endian == null) {
|
|
166
|
+
Log.e(TAG, "intToByteArray input arg is null")
|
|
167
|
+
throw IllegalArgumentException("intToByteArray input arg is null")
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
val to = ByteArray(4)
|
|
171
|
+
|
|
172
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
173
|
+
to[0] = ((i ushr 24) and 0xff).toByte()
|
|
174
|
+
to[1] = ((i ushr 16) and 0xff).toByte()
|
|
175
|
+
to[2] = ((i ushr 8) and 0xff).toByte()
|
|
176
|
+
to[3] = (i and 0xff).toByte()
|
|
177
|
+
} else {
|
|
178
|
+
to[0] = (i and 0xff).toByte()
|
|
179
|
+
to[1] = ((i ushr 8) and 0xff).toByte()
|
|
180
|
+
to[2] = ((i ushr 16) and 0xff).toByte()
|
|
181
|
+
to[3] = ((i ushr 24) and 0xff).toByte()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return to
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@Throws(IllegalArgumentException::class)
|
|
188
|
+
fun shortToByteArray(s: Short, to: ByteArray?, offset: Int, endian: EEndian?) {
|
|
189
|
+
if (to == null || endian == null) {
|
|
190
|
+
Log.e(TAG, "shortToByteArray input arg is null")
|
|
191
|
+
throw IllegalArgumentException("shortToByteArray input arg is null")
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
195
|
+
to[offset] = ((s.toInt() ushr 8) and 0xff).toByte()
|
|
196
|
+
to[offset + 1] = (s.toInt() and 0xff).toByte()
|
|
197
|
+
} else {
|
|
198
|
+
to[offset] = (s.toInt() and 0xff).toByte()
|
|
199
|
+
to[offset + 1] = ((s.toInt() ushr 8) and 0xff).toByte()
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Throws(IllegalArgumentException::class)
|
|
204
|
+
fun shortToByteArray(s: Short, endian: EEndian?): ByteArray {
|
|
205
|
+
if (endian == null) {
|
|
206
|
+
Log.e(TAG, "shortToByteArray input arg is null")
|
|
207
|
+
throw IllegalArgumentException("shortToByteArray input arg is null")
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
val to = ByteArray(2)
|
|
211
|
+
|
|
212
|
+
if (endian == EEndian.BIG_ENDIAN) {
|
|
213
|
+
to[0] = ((s.toInt() ushr 8) and 0xff).toByte()
|
|
214
|
+
to[1] = (s.toInt() and 0xff).toByte()
|
|
215
|
+
} else {
|
|
216
|
+
to[0] = (s.toInt() and 0xff).toByte()
|
|
217
|
+
to[1] = ((s.toInt() ushr 8) and 0xff).toByte()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return to
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@Throws(IllegalArgumentException::class)
|
|
224
|
+
fun longFromByteArray(from: ByteArray?, offset: Int, endian: EEndian?): Long {
|
|
225
|
+
if (from == null || endian == null) {
|
|
226
|
+
Log.e(TAG, "longFromByteArray input arg is null")
|
|
227
|
+
throw IllegalArgumentException("longFromByteArray input arg is null")
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return if (endian == EEndian.BIG_ENDIAN) {
|
|
231
|
+
(((from[offset].toInt() shl 56).toLong() and -0x100000000000000L) or ((from[offset + 1].toInt() shl 48).toLong() and 0xff000000000000L)
|
|
232
|
+
or ((from[offset + 2].toInt() shl 40).toLong() and 0xff0000000000L) or ((from[offset + 3].toInt() shl 32).toLong() and 0xff00000000L)
|
|
233
|
+
or ((from[offset + 4].toInt() shl 24) and -0x1000000).toLong() or ((from[offset + 5].toInt() shl 16) and 0xff0000)
|
|
234
|
+
.toLong()
|
|
235
|
+
or ((from[offset + 6].toInt() shl 8) and 0xff00).toLong() or (from[offset + 7].toInt() and 0xff).toLong())
|
|
236
|
+
} else {
|
|
237
|
+
(((from[offset + 7].toInt() shl 56).toLong() and -0x100000000000000L) or ((from[offset + 6].toInt() shl 48).toLong() and 0xff000000000000L)
|
|
238
|
+
or ((from[offset + 5].toInt() shl 40).toLong() and 0xff0000000000L) or ((from[offset + 4].toInt() shl 32).toLong() and 0xff00000000L)
|
|
239
|
+
or ((from[offset + 3].toInt() shl 24) and -0x1000000).toLong() or ((from[offset + 2].toInt() shl 16) and 0xff0000)
|
|
240
|
+
.toLong()
|
|
241
|
+
or ((from[offset + 1].toInt() shl 8) and 0xff00).toLong() or (from[offset].toInt() and 0xff).toLong())
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@Throws(IllegalArgumentException::class)
|
|
246
|
+
fun intFromByteArray(from: ByteArray?, offset: Int, endian: EEndian?): Int {
|
|
247
|
+
if (from == null || endian == null) {
|
|
248
|
+
Log.e(TAG, "intFromByteArray input arg is null")
|
|
249
|
+
throw IllegalArgumentException("intFromByteArray input arg is null")
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return if (endian == EEndian.BIG_ENDIAN) {
|
|
253
|
+
(((from[offset].toInt() shl 24) and -0x1000000) or ((from[offset + 1].toInt() shl 16) and 0xff0000)
|
|
254
|
+
or ((from[offset + 2].toInt() shl 8) and 0xff00) or (from[offset + 3].toInt() and 0xff))
|
|
255
|
+
} else {
|
|
256
|
+
(((from[offset + 3].toInt() shl 24) and -0x1000000) or ((from[offset + 2].toInt() shl 16) and 0xff0000)
|
|
257
|
+
or ((from[offset + 1].toInt() shl 8) and 0xff00) or (from[offset].toInt() and 0xff))
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@Throws(IllegalArgumentException::class)
|
|
262
|
+
fun shortFromByteArray(from: ByteArray?, offset: Int, endian: EEndian?): Short {
|
|
263
|
+
if (from == null || endian == null) {
|
|
264
|
+
Log.e(TAG, "shortFromByteArray input arg is null")
|
|
265
|
+
throw IllegalArgumentException("shortFromByteArray input arg is null")
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return if (endian == EEndian.BIG_ENDIAN) {
|
|
269
|
+
(((from[offset].toInt() shl 8) and 0xff00) or (from[offset + 1].toInt() and 0xff)).toShort()
|
|
270
|
+
} else {
|
|
271
|
+
(((from[offset + 1].toInt() shl 8) and 0xff00) or (from[offset].toInt() and 0xff)).toShort()
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@Throws(IllegalArgumentException::class)
|
|
276
|
+
fun stringPadding(
|
|
277
|
+
src: String?,
|
|
278
|
+
paddingChar: Char,
|
|
279
|
+
expLength: Long,
|
|
280
|
+
paddingpos: EPaddingPosition?
|
|
281
|
+
): String {
|
|
282
|
+
if (src == null || paddingpos == null) {
|
|
283
|
+
Log.e(TAG, "stringPadding input arg is null")
|
|
284
|
+
throw IllegalArgumentException("stringPadding input arg is null")
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (src.length >= expLength) {
|
|
288
|
+
return src
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (paddingpos == EPaddingPosition.PADDING_RIGHT) {
|
|
292
|
+
val sb = StringBuffer(src)
|
|
293
|
+
for (i in 0 until expLength - src.length) {
|
|
294
|
+
sb.append(paddingChar)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return sb.toString()
|
|
298
|
+
} else {
|
|
299
|
+
val sb = StringBuffer()
|
|
300
|
+
for (i in 0 until expLength - src.length) {
|
|
301
|
+
sb.append(paddingChar)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
sb.append(src)
|
|
305
|
+
return sb.toString()
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@Throws(IllegalArgumentException::class)
|
|
310
|
+
fun amountMajorToMinUnit(major: Double, exponent: ECurrencyExponent?): String {
|
|
311
|
+
if (exponent == null) {
|
|
312
|
+
Log.e(TAG, "amountMajorToMinUnit input arg is null")
|
|
313
|
+
throw IllegalArgumentException("amountMajorToMinUnit input arg is null")
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
val decimalFormat = DecimalFormat("0.000")
|
|
317
|
+
val majorS = decimalFormat.format(major)
|
|
318
|
+
|
|
319
|
+
val ht = majorS.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }
|
|
320
|
+
.toTypedArray()
|
|
321
|
+
|
|
322
|
+
val h = ht[0]
|
|
323
|
+
var t = ht[1]
|
|
324
|
+
|
|
325
|
+
if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_2) {
|
|
326
|
+
t = t.substring(0, 2)
|
|
327
|
+
|
|
328
|
+
return h + t
|
|
329
|
+
} else if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_0) {
|
|
330
|
+
return h
|
|
331
|
+
} else if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_1) {
|
|
332
|
+
t = t.substring(0, 1)
|
|
333
|
+
|
|
334
|
+
return h + t
|
|
335
|
+
} else if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_3) {
|
|
336
|
+
t = t.substring(0, 3)
|
|
337
|
+
|
|
338
|
+
return h + t
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return ""
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
@Throws(IllegalArgumentException::class)
|
|
345
|
+
fun amountMajorToMinUnit(major: String?, exponent: ECurrencyExponent?): String {
|
|
346
|
+
var major = major
|
|
347
|
+
if (major == null || exponent == null) {
|
|
348
|
+
Log.e(TAG, "amountMajorToMinUnit input arg is null")
|
|
349
|
+
throw IllegalArgumentException("amountMajorToMinUnit input arg is null")
|
|
350
|
+
}
|
|
351
|
+
major = major.replace(",", "")
|
|
352
|
+
return amountMajorToMinUnit(major.trim { it <= ' ' }.toDouble(), exponent)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@Throws(IllegalArgumentException::class)
|
|
356
|
+
fun amountMinUnitToMajor(
|
|
357
|
+
minUnit: String?,
|
|
358
|
+
exponent: ECurrencyExponent?,
|
|
359
|
+
isCommaStyle: Boolean
|
|
360
|
+
): String {
|
|
361
|
+
if (minUnit == null || exponent == null || minUnit == "") {
|
|
362
|
+
Log.e(TAG, "amountMinUnitToMajor input arg is null")
|
|
363
|
+
throw IllegalArgumentException("amountMinUnitToMajor input arg is null")
|
|
364
|
+
}
|
|
365
|
+
if (!minUnit.matches("[0-9]+".toRegex())) {
|
|
366
|
+
Log.e(TAG, "amountMinUnitToMajor input arg is illegal")
|
|
367
|
+
throw IllegalArgumentException("amountMinUnitToMajor input arg is illegal")
|
|
368
|
+
}
|
|
369
|
+
// 去掉头尾可能的空格
|
|
370
|
+
var temp = minUnit.trim { it <= ' ' }
|
|
371
|
+
temp = temp.toLong().toString() + "" // 删除minUnit的前导0
|
|
372
|
+
if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_2) {
|
|
373
|
+
if (temp.length < 3) {
|
|
374
|
+
val add = 3 - temp.length
|
|
375
|
+
for (i in 0 until add) {
|
|
376
|
+
temp = "0$temp"
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
temp = temp.substring(0, temp.length - 2) + "." + temp.substring(temp.length - 2)
|
|
380
|
+
} else if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_1) {
|
|
381
|
+
if (temp.length < 2) {
|
|
382
|
+
val add = 2 - temp.length
|
|
383
|
+
for (i in 0 until add) {
|
|
384
|
+
temp = "0$temp"
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
temp = temp.substring(0, temp.length - 1) + "." + temp.substring(temp.length - 1)
|
|
388
|
+
} else if (exponent == ECurrencyExponent.CURRENCY_EXPONENT_3) {
|
|
389
|
+
if (temp.length < 4) {
|
|
390
|
+
val add = 4 - temp.length
|
|
391
|
+
for (i in 0 until add) {
|
|
392
|
+
temp = "0$temp"
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
temp = temp.substring(0, temp.length - 3) + "." + temp.substring(temp.length - 3)
|
|
396
|
+
}
|
|
397
|
+
if (isCommaStyle == true) {
|
|
398
|
+
val index = temp.indexOf(".")
|
|
399
|
+
var strAdd = ""
|
|
400
|
+
if (index != -1) {
|
|
401
|
+
strAdd = temp.substring(index)
|
|
402
|
+
temp = temp.substring(0, index)
|
|
403
|
+
}
|
|
404
|
+
temp = StringBuffer(temp).reverse().toString() // 先将字符串颠倒顺序
|
|
405
|
+
var str2 = ""
|
|
406
|
+
val size = if ((temp.length % 3 == 0)) (temp.length / 3) else (temp.length / 3 + 1) // 每三位取一长度
|
|
407
|
+
/*
|
|
408
|
+
* 比如把一段字符串分成n段,第n段可能不是三个数,有可能是一个或者两个, 现将字符串分成两部分.一部分为前n-1段,第二部分为第n段.前n-1段,每一段加一",".而第n段直接取出即可
|
|
409
|
+
*/
|
|
410
|
+
for (i in 0 until size - 1) { // 前n-1段
|
|
411
|
+
str2 += temp.substring(i * 3, i * 3 + 3) + ","
|
|
412
|
+
}
|
|
413
|
+
for (i in size - 1 until size) { // 第n段
|
|
414
|
+
str2 += temp.substring(i * 3, temp.length)
|
|
415
|
+
}
|
|
416
|
+
str2 = StringBuffer(str2).reverse().toString()
|
|
417
|
+
str2 += strAdd
|
|
418
|
+
return str2
|
|
419
|
+
}
|
|
420
|
+
return temp
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* padding position
|
|
425
|
+
*
|
|
426
|
+
*/
|
|
427
|
+
enum class EPaddingPosition {
|
|
428
|
+
/**
|
|
429
|
+
* padding left
|
|
430
|
+
*/
|
|
431
|
+
PADDING_LEFT,
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* padding right
|
|
435
|
+
*/
|
|
436
|
+
PADDING_RIGHT
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* endian type
|
|
441
|
+
*
|
|
442
|
+
*/
|
|
443
|
+
enum class EEndian {
|
|
444
|
+
/**
|
|
445
|
+
* little endian
|
|
446
|
+
*/
|
|
447
|
+
LITTLE_ENDIAN,
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* big endian
|
|
451
|
+
*/
|
|
452
|
+
BIG_ENDIAN
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* currency exponent. refer to ISO4217
|
|
457
|
+
*
|
|
458
|
+
*/
|
|
459
|
+
enum class ECurrencyExponent {
|
|
460
|
+
/**
|
|
461
|
+
* currency exponent 0
|
|
462
|
+
*/
|
|
463
|
+
CURRENCY_EXPONENT_0,
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* currency exponent 1
|
|
467
|
+
*/
|
|
468
|
+
CURRENCY_EXPONENT_1,
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* currency exponent 2
|
|
472
|
+
*/
|
|
473
|
+
CURRENCY_EXPONENT_2,
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* currency exponent 3
|
|
477
|
+
*/
|
|
478
|
+
CURRENCY_EXPONENT_3
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
companion object {
|
|
482
|
+
private val TAG: String = PaxConverter::class.java.simpleName
|
|
483
|
+
|
|
484
|
+
@get:Synchronized
|
|
485
|
+
var instance: PaxConverter? = null
|
|
486
|
+
get() {
|
|
487
|
+
if (field == null) {
|
|
488
|
+
field = PaxConverter()
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return field
|
|
492
|
+
}
|
|
493
|
+
private set
|
|
494
|
+
|
|
495
|
+
fun bytes2String(source: ByteArray): String {
|
|
496
|
+
var result = ""
|
|
497
|
+
try {
|
|
498
|
+
if (source.size > 0) result = String(source, charset("UTF-8"))
|
|
499
|
+
} catch (e: UnsupportedEncodingException) {
|
|
500
|
+
e.printStackTrace()
|
|
501
|
+
}
|
|
502
|
+
return result.trim { it <= ' ' }
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
@@ -38,7 +38,7 @@ class PlugpagModule(
|
|
|
38
38
|
) {
|
|
39
39
|
try {
|
|
40
40
|
checkPlugpag()
|
|
41
|
-
plugpag
|
|
41
|
+
plugpag?.pay(rechargeValue, transactionType, promise)
|
|
42
42
|
} catch (e: Exception) {
|
|
43
43
|
e.printStackTrace()
|
|
44
44
|
promise.reject(e)
|
|
@@ -48,25 +48,25 @@ class PlugpagModule(
|
|
|
48
48
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
49
49
|
fun abortPayment() {
|
|
50
50
|
checkPlugpag()
|
|
51
|
-
plugpag
|
|
51
|
+
plugpag?.abortTransaction()
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
55
55
|
fun printEstablishmentReceipt() {
|
|
56
56
|
checkPlugpag()
|
|
57
|
-
plugpag
|
|
57
|
+
plugpag?.printEstablishmentReceipt()
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
61
61
|
fun printClientReceipt() {
|
|
62
62
|
checkPlugpag()
|
|
63
|
-
plugpag
|
|
63
|
+
plugpag?.printClientReceipt()
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
67
67
|
fun customDialogClientViaPrinter(color: String) {
|
|
68
68
|
checkPlugpag()
|
|
69
|
-
plugpag
|
|
69
|
+
plugpag?.customDialogClientViaPrinter(color)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
@@ -5,8 +5,8 @@ import android.graphics.BitmapFactory
|
|
|
5
5
|
import com.facebook.react.bridge.Promise
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
7
|
import com.mesmart.R
|
|
8
|
-
import com.sunmi.
|
|
9
|
-
import com.sunmi.
|
|
8
|
+
import com.sunmi.helpers.SunmiPrintHelper
|
|
9
|
+
import com.sunmi.helpers.SunmiRfidHelper
|
|
10
10
|
import sunmi.paylib.SunmiPayKernel
|
|
11
11
|
import sunmi.paylib.SunmiPayKernel.ConnectCallback
|
|
12
12
|
|
|
@@ -4,7 +4,7 @@ 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.
|
|
7
|
+
import com.mesmart.utils.Utils
|
|
8
8
|
|
|
9
9
|
class SunmiModule(
|
|
10
10
|
reactContext: ReactApplicationContext
|
|
@@ -12,7 +12,7 @@ class SunmiModule(
|
|
|
12
12
|
private var sunmi: SunmiImpl? = null
|
|
13
13
|
|
|
14
14
|
init {
|
|
15
|
-
if (
|
|
15
|
+
if (Utils.isSunmiP2()) {
|
|
16
16
|
sunmi = SunmiImpl(reactContext)
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -30,7 +30,7 @@ class SunmiModule(
|
|
|
30
30
|
fun searchRfid(promise: Promise) {
|
|
31
31
|
try {
|
|
32
32
|
checkSunmi()
|
|
33
|
-
|
|
33
|
+
sunmi?.searchRfid(promise)
|
|
34
34
|
} catch (e: Exception) {
|
|
35
35
|
e.printStackTrace()
|
|
36
36
|
promise.reject(e)
|
|
@@ -40,7 +40,7 @@ class SunmiModule(
|
|
|
40
40
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
41
41
|
fun cancelCardSearch() {
|
|
42
42
|
checkSunmi()
|
|
43
|
-
|
|
43
|
+
sunmi?.cancelCardSearch()
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
@@ -51,24 +51,24 @@ class SunmiModule(
|
|
|
51
51
|
isUnderline: Boolean
|
|
52
52
|
) {
|
|
53
53
|
checkSunmi()
|
|
54
|
-
|
|
54
|
+
sunmi?.printText(str, fontSize, isBold, isUnderline)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
58
58
|
fun printEmptyLine() {
|
|
59
59
|
checkSunmi()
|
|
60
|
-
sunmi
|
|
60
|
+
sunmi?.printEmptyLine()
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
64
64
|
fun printBpLogo() {
|
|
65
65
|
checkSunmi()
|
|
66
|
-
sunmi
|
|
66
|
+
sunmi?.printBpLogo()
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
70
70
|
fun setPrinterAlign(align: Int) {
|
|
71
71
|
checkSunmi()
|
|
72
|
-
sunmi
|
|
72
|
+
sunmi?.setPrinterAlign(align)
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
package com.sunmi.
|
|
1
|
+
package com.sunmi.helpers
|
|
2
2
|
|
|
3
3
|
import android.graphics.Bitmap
|
|
4
4
|
import android.os.RemoteException
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.mesmart.utils.ESCUtil
|
|
6
7
|
import com.sunmi.peripheral.printer.InnerPrinterCallback
|
|
7
8
|
import com.sunmi.peripheral.printer.InnerPrinterException
|
|
8
9
|
import com.sunmi.peripheral.printer.InnerPrinterManager
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
package com.sunmi.
|
|
1
|
+
package com.sunmi.helpers
|
|
2
2
|
|
|
3
3
|
import android.os.Bundle
|
|
4
4
|
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.mesmart.utils.Utils
|
|
5
6
|
import com.sunmi.pay.hardware.aidl.AidlConstants
|
|
6
7
|
import com.sunmi.pay.hardware.aidlv2.readcard.CheckCardCallbackV2
|
|
7
8
|
import sunmi.paylib.SunmiPayKernel
|
|
@@ -24,7 +25,7 @@ class SunmiRfidHelper(private val payKernel: SunmiPayKernel) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
override fun findRFCard(s: String) {
|
|
27
|
-
promise.resolve(
|
|
28
|
+
promise.resolve(Utils.resolveRFID(s))
|
|
28
29
|
cancelCardSearch()
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -60,7 +61,7 @@ class SunmiRfidHelper(private val payKernel: SunmiPayKernel) {
|
|
|
60
61
|
private fun handleOnFail(errorMessage: String, promise: Promise) {
|
|
61
62
|
attempt++
|
|
62
63
|
if (attempt == 5) {
|
|
63
|
-
promise.reject(
|
|
64
|
+
promise.reject(errorMessage)
|
|
64
65
|
attempt = 0
|
|
65
66
|
}
|
|
66
67
|
else searchRfid(promise)
|
|
@@ -25,4 +25,15 @@ Object.keys(_sunmi).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
var _pax = require("./pax");
|
|
29
|
+
Object.keys(_pax).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _pax[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _pax[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
28
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_plugpag","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_sunmi"],"sourceRoot":"../../../src","sources":["@types/index.ts"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_plugpag","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_sunmi","_pax"],"sourceRoot":"../../../src","sources":["@types/index.ts"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,IAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,IAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,IAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,IAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["@types/pax.ts"],"mappings":"","ignoreList":[]}
|