nets-service-sdk 1.0.1 → 1.1.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 +78 -2
- package/dist/index.js +1406 -2
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# NETS Service SDK
|
|
2
2
|
|
|
3
|
-
A utility library for integrating with NETS payment terminals and handling related operations. This SDK provides tools for serial communication, message parsing, configuration management, and common utility functions.
|
|
3
|
+
A utility library for integrating with NETS payment terminals and handling related operations. This SDK provides tools for serial communication, message parsing, configuration management, transaction storage, and common utility functions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔌 Serial communication with NETS payment terminals
|
|
8
|
+
- 💾 SQLite-based transaction storage with automatic purging
|
|
9
|
+
- 📝 Comprehensive logging with Winston
|
|
10
|
+
- 🔧 Configuration management
|
|
11
|
+
- 🛠️ Utility functions for payment processing
|
|
4
12
|
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
@@ -53,10 +61,67 @@ communication.sentToTerminal('STATUS_CHECK', {});
|
|
|
53
61
|
// For Payment
|
|
54
62
|
communication.sentToTerminal('PAYMENT', {
|
|
55
63
|
amount: 1000, // Amount in cents
|
|
56
|
-
reference: 'ORDER123'
|
|
64
|
+
reference: 'ORDER123',
|
|
65
|
+
ecn: '040126003000'
|
|
57
66
|
});
|
|
58
67
|
```
|
|
59
68
|
|
|
69
|
+
### Transaction Storage (New in v1.1.0)
|
|
70
|
+
|
|
71
|
+
All terminal requests and responses are automatically stored in a SQLite database.
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
const sdk = require('nets-service-sdk');
|
|
75
|
+
|
|
76
|
+
// Query specific transaction by ECN
|
|
77
|
+
const transaction = sdk.getTransactionByEcn('040126003000');
|
|
78
|
+
console.log(transaction);
|
|
79
|
+
// {
|
|
80
|
+
// ecn: '040126003000',
|
|
81
|
+
// request_type: 'PAYMENT',
|
|
82
|
+
// request_payload: { amount: 10.50, reference: 'ORDER123' },
|
|
83
|
+
// response_data: { status: 'APPROVED', ... },
|
|
84
|
+
// status: 'APPROVED',
|
|
85
|
+
// ...
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// Get recent transactions
|
|
89
|
+
const recent = sdk.getRecentTransactions(50);
|
|
90
|
+
|
|
91
|
+
// Query by status
|
|
92
|
+
const approved = sdk.getTransactionsByStatus('APPROVED', 100);
|
|
93
|
+
const pending = sdk.getTransactionsByStatus('PENDING', 100);
|
|
94
|
+
|
|
95
|
+
// Manual cleanup (delete old transactions)
|
|
96
|
+
const deleted = sdk.cleanupOldTransactions(90); // Keep last 90 days
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Automatic Data Purging (New in v1.1.0)
|
|
100
|
+
|
|
101
|
+
The SDK automatically purges old transaction data weekly.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
const sdk = require('nets-service-sdk');
|
|
105
|
+
|
|
106
|
+
// Auto-purge is enabled by default
|
|
107
|
+
// Default: Every Sunday at 2 AM, keeps last 7 days
|
|
108
|
+
|
|
109
|
+
// Start with custom settings
|
|
110
|
+
sdk.startAutoPurge(14, '0 3 * * *'); // Keep 14 days, run daily at 3 AM
|
|
111
|
+
|
|
112
|
+
// Stop auto-purge
|
|
113
|
+
sdk.stopAutoPurge();
|
|
114
|
+
|
|
115
|
+
// Check if auto-purge is running
|
|
116
|
+
const isRunning = sdk.isAutoPurgeRunning();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Cron Schedule Examples:**
|
|
120
|
+
- `'0 2 * * 0'` - Every Sunday at 2 AM (default)
|
|
121
|
+
- `'0 3 * * *'` - Every day at 3 AM
|
|
122
|
+
- `'0 */6 * * *'` - Every 6 hours
|
|
123
|
+
- `'0 0 1 * *'` - First day of every month
|
|
124
|
+
|
|
60
125
|
### Utility Functions
|
|
61
126
|
|
|
62
127
|
The SDK exports various utility functions directly.
|
|
@@ -96,6 +161,17 @@ myLogger.error('This is an error message');
|
|
|
96
161
|
- **sendMessage**: Helper for sending messages (e.g., to socket rooms).
|
|
97
162
|
- **hexRequest**: Generates HEX requests for the terminal.
|
|
98
163
|
- **parser**: Parses responses from the terminal.
|
|
164
|
+
- **Transaction Storage**: SQLite-based storage for request/response tracking.
|
|
165
|
+
- **Auto-Purge**: Automatic cleanup of old transaction data.
|
|
166
|
+
|
|
167
|
+
## Database
|
|
168
|
+
|
|
169
|
+
The SDK creates a `transactions.db` SQLite database in your project root to store all terminal transactions. This provides:
|
|
170
|
+
|
|
171
|
+
- Complete audit trail of all requests and responses
|
|
172
|
+
- Debugging capabilities with full hex data
|
|
173
|
+
- Transaction reconciliation
|
|
174
|
+
- Automatic weekly cleanup (configurable)
|
|
99
175
|
|
|
100
176
|
## License
|
|
101
177
|
|