@payware/mcp-server 1.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.
Files changed (106) hide show
  1. package/.env.example +92 -0
  2. package/MCP-SETUP.md +190 -0
  3. package/README.md +483 -0
  4. package/check-keys.js +52 -0
  5. package/keys/README.md +112 -0
  6. package/mcp-config.json +9 -0
  7. package/package.json +66 -0
  8. package/payware-mcp-config.json +12 -0
  9. package/src/auth/rsa-keys.js +82 -0
  10. package/src/auth/sandbox-setup.js +187 -0
  11. package/src/config/env.js +229 -0
  12. package/src/config/partner-types.js +143 -0
  13. package/src/core/auth/jwt-factory.js +182 -0
  14. package/src/core/auth/jwt-token.js +735 -0
  15. package/src/core/utils/json-serializer.js +100 -0
  16. package/src/core/utils/key-utils.js +133 -0
  17. package/src/index.js +237 -0
  18. package/src/isv/data/index.js +291 -0
  19. package/src/isv/deep-links/delete-product-link.js +154 -0
  20. package/src/isv/deep-links/delete-transaction-link.js +154 -0
  21. package/src/isv/deep-links/get-product-link.js +167 -0
  22. package/src/isv/deep-links/get-transaction-link.js +167 -0
  23. package/src/isv/deep-links/index.js +23 -0
  24. package/src/isv/index.js +103 -0
  25. package/src/isv/oauth2/create-token-simple.js +46 -0
  26. package/src/isv/oauth2/get-token-info.js +157 -0
  27. package/src/isv/oauth2/obtain-token.js +189 -0
  28. package/src/isv/oauth2/token-helper.js +151 -0
  29. package/src/isv/products/audios.js +470 -0
  30. package/src/isv/products/create-product.js +314 -0
  31. package/src/isv/products/delete-product.js +119 -0
  32. package/src/isv/products/get-product-image.js +247 -0
  33. package/src/isv/products/get-product.js +168 -0
  34. package/src/isv/products/index.js +65 -0
  35. package/src/isv/products/list-products.js +136 -0
  36. package/src/isv/products/schedules.js +522 -0
  37. package/src/isv/products/update-product.js +265 -0
  38. package/src/isv/transactions/cancel-transaction.js +129 -0
  39. package/src/isv/transactions/create-transaction.js +361 -0
  40. package/src/isv/transactions/get-status.js +217 -0
  41. package/src/isv/transactions/process-transaction.js +145 -0
  42. package/src/isv/transactions/simulate-callback.js +146 -0
  43. package/src/isv/transactions/transaction-history.js +186 -0
  44. package/src/isv/utils/auth.js +159 -0
  45. package/src/mcp-proxy.js +150 -0
  46. package/src/merchant/data/export-report.js +108 -0
  47. package/src/merchant/data/generate-report.js +151 -0
  48. package/src/merchant/data/get-report-status.js +120 -0
  49. package/src/merchant/data/index.js +351 -0
  50. package/src/merchant/deep-links/delete-product-link.js +121 -0
  51. package/src/merchant/deep-links/delete-transaction-link.js +121 -0
  52. package/src/merchant/deep-links/get-product-link.js +134 -0
  53. package/src/merchant/deep-links/get-transaction-link.js +134 -0
  54. package/src/merchant/deep-links/index.js +23 -0
  55. package/src/merchant/index.js +92 -0
  56. package/src/merchant/products/audios.js +606 -0
  57. package/src/merchant/products/create-product.js +288 -0
  58. package/src/merchant/products/delete-product.js +111 -0
  59. package/src/merchant/products/get-product-image.js +252 -0
  60. package/src/merchant/products/get-product.js +144 -0
  61. package/src/merchant/products/index.js +65 -0
  62. package/src/merchant/products/list-products.js +112 -0
  63. package/src/merchant/products/schedules.js +646 -0
  64. package/src/merchant/products/update-product.js +282 -0
  65. package/src/merchant/transactions/cancel-transaction.js +241 -0
  66. package/src/merchant/transactions/create-transaction.js +482 -0
  67. package/src/merchant/transactions/get-status.js +196 -0
  68. package/src/merchant/transactions/process-transaction.js +349 -0
  69. package/src/merchant/transactions/simulate-callback.js +246 -0
  70. package/src/merchant/transactions/transaction-history.js +258 -0
  71. package/src/payment-institution/data/index.js +280 -0
  72. package/src/payment-institution/deep-links/delete-transaction-link.js +128 -0
  73. package/src/payment-institution/deep-links/get-transaction-link.js +141 -0
  74. package/src/payment-institution/deep-links/index.js +17 -0
  75. package/src/payment-institution/index.js +92 -0
  76. package/src/payment-institution/transactions/create-pi-transaction.js +484 -0
  77. package/src/payment-institution/transactions/finalize-transaction.js +340 -0
  78. package/src/payment-institution/transactions/get-transaction-history.js +269 -0
  79. package/src/payment-institution/transactions/get-transaction-status.js +234 -0
  80. package/src/payment-institution/transactions/process-pi-transaction.js +421 -0
  81. package/src/payment-institution/transactions/simulate-pi-callback.js +326 -0
  82. package/src/payment-institution/transactions/soundbite-transaction.js +269 -0
  83. package/src/proxy-server.js +205 -0
  84. package/src/shared/data/data-api.js +372 -0
  85. package/src/shared/deep-links/api.js +214 -0
  86. package/src/shared/index.js +44 -0
  87. package/src/shared/products/products-api.js +872 -0
  88. package/src/tools/advanced-code-generator.js +2247 -0
  89. package/src/utils/code-examples/common/auth-examples.js +1482 -0
  90. package/src/utils/code-examples/common/helpers.js +416 -0
  91. package/src/utils/code-examples/common/utils-examples.js +591 -0
  92. package/src/utils/code-examples/frameworks/examples.js +859 -0
  93. package/src/utils/code-examples/index.js +441 -0
  94. package/src/utils/code-examples/isv/oauth2.js +600 -0
  95. package/src/utils/code-examples/isv/products.js +666 -0
  96. package/src/utils/code-examples/isv/transactions.js +813 -0
  97. package/src/utils/code-examples/merchant/products.js +497 -0
  98. package/src/utils/code-examples/merchant/transactions.js +623 -0
  99. package/src/utils/code-examples/payment-institution/transactions.js +388 -0
  100. package/src/utils/code-examples/shared/data.js +607 -0
  101. package/src/utils/code-examples/shared/deep-links.js +662 -0
  102. package/src/utils/code-examples/shared/soundbites.js +808 -0
  103. package/src/utils/code-examples.js +646 -0
  104. package/src/utils/format-request.js +363 -0
  105. package/src/utils/json-formatter.js +249 -0
  106. package/src/utils/server-info.js +132 -0
package/README.md ADDED
@@ -0,0 +1,483 @@
1
+ # payware MCP Server
2
+
3
+ Minimal MCP server for payware API integration. Enables quick merchant integration with payware APIs in sandbox environment.
4
+
5
+ ## Features
6
+
7
+ ### 🔐 Authentication Tools
8
+ - **RSA Key Generation**: Generate secure 2048-bit RSA key pairs
9
+ - **JWT Token Creation**: Create properly formatted JWT tokens
10
+ - **Sandbox Setup**: Configure sandbox authentication
11
+
12
+ ### 💳 Transaction Tools
13
+ - **Create Transaction**: Support PLAIN, QR, and BARCODE transactions
14
+ - **Transaction Status**: Check transaction status by ID
15
+ - **Callback Simulation**: Test callback scenarios
16
+
17
+ ### 🛠️ Utility Tools
18
+ - **Advanced Code Generation**: Generate complete integration code across 8 languages (Python, Node.js, PHP, Java, C#, Go, Ruby, cURL) with 16+ framework support
19
+ - **Framework Integration**: Framework-specific examples for Django, FastAPI, Express, NestJS, Laravel, Spring Boot, ASP.NET, and more
20
+ - **Real-world Scenarios**: Generate complete integration scenarios (e-commerce, ISV multi-merchant, P2P payments)
21
+ - **Comprehensive Documentation**: Auto-generate complete API documentation with code examples
22
+ - **Request Formatting**: Format and validate API requests
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Installation
27
+
28
+ ```bash
29
+ cd payware/mcp
30
+ npm install
31
+ ```
32
+
33
+ ### 2. Environment Configuration
34
+
35
+ Copy the example environment file and configure your credentials:
36
+
37
+ ```bash
38
+ cp .env.example .env
39
+ ```
40
+
41
+ Edit `.env` file:
42
+
43
+ ```env
44
+ # Partner ID from payware dashboard
45
+ PAYWARE_PARTNER_ID=your_partner_id_here
46
+
47
+ # Path to private key file (relative to project root)
48
+ PAYWARE_SANDBOX_PRIVATE_KEY_PATH=keys/sandbox-your-private-key.pem
49
+ PAYWARE_PRODUCTION_PRIVATE_KEY_PATH=keys/production-your-private-key.pem
50
+
51
+ # Optional: Sandbox base URL (defaults to https://sandbox.payware.eu/api)
52
+ PAYWARE_SANDBOX_URL=https://sandbox.payware.eu/api
53
+ ```
54
+
55
+ ⚠️ **Security Note**: Never commit the `.env` file to version control. It contains sensitive credentials.
56
+
57
+ ### 3. Start the MCP Server
58
+
59
+ ```bash
60
+ npm start
61
+ ```
62
+
63
+ ### 4. Basic Integration Flow
64
+
65
+ 1. **Generate RSA Keys**
66
+ ```
67
+ Tool: payware_authentication_generate_rsa_keys
68
+ ```
69
+
70
+ 2. **Create JWT Token**
71
+ ```
72
+ Tool: payware_authentication_create_jwt_token
73
+ Parameters:
74
+ - partnerId: (from PAYWARE_PARTNER_ID)
75
+ - privateKey: (from environment-specific key path)
76
+ ```
77
+
78
+ 3. **Setup Sandbox**
79
+ ```
80
+ Tool: payware_authentication_setup_sandbox_auth
81
+ Parameters:
82
+ - partnerId: (from PAYWARE_PARTNER_ID)
83
+ ```
84
+
85
+ 4. **Create Transaction**
86
+ ```
87
+ Tool: payware_operations_create_transaction
88
+ Parameters:
89
+ - partnerId: (from PAYWARE_PARTNER_ID)
90
+ - privateKey: (from environment-specific key path)
91
+ - amount: 10.00
92
+ - currency: EUR
93
+ - reasonL1: "Payment description"
94
+ - type: PLAIN
95
+ ```
96
+
97
+ 5. **Check Status**
98
+ ```
99
+ Tool: payware_operations_get_transaction_status
100
+ Parameters:
101
+ - partnerId: (from PAYWARE_PARTNER_ID)
102
+ - privateKey: (from environment-specific key path)
103
+ - transactionId: TRANSACTION_ID
104
+ ```
105
+
106
+ ## API Request Structure
107
+
108
+ The payware MCP server transforms flat parameter inputs into the proper nested JSON structure required by the payware API:
109
+
110
+ ### Create Transaction Request Structure
111
+ ```json
112
+ {
113
+ // ROOT LEVEL - Transaction metadata
114
+ "shop": "SHOP001", // Optional: Shop code
115
+ "account": "GB29NWBK60161331926810", // Optional: Account identifier
116
+ "friendlyName": "Your Shop Name", // Optional: Account holder name
117
+ "callbackUrl": "https://callback.url", // Optional: HTTPS callback URL
118
+ "passbackParams": "{\"orderId\":\"12345\"}", // Optional: Callback parameters
119
+
120
+ // TRANSACTION DATA - Required transaction information
121
+ "trData": {
122
+ "amount": "25.50", // String/Number: Amount (can be "0.00" for flexible amounts)
123
+ "currency": "EUR", // REQUIRED: ISO 3-character currency code
124
+ "reasonL1": "Payment for services", // REQUIRED: Transaction description (max 100 chars)
125
+ "reasonL2": "Order #12345" // Optional: Additional description (max 100 chars)
126
+ },
127
+
128
+ // TRANSACTION OPTIONS - Transaction behavior settings
129
+ "trOptions": {
130
+ "type": "QR", // PLAIN, QR, or BARCODE (default: PLAIN)
131
+ "timeToLive": 300 // Seconds: 60-600 (default: 120)
132
+ },
133
+
134
+ // QR OPTIONS - Only included when type=QR
135
+ "qrOptions": {
136
+ "qrFormat": "PNG", // PNG, SVG, JPG, GIF, BMP (default: SVG)
137
+ "qrBorder": 4, // Border modules: 1-10 (default: 4)
138
+ "qrErrorCorrection": "QUARTILE", // LOW, MEDIUM, QUARTILE, HIGH (default: QUARTILE)
139
+ "qrScale": 16, // Pixel size: 1-100 (default: 16, irrelevant for SVG)
140
+ "qrVersion": 10 // QR version: 1-40 (default: 10, auto if not specified)
141
+ },
142
+
143
+ // BARCODE OPTIONS - Only included when type=BARCODE
144
+ "barOptions": {
145
+ "barFormat": "SVG", // PNG, SVG, JPG (default: SVG)
146
+ "barModuleWidth": 2, // Module width: 1-10 (default: 2)
147
+ "barBarHeight": 100, // Height: 15-1000 (default: 100)
148
+ "barFontSize": 12, // Font size: 0-24 (default: 12)
149
+ "barHumanReadableLocation": "NONE" // NONE, BOTTOM, TOP (default: NONE)
150
+ }
151
+ }
152
+ ```
153
+
154
+ ### Parameter Mapping
155
+
156
+ When using MCP tools, parameters are automatically mapped to the correct API structure:
157
+
158
+ | MCP Tool Parameter | API Location | Description |
159
+ |------------------|-------------|-------------|
160
+ | `partnerId`, `privateKey` | Authentication | Used for JWT signing, not sent in request |
161
+ | `account`, `friendlyName`, `shop`, `callbackUrl`, `passbackParams` | Root Level | Transaction metadata |
162
+ | `amount`, `currency`, `reasonL1`, `reasonL2` | `trData` object | Core transaction data |
163
+ | `type`, `timeToLive` | `trOptions` object | Transaction behavior |
164
+ | `qrFormat`, `qrBorder`, etc. | `qrOptions` object | QR code settings (when type=QR) |
165
+ | `barFormat`, `barModuleWidth`, etc. | `barOptions` object | Barcode settings (when type=BARCODE) |
166
+
167
+ ## Available Tools
168
+
169
+ ### Code Generation & Documentation
170
+
171
+ #### `payware_generate_code_example`
172
+ **Advanced multi-language code generation with framework support**
173
+
174
+ Supports 60+ operations across all partner types:
175
+ - **Transactions**: create_transaction, get_transaction_status, cancel_transaction, process_transaction, get_transaction_history, simulate_callback
176
+ - **Products**: create_product, get_product, update_product, delete_product, list_products, get_product_image, create_schedule, update_schedule, delete_schedule, list_schedules
177
+ - **OAuth2** (ISV only): obtain_token, get_token_info, create_token_simple, refresh_token, revoke_token, list_active_tokens
178
+ - **Data**: generate_report, get_report_status, export_report, download_export, cancel_report, list_reports, get_analytics_summary, create_custom_report
179
+ - **Deep Links**: get_transaction_link, get_product_link, create_custom_link, delete_transaction_link, delete_product_link, list_active_links, get_link_analytics, create_batch_links
180
+ - **P2P** (Payment Institution): initiate_p2p_transfer, accept_p2p_transfer, reject_p2p_transfer, get_p2p_transfer_status, list_p2p_transfers, cancel_p2p_transfer, create_p2p_link, get_p2p_analytics
181
+ - **Soundbites** (Payment Institution): register_audio, get_audio, update_audio, delete_audio, list_audios, create_soundbite_transaction, stream_audio, download_audio, get_soundbite_analytics, create_audio_playlist, get_audio_preview
182
+
183
+ #### `payware_generate_documentation`
184
+ **Comprehensive documentation generator**
185
+
186
+ Generates complete API documentation with working code examples for any partner type and programming language combination.
187
+
188
+ ### Authentication
189
+
190
+ #### `payware_authentication_generate_rsa_keys`
191
+ Generate RSA key pair for API authentication.
192
+
193
+ **Parameters:**
194
+ - `keySize` (optional): RSA key size in bits (default: 2048)
195
+
196
+ #### `payware_authentication_create_jwt_token`
197
+ Create JWT token for API authentication.
198
+
199
+ **Parameters:**
200
+ - `partnerId` (required): Partner ID from payware
201
+ - `privateKey` (required): RSA private key in PEM format
202
+
203
+ #### `payware_authentication_validate_jwt`
204
+ Validate JWT token format and signature.
205
+
206
+ **Parameters:**
207
+ - `token` (required): JWT token to validate
208
+ - `partnerId` (required): Partner ID for validation
209
+
210
+ #### `payware_authentication_test_jwt`
211
+ Test JWT token with payware API.
212
+
213
+ **Parameters:**
214
+ - `token` (required): JWT token to test
215
+ - `partnerId` (required): Partner ID
216
+
217
+ #### `payware_authentication_setup_sandbox_auth`
218
+ Setup sandbox authentication configuration.
219
+
220
+ **Parameters:**
221
+ - `partnerId` (required): Partner ID from payware
222
+ - `privateKey` (optional): Private key for validation
223
+
224
+ ### Transactions
225
+
226
+ #### Transaction Status Overview
227
+
228
+ payware transactions can have the following statuses:
229
+
230
+ **ACTIVE Status:**
231
+ - ⏳ **ACTIVE**: Active transaction pending processing or finalizing
232
+ - This is the only status returned by `payware_transactions_get_transaction_status`
233
+ - Use GET `/transactions/{id}` endpoint
234
+
235
+ **Final Statuses:**
236
+ - ✅ **CONFIRMED**: Successfully finalized
237
+ - ❌ **DECLINED**: Declined by the user, processing or finalizing payment institutions
238
+ - 💥 **FAILED**: Failed due to technical reasons or other
239
+ - ⏰ **EXPIRED**: Time to live of the transaction has passed
240
+ - 🚫 **CANCELLED**: Transaction canceled by the originator
241
+
242
+ These final statuses are only available through `payware_operations_get_transaction_history` using GET `/transactions-history/{id}` endpoint.
243
+
244
+ #### `payware_operations_create_transaction`
245
+ Create a new transaction with full API structure support.
246
+
247
+ **Key Parameters:**
248
+ - `currency` (required): ISO 3-character code (EUR, USD, GBP, etc.)
249
+ - `reasonL1` (required): Transaction description (max 100 chars)
250
+ - `partnerId` (required): Partner ID from payware dashboard
251
+ - `privateKey` (required): RSA private key for JWT signing
252
+ - `amount` (optional): Currency value (default: "0.00" for flexible amounts)
253
+ - `type` (optional): PLAIN, QR, or BARCODE (default: PLAIN)
254
+ - `timeToLive` (optional): Payment timeout in seconds, 60-600 (default: 120)
255
+
256
+ **QR Options** (when type=QR):
257
+ - `qrFormat`: PNG, SVG, JPG, GIF, BMP (default: SVG)
258
+ - `qrErrorCorrection`: LOW, MEDIUM, QUARTILE, HIGH (default: QUARTILE)
259
+ - `qrScale`, `qrBorder`, `qrVersion`: Size and appearance settings
260
+
261
+ **Barcode Options** (when type=BARCODE):
262
+ - `barFormat`: PNG, SVG, JPG (default: SVG)
263
+ - `barModuleWidth`, `barBarHeight`, `barFontSize`: Size settings
264
+
265
+ #### `payware_operations_get_transaction_status`
266
+ Get status of ACTIVE transactions only. For completed/finalized transactions use history tool.
267
+
268
+ **Parameters:**
269
+ - `transactionId` (required): Transaction ID (starts with 'pw')
270
+ - `partnerId` (required): Partner ID
271
+ - `privateKey` (required): Private key for JWT signing
272
+
273
+ #### `payware_operations_simulate_callback`
274
+ Simulate callback scenarios for testing.
275
+
276
+ **Parameters:**
277
+ - `transactionId` (required): Transaction ID
278
+ - `status` (optional): CONFIRMED, DECLINED, FAILED, EXPIRED, or CANCELLED (default: CONFIRMED)
279
+ - `callbackUrl` (optional): URL where callback would be sent
280
+ - `amount` (optional): Transaction amount (default: 10.00)
281
+ - `currency` (optional): Currency (default: EUR)
282
+ - `type` (optional): Transaction type (default: PLAIN)
283
+
284
+ ### Utilities
285
+
286
+ #### `payware_generate_code_example`
287
+ Generate production-ready code examples for any payware operation.
288
+
289
+ **Parameters:**
290
+ - `operation` (required): Operation to generate - see complete list below
291
+ - `language` (optional): python, nodejs, php, java, csharp, curl (default: python)
292
+ - `partner_type` (optional): merchant, isv, payment_institution (default: merchant)
293
+ - `include_comments` (optional): Include detailed code comments (default: true)
294
+ - `include_error_handling` (optional): Include comprehensive error handling (default: true)
295
+
296
+ **Available Operations by Category:**
297
+
298
+ **Authentication:**
299
+ - `authentication` - JWT authentication setup
300
+
301
+ **Transaction Operations (all partner types):**
302
+ - `create_transaction` - Create a new payment transaction
303
+ - `get_transaction_status` - Get transaction status and details
304
+ - `process_transaction` - Process a pending transaction
305
+ - `cancel_transaction` - Cancel a pending transaction
306
+
307
+ **Product Operations (merchant, isv):**
308
+ - `create_product` - Create a new product
309
+ - `get_product` - Get product details
310
+ - `list_products` - List all products
311
+
312
+ **OAuth2 Operations (isv only):**
313
+ - `obtain_token` - Obtain OAuth2 access token
314
+ - `get_token_info` - Get OAuth2 token information
315
+
316
+ **Data Operations (all partner types):**
317
+ - `generate_report` - Generate analytics report
318
+ - `get_report_status` - Get report generation status
319
+
320
+ **P2P Operations (payment_institution only):**
321
+ - `initiate_p2p_transfer` - Initiate peer-to-peer transfer
322
+ - `accept_p2p_transfer` - Accept P2P transfer
323
+
324
+ **Deep Links (all partner types):**
325
+ - `get_transaction_link` - Get deep link for transaction
326
+
327
+ **Soundbites (payment_institution only):**
328
+ - `register_audio` - Register audio content for soundbite transactions
329
+
330
+ #### `payware_generate_documentation`
331
+ Generate comprehensive API documentation with code examples.
332
+
333
+ **Parameters:**
334
+ - `language` (optional): Target programming language (default: python)
335
+ - `partnerType` (optional): merchant, isv, payment_institution (default: merchant)
336
+ - `includeScenarios` (optional): Include real-world integration scenarios (default: true)
337
+ - `outputFormat` (optional): markdown, html, json (default: markdown)
338
+
339
+ #### `payware_utils_format_request`
340
+ Format and validate API requests with deterministic JSON serialization for MD5 consistency.
341
+
342
+ **Parameters:**
343
+ - `type` (required): transaction, headers, or curl
344
+ - `data` (optional): Data to format
345
+ - `jwtToken` (optional): JWT token for headers
346
+ - `signature` (optional): Request signature
347
+ - `endpoint` (optional): API endpoint for curl
348
+ - `method` (optional): HTTP method (default: POST)
349
+
350
+ #### `payware_utils_format_json_deterministic`
351
+ Format JSON with deterministic property ordering for consistent MD5 calculation.
352
+
353
+ **Parameters:**
354
+ - `data` (required): Object to serialize
355
+ - `minimize` (optional): Remove whitespace (default: true)
356
+
357
+ #### `payware_utils_server_info`
358
+ Get MCP server information and configuration.
359
+
360
+ **Note:** All transaction data is serialized using consistent property ordering to prevent MD5 mismatch errors.
361
+
362
+ ## Dependencies
363
+
364
+ - `@modelcontextprotocol/sdk`: MCP server framework
365
+ - `axios`: HTTP client for API calls
366
+ - `jsonwebtoken`: JWT token creation
367
+ - `node-forge`: RSA key generation
368
+
369
+ ## Environment
370
+
371
+ - **Sandbox Only**: All API calls are restricted to sandbox environment
372
+ - **Base URL**: `https://sandbox.payware.eu/api/v1`
373
+ - **Supported Currencies**: EUR, USD, GBP
374
+ - **Supported Transaction Types**: PLAIN, QR, BARCODE
375
+
376
+ ## Security
377
+
378
+ ⚠️ **Important Security Notes:**
379
+
380
+ ### Environment Variables
381
+ - **REQUIRED**: Use environment variables for all credentials
382
+ - Never commit `.env` files to version control
383
+ - Use different credentials for development and production
384
+ - Store private key files outside web-accessible directories
385
+
386
+ ### Private Key Security
387
+ - Generate separate key pairs for sandbox and production
388
+ - Store private keys with restricted file permissions (600)
389
+ - Never embed private keys in source code
390
+ - Rotate keys regularly according to security policies
391
+
392
+ ### API Security
393
+ - This server is designed for sandbox testing only
394
+ - Never use sandbox keys in production environment
395
+ - Implement proper error handling in production
396
+ - Use HTTPS for all API communications
397
+ - Validate all input parameters
398
+ - Implement rate limiting and monitoring
399
+
400
+ ### JSON Serialization & MD5 Consistency
401
+ ⚠️ **CRITICAL**: payware API requires deterministic JSON serialization for MD5 calculation
402
+
403
+ - **Property Order**: JSON objects must have consistent property ordering
404
+ - **Minimized Format**: No whitespace or formatting in request bodies
405
+ - **MD5 Calculation**: Must be calculated from the exact same JSON string sent to API
406
+ - **Implementation**: This server uses deterministic JSON serialization to ensure consistency
407
+
408
+ **Example of correct JSON format:**
409
+ ```json
410
+ {"trData":{"amount":"25.50","currency":"EUR","reasonL1":"Payment description"},"trOptions":{"timeToLive":300,"type":"PLAIN"}}
411
+ ```
412
+
413
+ **Why this matters:**
414
+ - Different property orders produce different MD5 hashes
415
+ - MD5 mismatch results in `ContentMd5 mismatch` errors
416
+ - Server validates that JWT contentMd5 matches request body MD5
417
+
418
+ ## Troubleshooting
419
+
420
+ ### Common Issues
421
+
422
+ 1. **Authentication Failed (ERR_INVALID_SIGNATURE)**
423
+ - **Root Cause**: Public key registered with payware doesn't match your private key
424
+ - **Solution**: Ensure the public key registered on payware site corresponds to your private key
425
+ - **Verification**: Use `openssl rsa -in privateKey.pem -pubout` to extract public key from private key
426
+ - **Status**: ✅ Resolved - Keys must be properly registered on payware partner portal
427
+
428
+ 2. **ContentMd5 Mismatch Error**
429
+ - **Root Cause**: Inconsistent JSON property ordering
430
+ - **Solution**: Use deterministic JSON serialization (implemented in this server)
431
+ - **Symptoms**: Server logs show different expected vs actual MD5 hashes
432
+ - **Prevention**: Always use `createMinimizedJSON()` from `/src/utils/json-serializer.js`
433
+ - **Status**: ✅ Fixed - Deterministic JSON serialization implemented
434
+
435
+ 3. **Transaction Creation Failed**
436
+ - Ensure all required parameters are provided
437
+ - Check amount is non-negative
438
+ - Verify transaction type is supported
439
+ - **Status**: ✅ Working - Create and cancel operations confirmed functional
440
+
441
+ 4. **MCP Connection Issues**
442
+ - Ensure server is started with `npm start`
443
+ - Check that MCP client is properly configured
444
+ - Verify no firewall blocking stdio communication
445
+ - **Note**: Use MCP Inspector (`npm run inspector`) for debugging
446
+
447
+ ### Proxy and Bridge Tools
448
+
449
+ **HTTP Proxy Server** (`npm run proxy`):
450
+ - Bridges MCP tools to HTTP REST API
451
+ - Useful for testing tools via HTTP requests
452
+ - Documentation: `README-proxy.md`
453
+
454
+ **MCP Bridge** (`npm run bridge`):
455
+ - Connects MCP server to MCP Inspector
456
+ - Essential for debugging and development
457
+ - Use with: `npm run inspector`
458
+
459
+ ### Testing Status
460
+
461
+ **✅ Confirmed Working Operations:**
462
+ - JWT token creation with RS256 algorithm
463
+ - Transaction creation (POST /api/transactions)
464
+ - Transaction cancellation (PATCH /api/transactions/{id})
465
+ - Deterministic JSON serialization for MD5 consistency
466
+ - Public/private key pair validation
467
+
468
+ **🧪 Test Results:**
469
+ - All MCP tools tested successfully with real payware sandbox API
470
+ - Both create and cancel transaction flows working end-to-end
471
+ - Signature validation resolved with proper key registration
472
+
473
+ ### Support
474
+
475
+ For issues related to:
476
+ - **MCP Server**: Check server logs and MCP client configuration
477
+ - **payware API**: Refer to payware documentation and sandbox status
478
+ - **Integration**: Use code examples and formatting tools provided
479
+ - **Key Issues**: Ensure public key is registered on payware partner portal
480
+
481
+ ## License
482
+
483
+ MIT License
package/check-keys.js ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+
3
+ import crypto from 'crypto';
4
+ import { getPrivateKey } from './src/config/env.js';
5
+
6
+ async function checkKeys() {
7
+ // Get our private key
8
+ const privateKey = getPrivateKey();
9
+ console.log('=== PRIVATE KEY (first 100 chars) ===');
10
+ console.log(privateKey.substring(0, 100) + '...');
11
+
12
+ // Extract public key from our private key
13
+ const keyObject = crypto.createPrivateKey(privateKey);
14
+ const publicKey = crypto.createPublicKey(keyObject);
15
+ const publicKeyFromPrivate = publicKey.export({ type: 'spki', format: 'der' });
16
+ const publicKeyBase64 = publicKeyFromPrivate.toString('base64');
17
+
18
+ console.log('\n=== OUR PUBLIC KEY (derived from private key) ===');
19
+ console.log(publicKeyBase64);
20
+
21
+ // The public key from payware DB
22
+ const paywarePublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi0h9c+0VASQ2BUvet/ScY6qBhf2NmIjHBm7SqxNoaHL8S9bwx2FPPsnmQRdlYrGHiQmdPaVG4hNa5Wefwf1jlDrjJDNXF5PoxHN3cUWdhhv1YWybGneyLdbWCEmWjG3M9BqkJrcgug+vsSIeswoophtk9woQ1gn/HhMzFKu4OYUdM7kqUbSVMJLzmx3Ja+XR4p32F73X6fzKJNhtjTkrxegsYXGyEOBoVVePlAEEjgF1Khmm1zct/bj/MjDiKuieFARNF5n9v+rVqj4a0KQTT0knBhTUJr4XfV346uSZt23U5dxlz+s/PJWXEKSIVuki5xXMKX1V0+U+To1wLbdBPQIDAQAB';
23
+
24
+ console.log('\n=== PAYWARE DB PUBLIC KEY ===');
25
+ console.log(paywarePublicKey);
26
+
27
+ console.log('\n=== COMPARISON ===');
28
+ const keysMatch = publicKeyBase64 === paywarePublicKey;
29
+ console.log('Keys match:', keysMatch ? '✅ YES' : '❌ NO');
30
+
31
+ if (!keysMatch) {
32
+ console.log('\n=== 🔍 KEY MISMATCH DETECTED ===');
33
+ console.log('This explains the ERR_INVALID_SIGNATURE error!');
34
+ console.log('The private key we are using does not correspond to the public key in payware DB.');
35
+ console.log('\n=== SOLUTION ===');
36
+ console.log('Either:');
37
+ console.log('1. Update payware DB with our public key:');
38
+ console.log(' ' + publicKeyBase64);
39
+ console.log('2. Get the correct private key that matches the DB public key');
40
+
41
+ console.log('\n=== KEY DETAILS ===');
42
+ console.log('Our public key length:', publicKeyBase64.length);
43
+ console.log('DB public key length:', paywarePublicKey.length);
44
+ console.log('First 50 chars - Ours:', publicKeyBase64.substring(0, 50));
45
+ console.log('First 50 chars - DB :', paywarePublicKey.substring(0, 50));
46
+ } else {
47
+ console.log('\n=== ✅ KEYS MATCH ===');
48
+ console.log('The signature error must be caused by something else.');
49
+ }
50
+ }
51
+
52
+ checkKeys().catch(console.error);
package/keys/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Private Keys Setup
2
+
3
+ This directory contains RSA private keys for payware API authentication. Private keys are required for JWT token generation and API requests.
4
+
5
+ ## Security Notice
6
+
7
+ ⚠️ **IMPORTANT**: Private keys contain sensitive credentials and should never be committed to version control or shared publicly.
8
+
9
+ - All `.pem` files in this directory are excluded via `.gitignore`
10
+ - Never share private keys via email, chat, or public repositories
11
+ - Store keys securely with appropriate file permissions (600)
12
+
13
+ ## Key Files
14
+
15
+ ### Required Keys
16
+
17
+ Depending on your partner type and environment, you'll need one or more of these keys:
18
+
19
+ - **Production Keys**: For live API integration
20
+ - `production-payware-merchant-private-key.pem` - Merchant production key
21
+ - `production-payware-isv-private-key.pem` - ISV production key
22
+ - `production-payware-pi-private-key.pem` - Payment Institution production key
23
+
24
+ - **Sandbox Keys**: For testing and development
25
+ - `sandbox-payware-merchant-private-key.pem` - Merchant sandbox key
26
+ - `sandbox-payware-isv-private-key.pem` - ISV sandbox key
27
+ - `sandbox-payware-pi-private-key.pem` - Payment Institution sandbox key
28
+
29
+ ## Generating Keys
30
+
31
+ ### Using payware MCP Tools
32
+
33
+ The easiest way to generate keys is using the built-in MCP tool:
34
+
35
+ ```bash
36
+ # Generate RSA key pair (2048-bit by default)
37
+ # Use the payware_authentication_generate_rsa_keys tool
38
+ ```
39
+
40
+ This will generate both private and public keys. **Register the public key** with payware via your partner portal before using the private key.
41
+
42
+ ### Manual Generation
43
+
44
+ You can also generate keys manually using OpenSSL:
45
+
46
+ ```bash
47
+ # Generate private key
48
+ openssl genrsa -out sandbox-payware-merchant-private-key.pem 2048
49
+
50
+ # Extract public key (for registration with payware)
51
+ openssl rsa -in sandbox-payware-merchant-private-key.pem -pubout -out public-key.pem
52
+
53
+ # Set secure permissions
54
+ chmod 600 sandbox-payware-merchant-private-key.pem
55
+ ```
56
+
57
+ ## Environment Configuration
58
+
59
+ Update your `.env` file to reference the correct key files:
60
+
61
+ ```env
62
+ # Sandbox keys
63
+ PAYWARE_SANDBOX_PRIVATE_KEY_PATH=keys/sandbox-payware-merchant-private-key.pem
64
+
65
+ # Production keys
66
+ PAYWARE_PRODUCTION_PRIVATE_KEY_PATH=keys/production-payware-merchant-private-key.pem
67
+ ```
68
+
69
+ ## Key Registration
70
+
71
+ **CRITICAL**: After generating keys, you must register the **public key** with payware:
72
+
73
+ 1. Extract the public key from your private key
74
+ 2. Log into your payware partner portal
75
+ 3. Navigate to API Settings > Keys
76
+ 4. Upload or paste your public key
77
+ 5. Save the configuration
78
+
79
+ The MCP server will fail with authentication errors if the public key isn't properly registered.
80
+
81
+ ## Validation
82
+
83
+ Use the key validation utility to test your setup:
84
+
85
+ ```bash
86
+ node check-keys.js
87
+ ```
88
+
89
+ This will verify that your keys are properly formatted and can generate valid JWT tokens.
90
+
91
+ ## File Permissions
92
+
93
+ Ensure private keys have restrictive permissions:
94
+
95
+ ```bash
96
+ # Set secure permissions for all key files
97
+ chmod 600 keys/*.pem
98
+ ```
99
+
100
+ ## Troubleshooting
101
+
102
+ ### Authentication Failed (ERR_INVALID_SIGNATURE)
103
+ - **Cause**: Public key registered with payware doesn't match your private key
104
+ - **Solution**: Re-extract public key from private key and re-register with payware
105
+
106
+ ### File Not Found
107
+ - **Cause**: Key path in `.env` doesn't match actual file location
108
+ - **Solution**: Verify file paths in environment configuration
109
+
110
+ ### Permission Denied
111
+ - **Cause**: Key file permissions too restrictive or too open
112
+ - **Solution**: Set permissions to 600 (`chmod 600 filename.pem`)
@@ -0,0 +1,9 @@
1
+ {
2
+ "mcpServers": {
3
+ "payware": {
4
+ "command": "node",
5
+ "args": ["src/index.js"],
6
+ "cwd": "."
7
+ }
8
+ }
9
+ }