@padosoft/react-native-ecr17 0.0.0 → 2.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.
- package/Ecr17.podspec +39 -39
- package/README.md +348 -348
- package/android/CMakeLists.txt +41 -41
- package/android/build.gradle +148 -148
- package/android/fix-prefab.gradle +50 -50
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/cpp/cpp-adapter.cpp +8 -8
- package/android/src/main/java/com/margelo/nitro/ecr17/HybridEcr17Transport.kt +233 -233
- package/android/src/main/java/com/padosoft/ecr17/Ecr17Package.kt +30 -30
- package/cpp/Ecr17.hpp +1 -1
- package/cpp/Ecr17Client/HybridEcr17Client.cpp +598 -598
- package/cpp/Ecr17Client/HybridEcr17Client.hpp +85 -85
- package/cpp/Ecr17Protocol/Ecr17Protocol.cpp +277 -277
- package/cpp/Ecr17Protocol/Ecr17Protocol.hpp +103 -103
- package/cpp/Ecr17Response/Ecr17Response.cpp +155 -155
- package/cpp/Ecr17Response/Ecr17Response.hpp +113 -113
- package/cpp/Lcr/Lcr.cpp +42 -42
- package/cpp/Lcr/Lcr.hpp +21 -21
- package/cpp/PacketCodec/PacketCodec.cpp +145 -145
- package/cpp/PacketCodec/PacketCodec.hpp +47 -47
- package/cpp/Session/Ecr17Session.cpp +260 -260
- package/cpp/Session/Ecr17Session.hpp +97 -97
- package/cpp/Session/RetryPolicy.hpp +23 -23
- package/cpp/Transport/FakeTransport.hpp +95 -95
- package/cpp/Transport/NativeTransportAdapter.cpp +42 -42
- package/cpp/Transport/NativeTransportAdapter.hpp +32 -32
- package/cpp/Transport/Transport.hpp +30 -30
- package/cpp/tests/CMakeLists.txt +55 -55
- package/cpp/tests/PosixTcpTransport.hpp +105 -105
- package/cpp/tests/stubs/LrcMode.hpp +25 -25
- package/cpp/tests/test_flows.cpp +148 -148
- package/cpp/tests/test_integration_terminal.cpp +72 -72
- package/cpp/tests/test_lrc.cpp +66 -66
- package/cpp/tests/test_packet_codec.cpp +164 -164
- package/cpp/tests/test_protocol.cpp +102 -102
- package/cpp/tests/test_protocol_commands.cpp +190 -190
- package/cpp/tests/test_response.cpp +164 -164
- package/cpp/tests/test_retry_policy.cpp +28 -28
- package/cpp/tests/test_session.cpp +262 -262
- package/ios/HybridEcr17Transport.swift +103 -103
- package/lib/commonjs/index.js +50 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/client.nitro.js +17 -0
- package/lib/commonjs/specs/client.nitro.js.map +1 -0
- package/lib/commonjs/specs/transport.nitro.js +6 -0
- package/lib/commonjs/specs/transport.nitro.js.map +1 -0
- package/lib/commonjs/types/client.js +2 -0
- package/lib/commonjs/types/client.js.map +1 -0
- package/lib/commonjs/utils/client.js +13 -0
- package/lib/commonjs/utils/client.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/client.nitro.js +13 -0
- package/lib/module/specs/client.nitro.js.map +1 -0
- package/lib/module/specs/transport.nitro.js +4 -0
- package/lib/module/specs/transport.nitro.js.map +1 -0
- package/lib/module/types/client.js +2 -0
- package/lib/module/types/client.js.map +1 -0
- package/lib/module/utils/client.js +9 -0
- package/lib/module/utils/client.js.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/client.nitro.d.ts +63 -0
- package/lib/typescript/src/specs/client.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/transport.nitro.d.ts +13 -0
- package/lib/typescript/src/specs/transport.nitro.d.ts.map +1 -0
- package/lib/typescript/src/types/client.d.ts +138 -0
- package/lib/typescript/src/types/client.d.ts.map +1 -0
- package/lib/typescript/src/utils/client.d.ts +3 -0
- package/lib/typescript/src/utils/client.d.ts.map +1 -0
- package/nitro.json +30 -30
- package/package.json +4 -4
- package/react-native.config.js +18 -18
- package/src/index.ts +4 -4
- package/src/specs/client.nitro.ts +102 -102
- package/src/specs/transport.nitro.ts +25 -25
- package/src/types/client.ts +196 -196
- package/src/utils/client.ts +10 -10
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <NitroModules/Promise.hpp>
|
|
4
|
-
|
|
5
|
-
#include <memory>
|
|
6
|
-
#include <mutex>
|
|
7
|
-
|
|
8
|
-
#include "HybridEcr17ClientSpec.hpp"
|
|
9
|
-
#include "HybridEcr17TransportSpec.hpp"
|
|
10
|
-
#include "Session/Ecr17Session.hpp"
|
|
11
|
-
#include "Transport/NativeTransportAdapter.hpp"
|
|
12
|
-
|
|
13
|
-
namespace margelo::nitro::ecr17 {
|
|
14
|
-
|
|
15
|
-
class HybridEcr17Client : public HybridEcr17ClientSpec {
|
|
16
|
-
public:
|
|
17
|
-
HybridEcr17Client() : HybridObject(TAG) {}
|
|
18
|
-
|
|
19
|
-
// --- Configuration (synchronous) ---
|
|
20
|
-
void configure(const Ecr17Config& config) override;
|
|
21
|
-
Ecr17Config configuration() override;
|
|
22
|
-
|
|
23
|
-
// --- Connection ---
|
|
24
|
-
std::shared_ptr<margelo::nitro::Promise<void>> connect() override;
|
|
25
|
-
void disconnect() override;
|
|
26
|
-
bool isConnected() override;
|
|
27
|
-
|
|
28
|
-
// --- Commands ---
|
|
29
|
-
std::shared_ptr<margelo::nitro::Promise<PosStatusResponse>> status() override;
|
|
30
|
-
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> pay(const PaymentRequest& request) override;
|
|
31
|
-
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> payExtended(const PaymentRequest& request) override;
|
|
32
|
-
std::shared_ptr<margelo::nitro::Promise<ReversalResult>> reverse(const ReversalRequest& request) override;
|
|
33
|
-
std::shared_ptr<margelo::nitro::Promise<PreAuthResult>> preAuth(const PreAuthRequest& request) override;
|
|
34
|
-
std::shared_ptr<margelo::nitro::Promise<PreAuthResult>> incrementalAuth(const IncrementalAuthRequest& request) override;
|
|
35
|
-
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> preAuthClosure(const PreAuthClosureRequest& request) override;
|
|
36
|
-
std::shared_ptr<margelo::nitro::Promise<CardVerificationResult>> verifyCard(const CardVerificationRequest& request) override;
|
|
37
|
-
std::shared_ptr<margelo::nitro::Promise<CloseSessionResult>> closeSession() override;
|
|
38
|
-
std::shared_ptr<margelo::nitro::Promise<TotalsResult>> totals() override;
|
|
39
|
-
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> sendLastResult() override;
|
|
40
|
-
std::shared_ptr<margelo::nitro::Promise<void>> enableEcrPrinting(bool enabled) override;
|
|
41
|
-
std::shared_ptr<margelo::nitro::Promise<void>> reprint(bool toEcr) override;
|
|
42
|
-
std::shared_ptr<margelo::nitro::Promise<VasResult>> vas(const std::string& xmlRequest) override;
|
|
43
|
-
|
|
44
|
-
// --- Events ---
|
|
45
|
-
void setOnProgress(const std::function<void(const ProgressEvent&)>& callback) override;
|
|
46
|
-
void setOnReceiptLine(const std::function<void(const ReceiptLine&)>& callback) override;
|
|
47
|
-
void setOnConnectionStateChange(const std::function<void(ConnectionState)>& callback) override;
|
|
48
|
-
|
|
49
|
-
protected:
|
|
50
|
-
// Lazily creates the native transport (via the Nitro registry), the adapter
|
|
51
|
-
// and the session, and wires session events to the JS callbacks.
|
|
52
|
-
void ensureInit();
|
|
53
|
-
// Ensures an open connection, auto-connecting (and blocking the worker
|
|
54
|
-
// thread until ready) if needed. Throws if the connection fails.
|
|
55
|
-
void ensureConnected();
|
|
56
|
-
std::string cashRegisterIdOr(const std::optional<std::string>& override) const;
|
|
57
|
-
// Runs a transaction, attaching the tokenization 'U' additional-data message
|
|
58
|
-
// when `tokenization` is set (request must be built with withAdditionalData=true).
|
|
59
|
-
// On a mid-command disconnect with autoReconnect enabled, the socket is
|
|
60
|
-
// reconnected; the command is retried ONLY if `safeToRetry` (read-only ops),
|
|
61
|
-
// never for financial ops (a blind retry could double-charge — recover via
|
|
62
|
-
// sendLastResult / 'G' instead).
|
|
63
|
-
DecodedPacket runTransaction(const std::string& mainPayload,
|
|
64
|
-
const std::optional<TokenizationRequest>& tokenization,
|
|
65
|
-
bool safeToRetry);
|
|
66
|
-
void runAckOnly(const std::string& payload, bool safeToRetry);
|
|
67
|
-
|
|
68
|
-
Ecr17Config config_;
|
|
69
|
-
|
|
70
|
-
// Serializes protocol exchanges: every public command runs on a Promise
|
|
71
|
-
// worker thread but they share one session_/transport_ and RX buffer, so
|
|
72
|
-
// concurrent commands must not interleave on the wire (or ACK each other's
|
|
73
|
-
// frames). Held for the duration of a single transaction's exchange.
|
|
74
|
-
std::mutex txMutex_;
|
|
75
|
-
|
|
76
|
-
std::shared_ptr<HybridEcr17TransportSpec> transport_;
|
|
77
|
-
std::shared_ptr<NativeTransportAdapter> adapter_;
|
|
78
|
-
std::unique_ptr<Ecr17Session> session_;
|
|
79
|
-
|
|
80
|
-
std::function<void(const ProgressEvent&)> onProgress_{};
|
|
81
|
-
std::function<void(const ReceiptLine&)> onReceiptLine_{};
|
|
82
|
-
std::function<void(ConnectionState)> onConnectionStateChange_{};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
} // namespace margelo::nitro::ecr17
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <NitroModules/Promise.hpp>
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <mutex>
|
|
7
|
+
|
|
8
|
+
#include "HybridEcr17ClientSpec.hpp"
|
|
9
|
+
#include "HybridEcr17TransportSpec.hpp"
|
|
10
|
+
#include "Session/Ecr17Session.hpp"
|
|
11
|
+
#include "Transport/NativeTransportAdapter.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::ecr17 {
|
|
14
|
+
|
|
15
|
+
class HybridEcr17Client : public HybridEcr17ClientSpec {
|
|
16
|
+
public:
|
|
17
|
+
HybridEcr17Client() : HybridObject(TAG) {}
|
|
18
|
+
|
|
19
|
+
// --- Configuration (synchronous) ---
|
|
20
|
+
void configure(const Ecr17Config& config) override;
|
|
21
|
+
Ecr17Config configuration() override;
|
|
22
|
+
|
|
23
|
+
// --- Connection ---
|
|
24
|
+
std::shared_ptr<margelo::nitro::Promise<void>> connect() override;
|
|
25
|
+
void disconnect() override;
|
|
26
|
+
bool isConnected() override;
|
|
27
|
+
|
|
28
|
+
// --- Commands ---
|
|
29
|
+
std::shared_ptr<margelo::nitro::Promise<PosStatusResponse>> status() override;
|
|
30
|
+
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> pay(const PaymentRequest& request) override;
|
|
31
|
+
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> payExtended(const PaymentRequest& request) override;
|
|
32
|
+
std::shared_ptr<margelo::nitro::Promise<ReversalResult>> reverse(const ReversalRequest& request) override;
|
|
33
|
+
std::shared_ptr<margelo::nitro::Promise<PreAuthResult>> preAuth(const PreAuthRequest& request) override;
|
|
34
|
+
std::shared_ptr<margelo::nitro::Promise<PreAuthResult>> incrementalAuth(const IncrementalAuthRequest& request) override;
|
|
35
|
+
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> preAuthClosure(const PreAuthClosureRequest& request) override;
|
|
36
|
+
std::shared_ptr<margelo::nitro::Promise<CardVerificationResult>> verifyCard(const CardVerificationRequest& request) override;
|
|
37
|
+
std::shared_ptr<margelo::nitro::Promise<CloseSessionResult>> closeSession() override;
|
|
38
|
+
std::shared_ptr<margelo::nitro::Promise<TotalsResult>> totals() override;
|
|
39
|
+
std::shared_ptr<margelo::nitro::Promise<PaymentResult>> sendLastResult() override;
|
|
40
|
+
std::shared_ptr<margelo::nitro::Promise<void>> enableEcrPrinting(bool enabled) override;
|
|
41
|
+
std::shared_ptr<margelo::nitro::Promise<void>> reprint(bool toEcr) override;
|
|
42
|
+
std::shared_ptr<margelo::nitro::Promise<VasResult>> vas(const std::string& xmlRequest) override;
|
|
43
|
+
|
|
44
|
+
// --- Events ---
|
|
45
|
+
void setOnProgress(const std::function<void(const ProgressEvent&)>& callback) override;
|
|
46
|
+
void setOnReceiptLine(const std::function<void(const ReceiptLine&)>& callback) override;
|
|
47
|
+
void setOnConnectionStateChange(const std::function<void(ConnectionState)>& callback) override;
|
|
48
|
+
|
|
49
|
+
protected:
|
|
50
|
+
// Lazily creates the native transport (via the Nitro registry), the adapter
|
|
51
|
+
// and the session, and wires session events to the JS callbacks.
|
|
52
|
+
void ensureInit();
|
|
53
|
+
// Ensures an open connection, auto-connecting (and blocking the worker
|
|
54
|
+
// thread until ready) if needed. Throws if the connection fails.
|
|
55
|
+
void ensureConnected();
|
|
56
|
+
std::string cashRegisterIdOr(const std::optional<std::string>& override) const;
|
|
57
|
+
// Runs a transaction, attaching the tokenization 'U' additional-data message
|
|
58
|
+
// when `tokenization` is set (request must be built with withAdditionalData=true).
|
|
59
|
+
// On a mid-command disconnect with autoReconnect enabled, the socket is
|
|
60
|
+
// reconnected; the command is retried ONLY if `safeToRetry` (read-only ops),
|
|
61
|
+
// never for financial ops (a blind retry could double-charge — recover via
|
|
62
|
+
// sendLastResult / 'G' instead).
|
|
63
|
+
DecodedPacket runTransaction(const std::string& mainPayload,
|
|
64
|
+
const std::optional<TokenizationRequest>& tokenization,
|
|
65
|
+
bool safeToRetry);
|
|
66
|
+
void runAckOnly(const std::string& payload, bool safeToRetry);
|
|
67
|
+
|
|
68
|
+
Ecr17Config config_;
|
|
69
|
+
|
|
70
|
+
// Serializes protocol exchanges: every public command runs on a Promise
|
|
71
|
+
// worker thread but they share one session_/transport_ and RX buffer, so
|
|
72
|
+
// concurrent commands must not interleave on the wire (or ACK each other's
|
|
73
|
+
// frames). Held for the duration of a single transaction's exchange.
|
|
74
|
+
std::mutex txMutex_;
|
|
75
|
+
|
|
76
|
+
std::shared_ptr<HybridEcr17TransportSpec> transport_;
|
|
77
|
+
std::shared_ptr<NativeTransportAdapter> adapter_;
|
|
78
|
+
std::unique_ptr<Ecr17Session> session_;
|
|
79
|
+
|
|
80
|
+
std::function<void(const ProgressEvent&)> onProgress_{};
|
|
81
|
+
std::function<void(const ReceiptLine&)> onReceiptLine_{};
|
|
82
|
+
std::function<void(ConnectionState)> onConnectionStateChange_{};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro::ecr17
|