quivio-transaction-processor 1.22.0-beta → 1.22.2-beta
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/dist/emvPaymentProvider/EMVPaymentProvider.js +53 -30
- package/dist/emvPaymentProvider/EMVPaymentProvider.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/libs/emvCardReaderLib/src/main/AndroidManifest.xml +22 -1
- package/package.json +1 -1
- package/src/emvPaymentProvider/EMVPaymentProvider.tsx +81 -43
- package/src/index.ts +2 -0
|
@@ -39,8 +39,6 @@ var types_1 = require("./types");
|
|
|
39
39
|
var useUSBDevice_1 = require("../usb/useUSBDevice");
|
|
40
40
|
var EMVPaymentContext = (0, react_1.createContext)(undefined);
|
|
41
41
|
exports.EMVPaymentContext = EMVPaymentContext;
|
|
42
|
-
var DsiEMVManagerBridge = react_native_1.NativeModules.DsiEMVManagerBridge;
|
|
43
|
-
var emvEmitter = new react_native_1.NativeEventEmitter(DsiEMVManagerBridge);
|
|
44
42
|
var EMVPaymentProvider = function (_a) {
|
|
45
43
|
var children = _a.children;
|
|
46
44
|
var TRANSACTION_RESPONSE_EVENTS = [
|
|
@@ -49,12 +47,15 @@ var EMVPaymentProvider = function (_a) {
|
|
|
49
47
|
'onSaleTransactionCompleted',
|
|
50
48
|
'onRecurringSaleCompleted',
|
|
51
49
|
'onReplaceCardCompleted',
|
|
52
|
-
'onTransactionCancelled'
|
|
50
|
+
'onTransactionCancelled',
|
|
53
51
|
];
|
|
52
|
+
var DsiEMVManagerBridge = react_native_1.NativeModules.DsiEMVManagerBridge;
|
|
53
|
+
var eventEmitterRef = (0, react_1.useRef)(null);
|
|
54
|
+
var listenersRef = (0, react_1.useRef)({}); // Now it's an array of listeners for each event
|
|
54
55
|
// Device Connected State
|
|
55
56
|
var isDeviceConnected = (0, useUSBDevice_1.useUSBDevice)().isDeviceConnected;
|
|
56
57
|
// Show Display Message Cache
|
|
57
|
-
var _b = (0, react_1.useState)(
|
|
58
|
+
var _b = (0, react_1.useState)(''), displayMessage = _b[0], setDisplayMessage = _b[1];
|
|
58
59
|
// Device Configiured State
|
|
59
60
|
var _c = (0, react_1.useState)(false), isConfigured = _c[0], setIsConfigured = _c[1];
|
|
60
61
|
// Transaction In Progress Flag
|
|
@@ -65,8 +66,6 @@ var EMVPaymentProvider = function (_a) {
|
|
|
65
66
|
var _f = (0, react_1.useState)(false), isConfigurationInProgress = _f[0], setConfigurationInProgress = _f[1];
|
|
66
67
|
// Logs DataStructure
|
|
67
68
|
var _g = (0, react_1.useState)([]), logs = _g[0], setLogs = _g[1];
|
|
68
|
-
// Ref to maintain subscription
|
|
69
|
-
var subscriptionsRef = (0, react_1.useRef)(new Map());
|
|
70
69
|
// Ref to maintain timeout during configuration
|
|
71
70
|
// Because after a successfull EMVParamDownload
|
|
72
71
|
// Device reboots which leads to USB disconnection
|
|
@@ -110,37 +109,50 @@ var EMVPaymentProvider = function (_a) {
|
|
|
110
109
|
};
|
|
111
110
|
// Native to Provider EMV event listening
|
|
112
111
|
(0, react_1.useEffect)(function () {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
if (!DsiEMVManagerBridge) {
|
|
113
|
+
console.error('Native module DsiEMVManagerBridge not found');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
var emitter = eventEmitterRef.current ||
|
|
117
|
+
new react_native_1.NativeEventEmitter(react_native_1.Platform.OS === 'android' ? DsiEMVManagerBridge : undefined);
|
|
118
|
+
eventEmitterRef.current = emitter;
|
|
119
|
+
types_1.EVENT_NAMES.forEach(function (event) {
|
|
120
|
+
var listener = emitter.addListener(event, function (payload) {
|
|
121
|
+
console.log("React Native received event: ".concat(event), payload);
|
|
122
|
+
pushLog(event, payload);
|
|
123
|
+
if (event === 'onShowDisplayMessage') {
|
|
117
124
|
setDisplayMessage(payload);
|
|
118
125
|
}
|
|
119
|
-
if (
|
|
126
|
+
if (event === 'onConfigCompleted') {
|
|
120
127
|
setConfigurationInProgress(false);
|
|
121
128
|
setCancellationRunning(false);
|
|
122
129
|
setIsConfigured(true);
|
|
123
130
|
}
|
|
124
|
-
if (
|
|
131
|
+
if (event === 'onConfigError') {
|
|
125
132
|
setConfigurationInProgress(false);
|
|
126
133
|
setCancellationRunning(false);
|
|
127
134
|
setIsConfigured(false);
|
|
128
135
|
}
|
|
129
|
-
if (
|
|
136
|
+
if (event === 'onProcessAlreadyRunning') {
|
|
130
137
|
setCancellationRunning(false);
|
|
131
138
|
setTransactionCurrentlyRunning(true);
|
|
132
139
|
}
|
|
133
|
-
if (TRANSACTION_RESPONSE_EVENTS.includes(
|
|
140
|
+
if (TRANSACTION_RESPONSE_EVENTS.includes(event)) {
|
|
134
141
|
setTransactionCurrentlyRunning(false);
|
|
135
142
|
setCancellationRunning(false);
|
|
136
143
|
}
|
|
137
|
-
|
|
138
|
-
|
|
144
|
+
// Store the listener in the ref
|
|
145
|
+
if (!listenersRef.current[event]) {
|
|
146
|
+
listenersRef.current[event] = [];
|
|
147
|
+
}
|
|
148
|
+
listenersRef.current[event].push(listener);
|
|
139
149
|
});
|
|
140
150
|
});
|
|
141
151
|
return function () {
|
|
142
|
-
|
|
143
|
-
|
|
152
|
+
Object.values(listenersRef.current).forEach(function (eventListeners) {
|
|
153
|
+
eventListeners.forEach(function (listener) { return listener.remove(); });
|
|
154
|
+
});
|
|
155
|
+
listenersRef.current = {};
|
|
144
156
|
};
|
|
145
157
|
}, []);
|
|
146
158
|
// Exposed method to run EMV configuration
|
|
@@ -208,21 +220,32 @@ var EMVPaymentProvider = function (_a) {
|
|
|
208
220
|
};
|
|
209
221
|
// Exposed method to remove all attached listener
|
|
210
222
|
var removeAllListeners = function () {
|
|
211
|
-
subscriptionsRef.current.clear();
|
|
212
223
|
DsiEMVManagerBridge.clearTransactionListener();
|
|
224
|
+
listenersRef.current = {};
|
|
213
225
|
};
|
|
214
|
-
//
|
|
215
|
-
var subscribeToEvent = function (eventName, callback) {
|
|
216
|
-
if (
|
|
217
|
-
|
|
226
|
+
// Event subscription functions
|
|
227
|
+
var subscribeToEvent = (0, react_1.useCallback)(function (eventName, callback) {
|
|
228
|
+
if (eventEmitterRef.current) {
|
|
229
|
+
var listener = eventEmitterRef.current.addListener(eventName, callback);
|
|
230
|
+
// Store listener in the ref object
|
|
231
|
+
if (!listenersRef.current[eventName]) {
|
|
232
|
+
listenersRef.current[eventName] = [];
|
|
233
|
+
}
|
|
234
|
+
listenersRef.current[eventName].push(listener);
|
|
235
|
+
return listener; // Return listener for potential removal later
|
|
218
236
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
}, []);
|
|
238
|
+
var unsubscribeFromEvent = (0, react_1.useCallback)(function (eventName, callback) {
|
|
239
|
+
var listeners = listenersRef.current[eventName];
|
|
240
|
+
if (listeners) {
|
|
241
|
+
var listener_1 = listeners.find(function (listener) { return listener.listener === callback; });
|
|
242
|
+
if (listener_1) {
|
|
243
|
+
listener_1.remove();
|
|
244
|
+
// Remove the listener from the stored list
|
|
245
|
+
listenersRef.current[eventName] = listeners.filter(function (l) { return l !== listener_1; });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, []);
|
|
226
249
|
// EVENTS Memoization
|
|
227
250
|
var EVENTS = (0, react_1.useMemo)(function () {
|
|
228
251
|
return types_1.EVENT_NAMES.reduce(function (acc, e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EMVPaymentProvider.js","sourceRoot":"","sources":["../../src/emvPaymentProvider/EMVPaymentProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"EMVPaymentProvider.js","sourceRoot":"","sources":["../../src/emvPaymentProvider/EMVPaymentProvider.tsx"],"names":[],"mappings":";;;;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OAAO,CACL,8BAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACrC,QAAQ,CACkB,CAC9B,CAAC;AACJ,CAAC,CAAC;AAEO,gDAAkB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ import { USBDeviceProvider } from './usb/USBDeviceContext';
|
|
|
4
4
|
import { useUSBDevice } from './usb/useUSBDevice';
|
|
5
5
|
export type { EMVEventName, CallbackLog, EMVPaymentHook, EMVConfig } from './emvPaymentProvider/types';
|
|
6
6
|
export { EMVPaymentProvider, useEMVPayment, USBDeviceProvider, useUSBDevice };
|
|
7
|
+
export default EMVPaymentProvider;
|
package/dist/index.js
CHANGED
|
@@ -9,4 +9,5 @@ var USBDeviceContext_1 = require("./usb/USBDeviceContext");
|
|
|
9
9
|
Object.defineProperty(exports, "USBDeviceProvider", { enumerable: true, get: function () { return USBDeviceContext_1.USBDeviceProvider; } });
|
|
10
10
|
var useUSBDevice_1 = require("./usb/useUSBDevice");
|
|
11
11
|
Object.defineProperty(exports, "useUSBDevice", { enumerable: true, get: function () { return useUSBDevice_1.useUSBDevice; } });
|
|
12
|
+
exports.default = EMVPaymentProvider_1.EMVPaymentProvider;
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8EAA6E;AASzE,mGATK,uCAAkB,OASL;AARtB,oEAAmE;AAS/D,8FATK,6BAAa,OASL;AAPjB,2DAA2D;AAQvD,kGARK,oCAAiB,OAQL;AAPrB,mDAAkD;AAQ9C,6FARK,2BAAY,OAQL"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8EAA6E;AASzE,mGATK,uCAAkB,OASL;AARtB,oEAAmE;AAS/D,8FATK,6BAAa,OASL;AAPjB,2DAA2D;AAQvD,kGARK,oCAAiB,OAQL;AAPrB,mDAAkD;AAQ9C,6FARK,2BAAY,OAQL;AAGhB,kBAAe,uCAAkB,CAAC"}
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
xmlns:tools="http://schemas.android.com/tools">
|
|
3
4
|
|
|
5
|
+
<!-- optional: advertise USB host feature but don't force Play Store filtering -->
|
|
6
|
+
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
|
|
7
|
+
|
|
8
|
+
<!-- any permissions your receiver/native code needs -->
|
|
9
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
10
|
+
<uses-permission android:name="com.pax.permission.RECV_BOOT_COMPLETED" />
|
|
11
|
+
<uses-permission android:name="com.pax.permission.PAX_START_ACTIVITIES_FROM_BACKGROUND" />
|
|
12
|
+
|
|
13
|
+
<application>
|
|
14
|
+
<!-- BroadcastReceiver that listens for USB attach/detach -->
|
|
15
|
+
<receiver
|
|
16
|
+
android:name=".usb.UsbDeviceReceiver"
|
|
17
|
+
android:exported="true"
|
|
18
|
+
android:enabled="true">
|
|
19
|
+
<intent-filter>
|
|
20
|
+
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
|
21
|
+
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
|
|
22
|
+
</intent-filter>
|
|
23
|
+
</receiver>
|
|
24
|
+
</application>
|
|
4
25
|
</manifest>
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
createContext,
|
|
3
|
+
useCallback,
|
|
3
4
|
useEffect,
|
|
4
5
|
useMemo,
|
|
5
6
|
useRef,
|
|
6
7
|
useState,
|
|
7
8
|
} from 'react';
|
|
8
|
-
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
9
|
+
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
9
10
|
import {
|
|
10
11
|
EMVPaymentContextType,
|
|
11
12
|
EMVEventName,
|
|
@@ -19,9 +20,6 @@ const EMVPaymentContext = createContext<EMVPaymentContextType | undefined>(
|
|
|
19
20
|
undefined,
|
|
20
21
|
);
|
|
21
22
|
|
|
22
|
-
const { DsiEMVManagerBridge } = NativeModules;
|
|
23
|
-
const emvEmitter = new NativeEventEmitter(DsiEMVManagerBridge);
|
|
24
|
-
|
|
25
23
|
const EMVPaymentProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
26
24
|
children,
|
|
27
25
|
}) => {
|
|
@@ -31,14 +29,17 @@ const EMVPaymentProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
31
29
|
'onSaleTransactionCompleted',
|
|
32
30
|
'onRecurringSaleCompleted',
|
|
33
31
|
'onReplaceCardCompleted',
|
|
34
|
-
'onTransactionCancelled'
|
|
32
|
+
'onTransactionCancelled',
|
|
35
33
|
];
|
|
34
|
+
const { DsiEMVManagerBridge } = NativeModules;
|
|
35
|
+
const eventEmitterRef = useRef<NativeEventEmitter | null>(null);
|
|
36
|
+
const listenersRef = useRef<{ [event: string]: any[] }>({}); // Now it's an array of listeners for each event
|
|
36
37
|
|
|
37
38
|
// Device Connected State
|
|
38
39
|
const { isDeviceConnected } = useUSBDevice();
|
|
39
40
|
|
|
40
41
|
// Show Display Message Cache
|
|
41
|
-
const [
|
|
42
|
+
const [displayMessage, setDisplayMessage] = useState('');
|
|
42
43
|
|
|
43
44
|
// Device Configiured State
|
|
44
45
|
const [isConfigured, setIsConfigured] = useState(false);
|
|
@@ -57,10 +58,6 @@ const EMVPaymentProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
57
58
|
// Logs DataStructure
|
|
58
59
|
const [logs, setLogs] = useState<CallbackLog[]>([]);
|
|
59
60
|
|
|
60
|
-
// Ref to maintain subscription
|
|
61
|
-
const subscriptionsRef = useRef<
|
|
62
|
-
Map<EMVEventName, Set<(payload: any) => void>>
|
|
63
|
-
>(new Map());
|
|
64
61
|
|
|
65
62
|
// Ref to maintain timeout during configuration
|
|
66
63
|
// Because after a successfull EMVParamDownload
|
|
@@ -114,44 +111,63 @@ const EMVPaymentProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
114
111
|
|
|
115
112
|
// Native to Provider EMV event listening
|
|
116
113
|
useEffect(() => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
if (!DsiEMVManagerBridge) {
|
|
115
|
+
console.error('Native module DsiEMVManagerBridge not found');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const emitter =
|
|
120
|
+
eventEmitterRef.current ||
|
|
121
|
+
new NativeEventEmitter(
|
|
122
|
+
Platform.OS === 'android' ? DsiEMVManagerBridge : undefined,
|
|
123
|
+
);
|
|
124
|
+
eventEmitterRef.current = emitter;
|
|
125
|
+
|
|
126
|
+
EVENT_NAMES.forEach(event => {
|
|
127
|
+
const listener = emitter.addListener(event, (payload: any) => {
|
|
128
|
+
console.log(`React Native received event: ${event}`, payload);
|
|
120
129
|
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
pushLog(event, payload);
|
|
131
|
+
|
|
132
|
+
if (event === 'onShowDisplayMessage') {
|
|
133
|
+
setDisplayMessage(payload);
|
|
123
134
|
}
|
|
124
135
|
|
|
125
|
-
if (
|
|
136
|
+
if (event === 'onConfigCompleted') {
|
|
126
137
|
setConfigurationInProgress(false);
|
|
127
138
|
setCancellationRunning(false);
|
|
128
139
|
setIsConfigured(true);
|
|
129
140
|
}
|
|
130
141
|
|
|
131
|
-
if (
|
|
142
|
+
if (event === 'onConfigError') {
|
|
132
143
|
setConfigurationInProgress(false);
|
|
133
144
|
setCancellationRunning(false);
|
|
134
145
|
setIsConfigured(false);
|
|
135
146
|
}
|
|
136
147
|
|
|
137
|
-
if (
|
|
148
|
+
if (event === 'onProcessAlreadyRunning') {
|
|
138
149
|
setCancellationRunning(false);
|
|
139
150
|
setTransactionCurrentlyRunning(true);
|
|
140
151
|
}
|
|
141
152
|
|
|
142
|
-
if (TRANSACTION_RESPONSE_EVENTS.includes(
|
|
153
|
+
if (TRANSACTION_RESPONSE_EVENTS.includes(event)) {
|
|
143
154
|
setTransactionCurrentlyRunning(false);
|
|
144
155
|
setCancellationRunning(false);
|
|
145
156
|
}
|
|
146
157
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
// Store the listener in the ref
|
|
159
|
+
if (!listenersRef.current[event]) {
|
|
160
|
+
listenersRef.current[event] = [];
|
|
161
|
+
}
|
|
162
|
+
listenersRef.current[event].push(listener);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
151
165
|
|
|
152
166
|
return () => {
|
|
153
|
-
|
|
154
|
-
|
|
167
|
+
Object.values(listenersRef.current).forEach(eventListeners => {
|
|
168
|
+
eventListeners.forEach(listener => listener.remove());
|
|
169
|
+
});
|
|
170
|
+
listenersRef.current = {};
|
|
155
171
|
};
|
|
156
172
|
}, []);
|
|
157
173
|
|
|
@@ -233,28 +249,50 @@ const EMVPaymentProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
233
249
|
|
|
234
250
|
// Exposed method to remove all attached listener
|
|
235
251
|
const removeAllListeners = () => {
|
|
236
|
-
subscriptionsRef.current.clear();
|
|
237
252
|
DsiEMVManagerBridge.clearTransactionListener();
|
|
253
|
+
listenersRef.current = {};
|
|
238
254
|
};
|
|
239
255
|
|
|
240
|
-
//
|
|
241
|
-
const subscribeToEvent = (
|
|
242
|
-
eventName:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
256
|
+
// Event subscription functions
|
|
257
|
+
const subscribeToEvent = useCallback(
|
|
258
|
+
(eventName: string, callback: (payload: any) => void) => {
|
|
259
|
+
if (eventEmitterRef.current) {
|
|
260
|
+
const listener = eventEmitterRef.current.addListener(
|
|
261
|
+
eventName,
|
|
262
|
+
callback,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
// Store listener in the ref object
|
|
266
|
+
if (!listenersRef.current[eventName]) {
|
|
267
|
+
listenersRef.current[eventName] = [];
|
|
268
|
+
}
|
|
269
|
+
listenersRef.current[eventName].push(listener);
|
|
250
270
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
|
|
271
|
+
return listener; // Return listener for potential removal later
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
[],
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const unsubscribeFromEvent = useCallback(
|
|
278
|
+
(eventName: string, callback: (payload: any) => void) => {
|
|
279
|
+
const listeners = listenersRef.current[eventName];
|
|
280
|
+
if (listeners) {
|
|
281
|
+
const listener = listeners.find(
|
|
282
|
+
listener => listener.listener === callback,
|
|
283
|
+
);
|
|
284
|
+
if (listener) {
|
|
285
|
+
listener.remove();
|
|
286
|
+
|
|
287
|
+
// Remove the listener from the stored list
|
|
288
|
+
listenersRef.current[eventName] = listeners.filter(
|
|
289
|
+
l => l !== listener,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
[],
|
|
295
|
+
);
|
|
258
296
|
|
|
259
297
|
// EVENTS Memoization
|
|
260
298
|
const EVENTS = useMemo(
|