@haroldtran/react-native-pax 0.1.8 → 1.0.1

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 (34) hide show
  1. package/.gitignore +4 -0
  2. package/README.md +118 -160
  3. package/android/build.gradle +15 -4
  4. package/android/gradle.properties +8 -5
  5. package/android/libs/POSLink_Admin_Android_Plugin_V2.00.00_20230828.jar +0 -0
  6. package/android/libs/POSLink_Core_Android_V2.00.03_20230828.jar +0 -0
  7. package/android/libs/POSLink_Semi_Android_Plugin_V2.00.00_20230828.jar +0 -0
  8. package/android/libs/PaxLog_1.0.11_20220921.jar +0 -0
  9. package/android/src/main/java/com/paxposlink/PaxPosConstant.kt +57 -0
  10. package/android/src/main/java/com/paxposlink/PaxPosLinkModule.kt +711 -0
  11. package/android/src/main/java/com/paxposlink/PaxPosLinkPackage.kt +12 -0
  12. package/android/src/main/java/com/paxposlink/Utils.kt +99 -0
  13. package/lib/commonjs/index.js +57 -26
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/type.js +13 -0
  16. package/lib/commonjs/type.js.map +1 -0
  17. package/lib/module/index.js +54 -20
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/type.js +9 -0
  20. package/lib/module/type.js.map +1 -0
  21. package/lib/typescript/commonjs/index.d.ts +34 -8
  22. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/type.d.ts +37 -0
  24. package/lib/typescript/commonjs/type.d.ts.map +1 -0
  25. package/lib/typescript/module/index.d.ts +34 -8
  26. package/lib/typescript/module/index.d.ts.map +1 -1
  27. package/lib/typescript/module/type.d.ts +37 -0
  28. package/lib/typescript/module/type.d.ts.map +1 -0
  29. package/package.json +4 -2
  30. package/src/index.tsx +45 -49
  31. package/src/type.ts +39 -0
  32. package/android/libs/POSLink_Core.jar +0 -0
  33. package/android/src/main/java/com/paxposlink/PaxPoslinkModule.java +0 -355
  34. package/android/src/main/java/com/paxposlink/PaxPoslinkPackage.java +0 -28
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
+ import { PaxResponseModel } from './type';
2
3
 
3
4
  const LINKING_ERROR =
4
5
  `The package '@haroldtran/react-native-pax' doesn't seem to be linked. Make sure: \n\n` +
@@ -6,7 +7,7 @@ const LINKING_ERROR =
6
7
  '- You rebuilt the app after installing the package\n' +
7
8
  '- You are not using Expo Go\n';
8
9
 
9
- const PaxPoslink = NativeModules.PaxPoslink
10
+ const PaxPosLink = NativeModules.PaxPoslink
10
11
  ? NativeModules.PaxPoslink
11
12
  : new Proxy(
12
13
  {},
@@ -17,61 +18,56 @@ const PaxPoslink = NativeModules.PaxPoslink
17
18
  }
18
19
  );
19
20
 
20
- export function initPOSLink(
21
- type:
22
- | 'UART'
23
- | 'TCP'
24
- | 'SSL'
25
- | 'HTTP'
26
- | 'HTTPS'
27
- | 'BLUETOOTH'
28
- | 'USB'
29
- | 'AIDL',
30
- timeout: string,
31
- proxy: boolean,
32
- ip?: any,
33
- port?: any
34
- ): Promise<boolean> {
35
- return PaxPoslink.initPOSLink(type, timeout, proxy, ip, port);
21
+ /**
22
+ * Initializes the POSLink connection.
23
+ * @param {string} [ip] - The IP address of the POS device.
24
+ * @returns {*} The result of the native initPOSLink call.
25
+ */
26
+ export function initPOSLink(ip: string) {
27
+ return PaxPosLink.initPOSLink(ip);
36
28
  }
37
29
 
30
+ /**
31
+ * Initiates a payment transaction.
32
+ * @param {string} [id] - Transaction ID (optional).
33
+ * @param {number} [amount] - Payment amount
34
+ * @param {number} [tip] - Tip amount (optional).
35
+ * @param {number} [paymentType] - Type of payment (optional).
36
+ * @param {string} [ecrRefNum] - ECR reference number (optional).
37
+ * @returns {Promise<PaxResponseModel>} A promise resolving to the payment result.
38
+ */
38
39
  export function makePayment(
39
- amount: string,
40
- _tip: string = '0'
41
- ): Promise<string> {
42
- return PaxPoslink.runPayment(amount, _tip);
40
+ id?: string,
41
+ amount: number = 0,
42
+ tip?: number,
43
+ paymentType?: number,
44
+ ecrRefNum?: string
45
+ ): Promise<PaxResponseModel> {
46
+ return PaxPosLink.payment({ id, amount, tip, paymentType, ecrRefNum });
43
47
  }
44
48
 
45
- export function makeReturn(amount: string): Promise<string> {
46
- return PaxPoslink.runReturn(amount);
49
+ /**
50
+ * Initiates a refund transaction.
51
+ * @param {string} amount - The amount to refund.
52
+ * @returns {Promise<PaxResponseModel>} A promise resolving to the refund result.
53
+ */
54
+ export function makeRefund(amount: string): Promise<PaxResponseModel> {
55
+ return PaxPosLink.refund({ amount });
47
56
  }
48
57
 
49
- export function makeAdjustment(
50
- amount: string,
51
- refNum: string
52
- ): Promise<string> {
53
- return PaxPoslink.runAdjustment(amount, refNum);
58
+ /**
59
+ * Voids a transaction for the given amount.
60
+ * @param {string} amount - The amount to void.
61
+ * @returns {Promise<PaxResponseModel>} A promise resolving to the void result.
62
+ */
63
+ export function makeVoid(amount: string): Promise<PaxResponseModel> {
64
+ return PaxPosLink.void({ amount });
54
65
  }
55
66
 
56
- export function makeAuth(amount: string): Promise<string> {
57
- return PaxPoslink.runAuth(amount);
58
- }
59
-
60
- export function makePostAuth(
61
- amount: string,
62
- refNum: string,
63
- autCode: string
64
- ): Promise<string> {
65
- return PaxPoslink.runPostAuth(amount, refNum, autCode);
66
- }
67
-
68
- export function voidTransaction(
69
- refNum: string,
70
- autCode: string
71
- ): Promise<string> {
72
- return PaxPoslink.runVoid(refNum, autCode);
73
- }
74
-
75
- export function closeBatch(): Promise<string> {
76
- return PaxPoslink.closeBatch();
67
+ /**
68
+ * Closes the current batch of transactions.
69
+ * @returns {Promise<PaxResponseModel>} A promise resolving to the batch closeout result.
70
+ */
71
+ export function makeCloseBatch(): Promise<PaxResponseModel> {
72
+ return PaxPosLink.batchCloseout();
77
73
  }
package/src/type.ts ADDED
@@ -0,0 +1,39 @@
1
+ export interface PaxRequestModel {
2
+ id?: string;
3
+ amount?: number;
4
+ tip?: number;
5
+ paymentType?: number;
6
+ ecrRefNum?: string;
7
+ }
8
+
9
+ export interface PaxResponseModel {
10
+ status?: boolean;
11
+ data?: any; // WritableMap equivalent, adjust as needed
12
+ message?: string;
13
+ isPaymentSuccess?: boolean;
14
+ id?: string;
15
+ transactionId?: string;
16
+ transactionNo?: string;
17
+ refNum?: string;
18
+ transactionDateTime?: string;
19
+ cardType?: string;
20
+ cardNumber?: string;
21
+ cardHolder?: string;
22
+ amount?: string;
23
+ tipAmount?: string;
24
+ surcharge?: string;
25
+ entryMethod?: string;
26
+ sn?: string;
27
+ }
28
+
29
+ export interface PaxTerminalInfoModel {
30
+ serialNumber?: string;
31
+ modelName?: string;
32
+ appName?: string;
33
+ }
34
+
35
+ export enum CreditTransactionType {
36
+ Credit = 1,
37
+ Debit = 2,
38
+ Empty = 0,
39
+ }
Binary file
@@ -1,355 +0,0 @@
1
- package com.paxposlink;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.bridge.Promise;
6
- import com.facebook.react.bridge.ReactApplicationContext;
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
- import com.facebook.react.bridge.ReactMethod;
9
- import com.facebook.react.module.annotations.ReactModule;
10
- import com.facebook.react.bridge.Arguments;
11
- import com.facebook.react.bridge.WritableMap;
12
- import java.util.Map;
13
- import java.util.HashMap;
14
- import com.paxposlink.poslink.CommSetting;
15
- import com.paxposlink.poslink.POSLinkAndroid;
16
- import com.paxposlink.poslink.LogSetting;
17
- import com.paxposlink.poslink.PosLink;
18
- import com.paxposlink.poslink.PaymentRequest;
19
- import com.paxposlink.poslink.ProcessTransResult;
20
- import com.paxposlink.poslink.PaymentResponse;
21
- import com.paxposlink.poslink.BatchRequest;
22
- import com.paxposlink.poslink.BatchResponse;
23
- import com.paxposlink.poslink.CommSetting;
24
- import android.os.HandlerThread;
25
- import android.os.Handler;
26
- import android.os.Looper;
27
- import java.lang.Runnable;
28
- import android.util.Log;
29
- import android.content.Context;
30
-
31
- @ReactModule(name = PaxPoslinkModule.NAME)
32
- public class PaxPoslinkModule extends ReactContextBaseJavaModule {
33
- public static final String NAME = "PaxPoslink";
34
- private PosLink poslink;
35
- private HandlerThread handlerThread;
36
- private Context context;
37
-
38
- public PaxPoslinkModule(ReactApplicationContext reactContext) {
39
-
40
- super(reactContext);
41
- this.context = reactContext;
42
-
43
- }
44
-
45
- @Override
46
- @NonNull
47
- public String getName() {
48
- return NAME;
49
- }
50
-
51
- // Example method
52
- // See https://reactnative.dev/docs/native-modules-android
53
- @ReactMethod
54
- public void multiply(double a, double b, Promise promise) {
55
- promise.resolve(a * b);
56
- }
57
-
58
- @ReactMethod
59
- public void initPOSLink(String type, String timeout, Boolean proxy, String ip, String port, Promise promise) {
60
-
61
- try {
62
- LogSetting logSetting = new LogSetting();
63
-
64
- logSetting.setLogMode(true); // Open or close log
65
- logSetting.setLevel(LogSetting.LOGLEVEL.DEBUG); // Set log level
66
- logSetting.setLogFileName("POSLinkLog"); // Set the file name of output log
67
- logSetting.setOutputPath("sdcard/log"); // Set path for output log
68
- logSetting.setLogDays("30"); // Keep log for 30 days
69
-
70
- // Setting connection configurations
71
- CommSetting commSetting = new CommSetting();
72
-
73
- commSetting.setType(type);
74
-
75
- if (ip != null) {
76
- commSetting.setDestIP(ip);
77
- commSetting.setDestPort(port);
78
- }
79
-
80
- commSetting.setTimeOut(timeout);
81
-
82
- if (proxy) {
83
- commSetting.setEnableProxy(proxy);
84
- }
85
-
86
- poslink = new PosLink(this.context);
87
-
88
- poslink.SetCommSetting(commSetting);
89
-
90
- promise.resolve(true);
91
-
92
- } catch (Exception e) {
93
- promise.reject("Exception Error", e);
94
- }
95
-
96
- }
97
-
98
- @ReactMethod
99
- private void runPayment(String amount, String tip, Promise promise) {
100
-
101
- PaymentRequest req = new PaymentRequest();
102
-
103
- req.TenderType = req.ParseTenderType("CREDIT");
104
- req.TransType = req.ParseTransType("SALE");
105
- req.ECRRefNum = "1";
106
- req.Amount = amount;
107
- req.TipAmt = tip;
108
-
109
- this.runTransaction(req, promise);
110
-
111
- }
112
-
113
- @ReactMethod
114
- private void runAuth(String amount, Promise promise) {
115
-
116
- PaymentRequest req = new PaymentRequest();
117
-
118
- req.TenderType = req.ParseTenderType("CREDIT");
119
- req.TransType = req.ParseTransType("AUTH");
120
- req.ECRRefNum = "1";
121
- req.Amount = amount;
122
-
123
- this.runTransaction(req, promise);
124
-
125
- }
126
-
127
- @ReactMethod
128
- private void runReturn(String amount, Promise promise) {
129
-
130
- PaymentRequest req = new PaymentRequest();
131
-
132
- req.TenderType = req.ParseTenderType("CREDIT");
133
- req.TransType = req.ParseTransType("RETURN");
134
- req.ECRRefNum = "5";
135
- req.Amount = amount;
136
-
137
- this.runTransaction(req, promise);
138
-
139
- }
140
-
141
- @ReactMethod
142
- private void closeBatch(Promise promise) {
143
-
144
- handlerThread = new HandlerThread("MyHandlerThread");
145
- handlerThread.start();
146
- Looper looper = handlerThread.getLooper();
147
- Handler handler = new Handler(looper);
148
-
149
- handler.post(new Runnable() {
150
-
151
- @Override
152
- public void run() {
153
- BatchRequest batchRequest = new BatchRequest();
154
- batchRequest.TransType = batchRequest.ParseTransType("BATCHCLOSE");
155
- poslink.BatchRequest = batchRequest;
156
-
157
- ProcessTransResult ptr = poslink.ProcessTrans();
158
-
159
- if (ptr.Code == ProcessTransResult.ProcessTransResultCode.OK) {
160
- BatchResponse response = poslink.BatchResponse;
161
-
162
- WritableMap map = Arguments.createMap();
163
- map.putString("AuthCode", response.AuthCode);
164
- map.putString("BatchFailedCount", response.BatchFailedCount);
165
- map.putString("BatchFailedRefNum", response.BatchFailedRefNum);
166
- map.putString("BatchNum", response.BatchNum);
167
- map.putString("CashAmount", response.CashAmount);
168
- map.putString("CashCount", response.CashCount);
169
- map.putString("CHECKAmount", response.CHECKAmount);
170
- map.putString("CreditAmount", response.CreditAmount);
171
- map.putString("CreditCount", response.CreditCount);
172
- map.putString("DebitAmount", response.DebitAmount);
173
- map.putString("DebitCount", response.DebitCount);
174
- map.putString("EBTAmount", response.EBTAmount);
175
- map.putString("EBTCount", response.EBTCount);
176
- map.putString("ExtData", response.ExtData);
177
- map.putString("GiftAmount", response.GiftAmount);
178
- map.putString("GiftCount", response.GiftCount);
179
- map.putString("HostCode", response.HostCode);
180
- map.putString("HostResponse", response.HostResponse);
181
- map.putString("HostTraceNum", response.HostTraceNum);
182
- map.putString("LoyaltyAmount", response.LoyaltyAmount);
183
- map.putString("LoyaltyCount", response.LoyaltyCount);
184
- map.putString("Message", response.Message);
185
- map.putString("ResultCode", response.ResultCode);
186
- map.putString("ResultTxt", response.ResultTxt);
187
- map.putString("SAFDeletedCount", response.SAFDeletedCount);
188
- map.putString("SAFFailedCount", response.SAFFailedCount);
189
- map.putString("SAFFailedTotal", response.SAFFailedTotal);
190
- map.putString("SAFTotalAmount", response.SAFTotalAmount);
191
- map.putString("SAFTotalCount", response.SAFTotalCount);
192
- map.putString("SAFUploadedAmount", response.SAFUploadedAmount);
193
- map.putString("SAFUploadedCount", response.SAFUploadedCount);
194
- map.putString("TID", response.TID);
195
- map.putString("Timestamp", response.Timestamp);
196
-
197
- promise.resolve(map);
198
-
199
- } else if (ptr.Code == ProcessTransResult.ProcessTransResultCode.TimeOut) {
200
- String errorMsg = ptr.Msg;
201
- String errorCode = String.valueOf(ptr.Code);
202
- promise.reject(ptr.Msg);
203
-
204
- } else {
205
- String errorMsg = ptr.Msg;
206
- String errorCode = String.valueOf(ptr.Code);
207
- promise.reject(ptr.Msg);
208
- }
209
- }
210
- });
211
- }
212
-
213
- @ReactMethod
214
- private void runPostAuth(String amount, String refNum, String authCode, Promise promise) {
215
- PaymentRequest req = new PaymentRequest();
216
-
217
- req.TenderType = req.ParseTenderType("CREDIT");
218
- req.TransType = req.ParseTransType("POSTAUTH");
219
- req.ECRRefNum = "1";
220
- req.OrigRefNum = refNum;
221
- req.AuthCode = authCode;
222
- req.Amount = amount;
223
-
224
- this.runTransaction(req, promise);
225
- }
226
-
227
- @ReactMethod
228
- private void runVoid(String refNum, String authCode, Promise promise) {
229
- PaymentRequest req = new PaymentRequest();
230
-
231
- req.TenderType = req.ParseTenderType("CREDIT");
232
- req.TransType = req.ParseTransType("VOID");
233
- req.ECRRefNum = "1";
234
- req.OrigRefNum = refNum;
235
- req.AuthCode = authCode;
236
-
237
- this.runTransaction(req, promise);
238
- }
239
-
240
- @ReactMethod
241
- private void runAdjustment(String amount, String refNum, Promise promise) {
242
- PaymentRequest req = new PaymentRequest();
243
-
244
- req.TenderType = req.ParseTenderType("CREDIT");
245
- req.TransType = req.ParseTransType("ADJUST");
246
- req.OrigTraceNum = refNum;
247
- req.ECRRefNum = "1";
248
- req.OrigRefNum = refNum;
249
- req.Amount = amount;
250
-
251
- this.runTransaction(req, promise);
252
- }
253
-
254
- @ReactMethod
255
- private void runTransaction(PaymentRequest request, Promise promise) {
256
-
257
- handlerThread = new HandlerThread("MyHandlerThread");
258
- handlerThread.start();
259
- Looper looper = handlerThread.getLooper();
260
- Handler handler = new Handler(looper);
261
-
262
- handler.post(new Runnable() {
263
-
264
- @Override
265
- public void run() {
266
- Log.d("DEBUG_POSLINK_INFO", String.valueOf(poslink.GetCommSetting().getDestIP()));
267
-
268
- poslink.PaymentRequest = request;
269
-
270
- ProcessTransResult ptr = poslink.ProcessTrans();
271
-
272
- Log.d("DEBUG_PAYMENT_REQUEST", String.valueOf(ptr.Msg));
273
-
274
- // Check transaction result
275
- if (ptr.Code == ProcessTransResult.ProcessTransResultCode.OK) {
276
- /**
277
- * When the transResult.Code is OK, then the response has already been
278
- * assigned to poslink instance's PaymentResponse field automatically,
279
- * what you only need to do is get the response from the field
280
- */
281
- PaymentResponse response = poslink.PaymentResponse;
282
-
283
- Log.d("PAYMENT_RESPONSE_DEBUG AuthCode", response.AuthCode);
284
- WritableMap map = Arguments.createMap();
285
- map.putString("ApprovedAmount", response.ApprovedAmount);
286
- map.putString("ApprovedCashBackAmount", response.ApprovedCashBackAmount);
287
- map.putString("ApprovedMerchantFee", response.ApprovedMerchantFee);
288
- map.putString("ApprovedTaxAmount", response.ApprovedTaxAmount);
289
- map.putString("ApprovedTipAmount", response.ApprovedTipAmount);
290
- map.putString("AuthCode", response.AuthCode);
291
- map.putString("AuthorizationResponse", response.AuthorizationResponse);
292
- map.putString("AvsResponse", response.AvsResponse);
293
- map.putString("BogusAccountNum", response.BogusAccountNum);
294
- map.putString("CardType", response.CardType);
295
- map.putString("CvResponse", response.CvResponse);
296
- map.putString("DebitAccountType", response.DebitAccountType);
297
- map.putString("ECRTransID", response.ECRTransID);
298
- map.putString("EDCType", response.EDCType);
299
- map.putString("ExtraBalance", response.ExtraBalance);
300
- map.putString("GatewayTransactionID", response.GatewayTransactionID);
301
- map.putString("GiftCardType", response.GiftCardType);
302
- map.putString("HostAccount", response.HostAccount);
303
- map.putString("HostCardType", response.HostCardType);
304
- map.putString("HostCode", response.HostCode);
305
- map.putString("HostDetailedMessage", response.HostDetailedMessage);
306
- map.putString("HostResponse", response.HostResponse);
307
- map.putString("HostTimeStamp", response.HostTimeStamp);
308
- map.putString("IssuerResponseCode", response.IssuerResponseCode);
309
- map.putString("MaskedPAN", response.MaskedPAN);
310
- map.putString("Message", response.Message);
311
- map.putString("PayloadData", response.PayloadData);
312
- map.putString("PaymentAccountReferenceID", response.PaymentAccountReferenceID);
313
- map.putString("RawResponse", response.RawResponse);
314
- map.putString("RefNum", response.RefNum);
315
- map.putString("RemainingBalance", response.RemainingBalance);
316
- map.putString("RequestedAmount", response.RequestedAmount);
317
- map.putString("ResultCode", response.ResultCode);
318
- map.putString("ResultTxt", response.ResultTxt);
319
- map.putString("RetrievalReferenceNumber", response.RetrievalReferenceNumber);
320
- map.putString("SigFileName", response.SigFileName);
321
- map.putString("SignData", response.SignData);
322
- map.putString("Timestamp", response.Timestamp);
323
- map.putString("Track1Data", response.Track1Data);
324
- map.putString("Track2Data", response.Track2Data);
325
- map.putString("Track3Data", response.Track3Data);
326
- map.putString("TransactionIntegrityClass", response.TransactionIntegrityClass);
327
- map.putString("TransactionRemainingAmount", response.TransactionRemainingAmount);
328
- map.putString("ExtData", response.ExtData);
329
-
330
- promise.resolve(map);
331
-
332
- } else if (ptr.Code == ProcessTransResult.ProcessTransResultCode.TimeOut) {
333
- String errorMsg = ptr.Msg;
334
- String errorCode = String.valueOf(ptr.Code);
335
- Log.d("PAYMENT_RESPONSE_DEBUG", errorMsg);
336
- Log.d("PAYMENT_RESPONSE_DEBUG", errorCode);
337
- handler.getLooper().quit();
338
- promise.reject(ptr.Msg);
339
-
340
- } else {
341
- String errorMsg = ptr.Msg;
342
- String errorCode = String.valueOf(ptr.Code);
343
- Log.d("PAYMENT_RESPONSE_DEBUG", errorCode);
344
- Log.d("PAYMENT_RESPONSE_DEBUG", errorMsg);
345
- promise.reject(ptr.Msg);
346
-
347
- handler.getLooper().quit();
348
-
349
- }
350
- }
351
- });
352
-
353
- }
354
-
355
- }
@@ -1,28 +0,0 @@
1
- package com.paxposlink;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.ReactPackage;
6
- import com.facebook.react.bridge.NativeModule;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.uimanager.ViewManager;
9
-
10
- import java.util.ArrayList;
11
- import java.util.Collections;
12
- import java.util.List;
13
-
14
- public class PaxPoslinkPackage implements ReactPackage {
15
- @NonNull
16
- @Override
17
- public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
- List<NativeModule> modules = new ArrayList<>();
19
- modules.add(new PaxPoslinkModule(reactContext));
20
- return modules;
21
- }
22
-
23
- @NonNull
24
- @Override
25
- public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26
- return Collections.emptyList();
27
- }
28
- }