@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/.gitignore CHANGED
@@ -38,3 +38,7 @@ yarn-error.*
38
38
 
39
39
  app-example
40
40
  .yarn/
41
+ android/.idea/*
42
+ android/.gradle/*
43
+ android/gradle/wrapper/gradle-wrapper.jar
44
+ android/local.properties
package/README.md CHANGED
@@ -9,27 +9,23 @@ React Native library to integrate with PAX payment devices using the POSLink SDK
9
9
 
10
10
  ## Features
11
11
 
12
- - 🔄 Initialize PAX device connection
13
- - 💳 Process credit card payments (Sale, Auth, Post-Auth)
14
- - 🔄 Handle transaction adjustments and voids
12
+ - 🔄 Initialize PAX device connection via TCP/IP
13
+ - 💳 Process credit and debit card payments (Sale)
14
+ - 🔄 Handle voids (Void Sale)
15
15
  - 📊 Batch operations and settlement
16
- - 🔙 Process returns and refunds
17
- - 📱 Support for both iOS and Android platforms
16
+ - 🔙 Process refunds (Return)
17
+ - 📱 Android platform support (iOS implementation pending)
18
18
 
19
19
  ## Installation
20
20
 
21
- ```sh
22
- npm install @haroldtran/react-native-pax
23
- ```
24
-
25
- or with yarn:
26
-
27
21
  ```sh
28
22
  yarn add @haroldtran/react-native-pax
29
23
  ```
30
24
 
31
25
  ### iOS Setup
32
26
 
27
+ ⚠️ **Note: iOS implementation is currently not complete. Only Android is fully supported at this time.**
28
+
33
29
  1. Navigate to your iOS project directory and install pods:
34
30
  ```sh
35
31
  cd ios && pod install
@@ -52,12 +48,9 @@ The Android setup is automatic. The library will be linked automatically when yo
52
48
  import {
53
49
  initPOSLink,
54
50
  makePayment,
55
- makeAuth,
56
- makePostAuth,
57
- makeReturn,
58
- makeAdjustment,
59
- voidTransaction,
60
- closeBatch
51
+ makeRefund,
52
+ makeVoid,
53
+ makeCloseBatch
61
54
  } from '@haroldtran/react-native-pax';
62
55
  ```
63
56
 
@@ -67,17 +60,8 @@ First, initialize the connection to your PAX device:
67
60
 
68
61
  ```js
69
62
  try {
70
- const success = await initPOSLink(
71
- 'TCP', // Connection type: 'UART', 'TCP', 'SSL', 'HTTP', 'HTTPS', 'BLUETOOTH', 'USB', 'AIDL'
72
- '30000', // Timeout in milliseconds
73
- false, // Use proxy
74
- '192.168.1.100', // Device IP (for TCP/IP connections)
75
- '10009' // Port number
76
- );
77
-
78
- if (success) {
79
- console.log('PAX device initialized successfully');
80
- }
63
+ const result = await initPOSLink('192.168.1.100'); // Pass the IP address of the POS device
64
+ console.log('PAX device initialized:', result);
81
65
  } catch (error) {
82
66
  console.error('Failed to initialize PAX device:', error);
83
67
  }
@@ -86,56 +70,47 @@ try {
86
70
  ### Process a Payment
87
71
 
88
72
  ```js
89
- try {
90
- const result = await makePayment('10.00', '1.50'); // amount, tip
91
- console.log('Payment result:', result);
92
-
93
- // Result contains transaction details like:
94
- // - AuthCode
95
- // - RefNum
96
- // - ApprovedAmount
97
- // - CardType
98
- // - MaskedPAN
99
- // etc.
100
- } catch (error) {
101
- console.error('Payment failed:', error);
102
- }
103
- ```
73
+ import { CreditTransactionType } from '@haroldtran/react-native-pax/lib/typescript/module/type';
104
74
 
105
- ### Authorization Only
106
-
107
- ```js
108
75
  try {
109
- const result = await makeAuth('25.00');
110
- console.log('Authorization result:', result);
111
- } catch (error) {
112
- console.error('Authorization failed:', error);
113
- }
114
- ```
115
-
116
- ### Post Authorization (Capture)
117
-
118
- ```js
119
- try {
120
- const result = await makePostAuth(
121
- '25.00', // amount
122
- 'REF123456', // original reference number
123
- 'AUTH123' // authorization code
76
+ const paymentResult = await makePayment(
77
+ 'txn-123', // id (optional)
78
+ 1000, // amount in cents (e.g., 1000 = $10.00)
79
+ 150, // tip in cents (optional, e.g., 150 = $1.50)
80
+ CreditTransactionType.Credit, // paymentType (1 = Credit, 2 = Debit)
81
+ 'ECR123' // ecrRefNum (optional)
124
82
  );
125
- console.log('Post-auth result:', result);
83
+
84
+ console.log('Payment result:', paymentResult);
85
+ // paymentResult contains:
86
+ // - status: boolean
87
+ // - isPaymentSuccess: boolean
88
+ // - cardHolder: string
89
+ // - cardNumber: string (masked)
90
+ // - refNum: string
91
+ // - transactionId: string
92
+ // - amount: string
93
+ // - tipAmount: string
94
+ // - cardType: string
95
+ // - entryMethod: string
96
+ // - and more transaction details
126
97
  } catch (error) {
127
- console.error('Post-auth failed:', error);
98
+ console.error('Payment failed:', error);
128
99
  }
129
100
  ```
130
101
 
131
- ### Process a Return
102
+
103
+ ### Process a Refund
132
104
 
133
105
  ```js
134
106
  try {
135
- const result = await makeReturn('15.00');
136
- console.log('Return result:', result);
107
+ const refundResult = await makeRefund({
108
+ amount: 1500 // amount in cents (e.g., 1500 = $15.00)
109
+ });
110
+ console.log('Refund result:', refundResult);
111
+ // refundResult is a PaxResponseModel object
137
112
  } catch (error) {
138
- console.error('Return failed:', error);
113
+ console.error('Refund failed:', error);
139
114
  }
140
115
  ```
141
116
 
@@ -143,42 +118,24 @@ try {
143
118
 
144
119
  ```js
145
120
  try {
146
- const result = await voidTransaction(
147
- 'REF123456', // original reference number
148
- 'AUTH123' // authorization code
149
- );
150
- console.log('Void result:', result);
121
+ const voidResult = await makeVoid({
122
+ amount: 1500 // amount in cents (e.g., 1500 = $15.00)
123
+ });
124
+ console.log('Void result:', voidResult);
125
+ // voidResult is a PaxResponseModel object
151
126
  } catch (error) {
152
127
  console.error('Void failed:', error);
153
128
  }
154
129
  ```
155
130
 
156
- ### Adjust a Transaction
157
-
158
- ```js
159
- try {
160
- const result = await makeAdjustment(
161
- '12.50', // new amount
162
- 'REF123456' // original reference number
163
- );
164
- console.log('Adjustment result:', result);
165
- } catch (error) {
166
- console.error('Adjustment failed:', error);
167
- }
168
- ```
169
131
 
170
132
  ### Close Batch
171
133
 
172
134
  ```js
173
135
  try {
174
- const result = await closeBatch();
175
- console.log('Batch close result:', result);
176
-
177
- // Result contains batch summary:
178
- // - BatchNum
179
- // - CreditCount, CreditAmount
180
- // - DebitCount, DebitAmount
181
- // etc.
136
+ const batchResult = await makeCloseBatch();
137
+ console.log('Batch close result:', batchResult);
138
+ // batchResult is a PaxResponseModel object
182
139
  } catch (error) {
183
140
  console.error('Batch close failed:', error);
184
141
  }
@@ -186,113 +143,114 @@ try {
186
143
 
187
144
  ## API Reference
188
145
 
189
- ### initPOSLink(type, timeout, proxy, ip?, port?)
146
+ #### initPOSLink(ip)
190
147
 
191
148
  Initializes the connection to the PAX device.
192
149
 
193
150
  **Parameters:**
194
- - `type` (string): Connection type - 'UART', 'TCP', 'SSL', 'HTTP', 'HTTPS', 'BLUETOOTH', 'USB', 'AIDL'
195
- - `timeout` (string): Timeout in milliseconds
196
- - `proxy` (boolean): Whether to use proxy
197
- - `ip` (string, optional): Device IP address (for network connections)
198
- - `port` (string, optional): Port number (for network connections)
151
+ - `ip` (string): Device IP address
199
152
 
200
- **Returns:** `Promise<boolean>`
153
+ **Returns:** `Promise<any>`
201
154
 
202
- ### makePayment(amount, tip?)
155
+ #### makePayment(id?, amount, tip?, paymentType?, ecrRefNum?)
203
156
 
204
- Processes a sale transaction.
157
+ Initiates a payment transaction.
205
158
 
206
159
  **Parameters:**
207
- - `amount` (string): Transaction amount
208
- - `tip` (string, optional): Tip amount (default: "0")
160
+ - `id` (string, optional): Transaction ID
161
+ - `amount` (number): Payment amount in cents (e.g., 1000 = $10.00)
162
+ - `tip` (number, optional): Tip amount in cents (e.g., 150 = $1.50)
163
+ - `paymentType` (number, optional): Type of payment (1 = Credit, 2 = Debit, see `CreditTransactionType` enum)
164
+ - `ecrRefNum` (string, optional): ECR reference number
209
165
 
210
- **Returns:** `Promise<PaymentResponse>`
166
+ **Returns:** `Promise<PaxResponseModel>`
211
167
 
212
- ### makeAuth(amount)
168
+ #### makeRefund(data)
213
169
 
214
- Processes an authorization-only transaction.
170
+ Initiates a refund transaction.
215
171
 
216
172
  **Parameters:**
217
- - `amount` (string): Authorization amount
173
+ - `data` (object): Object containing:
174
+ - `amount` (number): The amount to refund in cents
218
175
 
219
- **Returns:** `Promise<PaymentResponse>`
176
+ **Returns:** `Promise<PaxResponseModel>`
220
177
 
221
- ### makePostAuth(amount, refNum, authCode)
178
+ #### makeVoid(data)
222
179
 
223
- Captures a previously authorized transaction.
180
+ Voids a transaction for the given amount.
224
181
 
225
182
  **Parameters:**
226
- - `amount` (string): Capture amount
227
- - `refNum` (string): Original reference number
228
- - `authCode` (string): Authorization code
229
-
230
- **Returns:** `Promise<PaymentResponse>`
183
+ - `data` (object): Object containing:
184
+ - `amount` (number): The amount to void in cents
231
185
 
232
- ### makeReturn(amount)
186
+ **Returns:** `Promise<PaxResponseModel>`
233
187
 
234
- Processes a return transaction.
188
+ #### makeCloseBatch()
235
189
 
236
- **Parameters:**
237
- - `amount` (string): Return amount
190
+ Closes the current batch of transactions.
238
191
 
239
- **Returns:** `Promise<PaymentResponse>`
192
+ **Returns:** `Promise<PaxResponseModel>`
240
193
 
241
- ### makeAdjustment(amount, refNum)
242
-
243
- Adjusts a previous transaction amount.
244
-
245
- **Parameters:**
246
- - `amount` (string): New amount
247
- - `refNum` (string): Original reference number
248
-
249
- **Returns:** `Promise<PaymentResponse>`
194
+ ## Response Objects
250
195
 
251
- ### voidTransaction(refNum, authCode)
252
196
 
253
- Voids a previous transaction.
197
+ ### PaxResponseModel
254
198
 
255
- **Parameters:**
256
- - `refNum` (string): Original reference number
257
- - `authCode` (string): Authorization code
199
+ The response object returned by all transaction functions. Key fields include:
258
200
 
259
- **Returns:** `Promise<PaymentResponse>`
201
+ **Status & Result:**
202
+ - `status` (boolean): Overall operation success status
203
+ - `isPaymentSuccess` (boolean): Payment-specific success flag
204
+ - `message` (string): Response message or error description
260
205
 
261
- ### closeBatch()
206
+ **Transaction Details:**
207
+ - `id` (string): Transaction ID
208
+ - `transactionId` (string): Global unique transaction identifier
209
+ - `transactionNo` (string): Transaction sequence number
210
+ - `refNum` (string): Reference number
211
+ - `transactionDateTime` (string): Date/time of transaction
262
212
 
263
- Closes the current batch and settles transactions.
213
+ **Card & Payment Info:**
214
+ - `cardType` (string): Card type/brand (e.g., VISA, MASTERCARD)
215
+ - `cardNumber` (string): Masked card number
216
+ - `cardHolder` (string): Card holder name
217
+ - `entryMethod` (string): How card was entered (SWIPED_MSD, CONTACT_CHIP, CONTACTLESS_CHIP, etc.)
264
218
 
265
- **Returns:** `Promise<BatchResponse>`
266
-
267
- ## Response Objects
219
+ **Amount Details:**
220
+ - `amount` (string): Transaction amount
221
+ - `tipAmount` (string): Tip amount
222
+ - `surcharge` (string): Additional fees/surcharge
268
223
 
269
- ### PaymentResponse
224
+ **Additional Data:**
225
+ - `data` (object): Detailed response data including account info, trace info, AVS info, etc.
226
+ - `sn` (string): Serial number
270
227
 
271
- Contains transaction details including:
272
- - `AuthCode`: Authorization code
273
- - `RefNum`: Reference number
274
- - `ApprovedAmount`: Approved amount
275
- - `CardType`: Type of card used
276
- - `MaskedPAN`: Masked card number
277
- - `ResultCode`: Transaction result code
278
- - `ResultTxt`: Result description
279
- - And many more fields...
228
+ ### CreditTransactionType Enum
280
229
 
281
- ### BatchResponse
230
+ Available payment types:
231
+ - `CreditTransactionType.Credit` (1): Credit card transaction
232
+ - `CreditTransactionType.Debit` (2): Debit card transaction
233
+ - `CreditTransactionType.Empty` (0): Not set/default
282
234
 
283
- Contains batch settlement details including:
284
- - `BatchNum`: Batch number
285
- - `CreditCount` / `CreditAmount`: Credit transaction totals
286
- - `DebitCount` / `DebitAmount`: Debit transaction totals
287
- - `ResultCode`: Batch result code
288
- - And more batch summary fields...
235
+ See `src/type.ts` for the complete interface definition.
289
236
 
290
237
  ## Requirements
291
238
 
292
239
  - React Native 0.63+
293
- - iOS 11.0+
294
- - Android API level 21+
240
+ - **Android API level 21+ (Full support)**
241
+ - **iOS 11.0+ (Limited support - implementation pending)**
295
242
  - PAX payment terminal with POSLink SDK support
243
+ - TCP/IP network connection to PAX terminal
244
+
245
+ ## Current Platform Support
246
+
247
+ | Feature | Android | iOS |
248
+ | --------------------- | ------- | --- |
249
+ | Initialize Connection | ✅ | ❌ |
250
+ | Payment Processing | ✅ | ❌ |
251
+ | Refunds | ❌ | ❌ |
252
+ | Voids | ❌ | ❌ |
253
+ | Batch Operations | ❌ | ❌ |
296
254
 
297
255
  ## Contributing
298
256
 
@@ -5,7 +5,8 @@ buildscript {
5
5
  }
6
6
 
7
7
  dependencies {
8
- classpath "com.android.tools.build:gradle:7.2.1"
8
+ classpath("com.android.tools.build:gradle:8.3.2")
9
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
9
10
  }
10
11
  }
11
12
 
@@ -14,6 +15,7 @@ def isNewArchitectureEnabled() {
14
15
  }
15
16
 
16
17
  apply plugin: "com.android.library"
18
+ apply plugin: 'org.jetbrains.kotlin.android'
17
19
 
18
20
 
19
21
  def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
@@ -23,15 +25,19 @@ if (isNewArchitectureEnabled()) {
23
25
  }
24
26
 
25
27
  def getExtOrDefault(name) {
26
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["PaxPoslink_" + name]
28
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Default_" + name]
27
29
  }
28
30
 
29
31
  def getExtOrIntegerDefault(name) {
30
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PaxPoslink_" + name]).toInteger()
32
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Default_" + name]).toInteger()
31
33
  }
32
34
 
33
35
  android {
34
36
  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
37
+ namespace 'com.paxposlink'
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
35
41
 
36
42
  defaultConfig {
37
43
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
@@ -52,6 +58,9 @@ android {
52
58
  sourceCompatibility JavaVersion.VERSION_1_8
53
59
  targetCompatibility JavaVersion.VERSION_1_8
54
60
  }
61
+ kotlinOptions {
62
+ jvmTarget = '17'
63
+ }
55
64
 
56
65
  }
57
66
 
@@ -70,7 +79,9 @@ dependencies {
70
79
  //! https://developer.pax.us/resources/section/250038301709316096?sectionName=POSLink%202&articleId=352771637260593152
71
80
  //! POSLink_Core_Android_V2.00.07_20240914
72
81
  //! https://developer.pax.us/api/v1/files/314390436447793152/download/private#POSLink_Semi_Integration_Java_Android_V2.01.00_20240914.zip
73
- implementation files('libs/POSLink_Core.jar')
82
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
83
+ implementation 'androidx.core:core-ktx:1.16.0'
84
+ implementation 'com.google.code.gson:gson:2.11.0'
74
85
  }
75
86
 
76
87
  if (isNewArchitectureEnabled()) {
@@ -1,5 +1,8 @@
1
- PaxPoslink_kotlinVersion=1.7.0
2
- PaxPoslink_minSdkVersion=21
3
- PaxPoslink_targetSdkVersion=31
4
- PaxPoslink_compileSdkVersion=31
5
- PaxPoslink_ndkversion=21.4.7075529
1
+ Default_kotlinVersion=1.9.24
2
+ Default_minSdkVersion=21
3
+ Default_targetSdkVersion=31
4
+ Default_compileSdkVersion=31
5
+ Default_ndkversion=21.4.7075529
6
+ Default_kotlin-gradle-plugin=1.9.24
7
+
8
+ android.useAndroidX=true
@@ -0,0 +1,57 @@
1
+ package com.paxposlink
2
+
3
+ import com.facebook.react.bridge.WritableMap
4
+
5
+ object PaxPosConstant {
6
+ const val DEFAULT_ID: String = ""
7
+ const val PORT: String = "10009"
8
+ const val TIMEOUT: Int = 300000
9
+ }
10
+
11
+ // Data holder for PAX request parameters
12
+ data class PaxRequestModel(
13
+ var id: String? = "",
14
+ var amount: Int = 0,
15
+ var tip: Int? = null,
16
+ var paymentType: Int? = null,
17
+ var ecrRefNum: String = "",
18
+ )
19
+
20
+ data class PaxResponseModel(
21
+ var status: Boolean = false,
22
+ var data: WritableMap? = null,
23
+ var message: String = "",
24
+ var isPaymentSuccess: Boolean = false,
25
+ var id: String = "",
26
+ var transactionId: String = "",
27
+ var transactionNo: String = "",
28
+ var refNum: String = "",
29
+ var transactionDateTime: String = "",
30
+ var cardType: String = "",
31
+ var cardNumber: String = "",
32
+ var cardHolder: String = "",
33
+ var amount: String = "",
34
+ var tipAmount: String = "",
35
+ var surcharge: String = "",
36
+ var entryMethod: String = "",
37
+ var sn: String = "0",
38
+ )
39
+
40
+ data class PaxTerminalInfoModel(
41
+ var serialNumber: String = "",
42
+ var modelName: String = "",
43
+ var appName: String = "",
44
+ )
45
+
46
+ enum class CreditTransactionType(
47
+ val code: Int,
48
+ ) {
49
+ Credit(1),
50
+ Debit(2),
51
+ Empty(0),
52
+ ;
53
+
54
+ companion object {
55
+ fun fromCode(code: Int): CreditTransactionType = entries.find { it.code == code } ?: Empty
56
+ }
57
+ }