@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
@@ -0,0 +1,388 @@
1
+ /**
2
+ * Payment Institution transaction examples
3
+ */
4
+
5
+ import { ExampleGenerator, CommonTemplates } from '../common/helpers.js';
6
+
7
+ /**
8
+ * Payment Institution transaction operations
9
+ */
10
+ export const PITransactionOperations = {
11
+ create_pi_transaction: {
12
+ description: 'Create a payment institution transaction',
13
+ endpoint: '/transactions',
14
+ method: 'POST',
15
+ sampleBody: {
16
+ trData: {
17
+ amount: '50.00',
18
+ currency: 'EUR',
19
+ reasonL1: 'Payment processing',
20
+ reasonL2: 'Service fee'
21
+ },
22
+ trOptions: {
23
+ type: 'PLAIN',
24
+ timeToLive: 120
25
+ }
26
+ }
27
+ },
28
+
29
+ process_pi_transaction: {
30
+ description: 'Process a payment institution transaction',
31
+ endpoint: '/transactions/{id}',
32
+ method: 'POST',
33
+ sampleBody: {
34
+ account: 'PI_ACCOUNT',
35
+ friendlyName: 'Payment Institution Name',
36
+ trData: {
37
+ amount: '50.00',
38
+ currency: 'EUR',
39
+ reasonL1: 'Payment processing'
40
+ }
41
+ }
42
+ },
43
+
44
+ finalize_transaction: {
45
+ description: 'Finalize a payment institution transaction',
46
+ endpoint: '/transactions/{id}/finalize',
47
+ method: 'POST',
48
+ sampleBody: {
49
+ status: 'CONFIRMED',
50
+ amount: '50.00',
51
+ currency: 'EUR',
52
+ finalAmount: '48.50',
53
+ fees: {
54
+ processingFee: '1.50'
55
+ }
56
+ }
57
+ },
58
+
59
+ get_pi_transaction_status: {
60
+ description: 'Get payment institution transaction status',
61
+ endpoint: '/transactions/{id}',
62
+ method: 'GET',
63
+ sampleBody: null
64
+ },
65
+
66
+ get_pi_transaction_history: {
67
+ description: 'Get payment institution transaction history',
68
+ endpoint: '/transactions/{id}/history',
69
+ method: 'GET',
70
+ sampleBody: null
71
+ },
72
+
73
+ soundbite_transaction: {
74
+ description: 'Create a soundbite transaction for payment institution',
75
+ endpoint: '/transactions',
76
+ method: 'POST',
77
+ sampleBody: {
78
+ trData: {
79
+ amount: '25.00',
80
+ currency: 'EUR',
81
+ reasonL1: 'Audio content purchase',
82
+ soundbiteId: 'sb_12345'
83
+ },
84
+ trOptions: {
85
+ type: 'SOUNDBITE',
86
+ timeToLive: 300,
87
+ audioSettings: {
88
+ quality: 'high',
89
+ format: 'mp3'
90
+ }
91
+ }
92
+ }
93
+ },
94
+
95
+ simulate_pi_callback: {
96
+ description: 'Simulate payment institution callback for testing',
97
+ endpoint: '/transactions/{id}/callback',
98
+ method: 'POST',
99
+ sampleBody: {
100
+ status: 'COMPLETED',
101
+ statusMessage: 'Transaction processed successfully',
102
+ piReference: 'PI_REF_12345',
103
+ processingTime: '2.5s'
104
+ }
105
+ }
106
+ };
107
+
108
+ /**
109
+ * Python Payment Institution Transaction Generator
110
+ */
111
+ export class PythonPITransactionGenerator extends ExampleGenerator {
112
+ constructor() {
113
+ super('python');
114
+ }
115
+
116
+ getOperationTemplate(operation, partnerType, params = {}) {
117
+ const opConfig = PITransactionOperations[operation];
118
+ if (!opConfig) {
119
+ throw new Error(`Unknown operation: ${operation}`);
120
+ }
121
+
122
+ const { transactionId = 'tr_example_123', ...otherParams } = params;
123
+ const endpoint = opConfig.endpoint.replace('{id}', transactionId);
124
+ const functionName = `${operation}_example`;
125
+
126
+ return `def ${functionName}(transaction_id='${transactionId}', use_sandbox=True):
127
+ """${opConfig.description}"""
128
+
129
+ # Get API configuration
130
+ base_url = get_api_base_url(use_sandbox)
131
+ endpoint = '${endpoint}'
132
+ url = f"{base_url}{endpoint}"
133
+
134
+ ${this.getRequestBodySection(operation, opConfig)}
135
+
136
+ # Create JWT token
137
+ token, body_string = create_jwt_token(request_body, use_sandbox)
138
+ headers = get_api_headers(token)
139
+
140
+ try:
141
+ ${this.getRequestSection(opConfig.method)}
142
+
143
+ if response.status_code == 200:
144
+ result = response.json()
145
+ print(f"${opConfig.description} successful:")
146
+ print(json.dumps(result, indent=2))
147
+ return result
148
+ else:
149
+ error_msg = f"Request failed with status {response.status_code}: {response.text}"
150
+ print(error_msg)
151
+ return None
152
+
153
+ except requests.exceptions.RequestException as e:
154
+ print(f"Request error: {str(e)}")
155
+ return None
156
+ except Exception as e:
157
+ print(f"Unexpected error: {str(e)}")
158
+ return None
159
+
160
+ # Example usage
161
+ if __name__ == "__main__":
162
+ # ${opConfig.description}
163
+ result = ${functionName}()
164
+
165
+ if result:
166
+ print("Operation completed successfully")
167
+ ${this.getResultProcessingSection(operation)}
168
+ else:
169
+ print("Operation failed")`;
170
+ }
171
+
172
+ getRequestBodySection(operation, opConfig) {
173
+ if (!opConfig.sampleBody) {
174
+ return '# No request body needed for this operation\n request_body = None';
175
+ }
176
+
177
+ const bodyStr = JSON.stringify(opConfig.sampleBody, null, 8).replace(/^/gm, ' ');
178
+ return `# Prepare request body
179
+ request_body = ${bodyStr}`;
180
+ }
181
+
182
+ getRequestSection(method) {
183
+ if (method === 'GET') {
184
+ return 'response = requests.get(url, headers=headers)';
185
+ } else {
186
+ return `response = requests.${method.toLowerCase()}(
187
+ url,
188
+ headers=headers,
189
+ data=body_string if request_body else None
190
+ )`;
191
+ }
192
+ }
193
+
194
+ getResultProcessingSection(operation) {
195
+ const processing = {
196
+ create_pi_transaction: `# Store transaction ID for later use
197
+ transaction_id = result.get('transactionId')
198
+ print(f"Transaction created with ID: {transaction_id}")`,
199
+
200
+ process_pi_transaction: `# Check processing status
201
+ status = result.get('status')
202
+ print(f"Transaction processing status: {status}")`,
203
+
204
+ finalize_transaction: `# Verify finalization
205
+ final_amount = result.get('finalAmount')
206
+ fees = result.get('fees', {})
207
+ print(f"Final amount: {final_amount}")
208
+ print(f"Processing fees: {fees}")`,
209
+
210
+ get_pi_transaction_status: `# Display transaction details
211
+ status = result.get('status')
212
+ amount = result.get('amount')
213
+ print(f"Transaction status: {status}, Amount: {amount}")`,
214
+
215
+ soundbite_transaction: `# Handle soundbite transaction
216
+ soundbite_url = result.get('soundbiteUrl')
217
+ if soundbite_url:
218
+ print(f"Soundbite available at: {soundbite_url}")`,
219
+
220
+ simulate_pi_callback: `# Verify callback simulation
221
+ callback_status = result.get('status')
222
+ print(f"Callback simulation status: {callback_status}")`
223
+ };
224
+
225
+ return processing[operation] || '# Process result as needed';
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Node.js Payment Institution Transaction Generator
231
+ */
232
+ export class NodeJSPITransactionGenerator extends ExampleGenerator {
233
+ constructor() {
234
+ super('nodejs');
235
+ }
236
+
237
+ getOperationTemplate(operation, partnerType, params = {}) {
238
+ const opConfig = PITransactionOperations[operation];
239
+ if (!opConfig) {
240
+ throw new Error(`Unknown operation: ${operation}`);
241
+ }
242
+
243
+ const { transactionId = 'tr_example_123', ...otherParams } = params;
244
+ const endpoint = opConfig.endpoint.replace('{id}', transactionId);
245
+ const functionName = `${operation}Example`;
246
+
247
+ return `async function ${functionName}(transactionId = '${transactionId}', useSandbox = true) {
248
+ /**
249
+ * ${opConfig.description}
250
+ */
251
+
252
+ try {
253
+ // Get API configuration
254
+ const baseUrl = getAPIBaseURL(useSandbox);
255
+ const endpoint = '${endpoint}';
256
+ const url = \`\${baseUrl}\${endpoint}\`;
257
+
258
+ ${this.getRequestBodySection(operation, opConfig)}
259
+
260
+ // Create JWT token
261
+ const { token, bodyString } = createJWTToken(requestBody, useSandbox);
262
+ const headers = getAPIHeaders(token);
263
+
264
+ ${this.getRequestSection(opConfig.method)}
265
+
266
+ if (response.status === 200) {
267
+ const result = response.data;
268
+ console.log('${opConfig.description} successful:');
269
+ console.log(JSON.stringify(result, null, 2));
270
+
271
+ ${this.getResultProcessingSection(operation)}
272
+
273
+ return result;
274
+ } else {
275
+ console.error(\`Request failed with status \${response.status}: \${response.statusText}\`);
276
+ return null;
277
+ }
278
+
279
+ } catch (error) {
280
+ if (error.response) {
281
+ console.error(\`API Error: \${error.response.status} - \${error.response.data}\`);
282
+ } else if (error.request) {
283
+ console.error('Network Error:', error.message);
284
+ } else {
285
+ console.error('Request Error:', error.message);
286
+ }
287
+ return null;
288
+ }
289
+ }
290
+
291
+ // Example usage
292
+ async function main() {
293
+ console.log('Payment Institution Transaction Example');
294
+
295
+ const result = await ${functionName}();
296
+
297
+ if (result) {
298
+ console.log('Operation completed successfully');
299
+ } else {
300
+ console.log('Operation failed');
301
+ }
302
+ }
303
+
304
+ // Run example if this file is executed directly
305
+ if (require.main === module) {
306
+ main().catch(console.error);
307
+ }`;
308
+ }
309
+
310
+ getRequestBodySection(operation, opConfig) {
311
+ if (!opConfig.sampleBody) {
312
+ return '// No request body needed for this operation\n const requestBody = null;';
313
+ }
314
+
315
+ const bodyStr = JSON.stringify(opConfig.sampleBody, null, 4).replace(/^/gm, ' ');
316
+ return `// Prepare request body
317
+ const requestBody = ${bodyStr};`;
318
+ }
319
+
320
+ getRequestSection(method) {
321
+ if (method === 'GET') {
322
+ return 'const response = await axios.get(url, { headers });';
323
+ } else {
324
+ return `const response = await axios.${method.toLowerCase()}(
325
+ url,
326
+ bodyString || undefined,
327
+ { headers }
328
+ );`;
329
+ }
330
+ }
331
+
332
+ getResultProcessingSection(operation) {
333
+ const processing = {
334
+ create_pi_transaction: `// Store transaction ID for later use
335
+ const transactionId = result.transactionId;
336
+ console.log(\`Transaction created with ID: \${transactionId}\`);`,
337
+
338
+ process_pi_transaction: `// Check processing status
339
+ const status = result.status;
340
+ console.log(\`Transaction processing status: \${status}\`);`,
341
+
342
+ finalize_transaction: `// Verify finalization
343
+ const finalAmount = result.finalAmount;
344
+ const fees = result.fees || {};
345
+ console.log(\`Final amount: \${finalAmount}\`);
346
+ console.log(\`Processing fees:\`, fees);`,
347
+
348
+ get_pi_transaction_status: `// Display transaction details
349
+ const status = result.status;
350
+ const amount = result.amount;
351
+ console.log(\`Transaction status: \${status}, Amount: \${amount}\`);`,
352
+
353
+ soundbite_transaction: `// Handle soundbite transaction
354
+ const soundbiteUrl = result.soundbiteUrl;
355
+ if (soundbiteUrl) {
356
+ console.log(\`Soundbite available at: \${soundbiteUrl}\`);
357
+ }`,
358
+
359
+ simulate_pi_callback: `// Verify callback simulation
360
+ const callbackStatus = result.status;
361
+ console.log(\`Callback simulation status: \${callbackStatus}\`);`
362
+ };
363
+
364
+ return processing[operation] || '// Process result as needed';
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Export all generators
370
+ */
371
+ export const PITransactionGenerators = {
372
+ python: PythonPITransactionGenerator,
373
+ nodejs: NodeJSPITransactionGenerator,
374
+ javascript: NodeJSPITransactionGenerator
375
+ };
376
+
377
+ /**
378
+ * Generate payment institution transaction example
379
+ */
380
+ export function generatePITransactionExample(operation, language = 'python', options = {}) {
381
+ const GeneratorClass = PITransactionGenerators[language];
382
+ if (!GeneratorClass) {
383
+ throw new Error(`Unsupported language: ${language}`);
384
+ }
385
+
386
+ const generator = new GeneratorClass();
387
+ return generator.generateExample(operation, 'payment_institution', options);
388
+ }