@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,522 @@
1
+ import {
2
+ createPriceSchedule,
3
+ getProductSchedules,
4
+ getSchedule,
5
+ updatePriceSchedule,
6
+ deletePriceSchedule
7
+ } from '../../shared/products/products-api.js';
8
+ import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
9
+ import { PRICE_CORRECTION_TYPES, CORRECTION_TYPES } from '../../shared/products/products-api.js';
10
+
11
+ // Common ISV authentication properties
12
+ const ISV_AUTH_PROPS = {
13
+ merchantPartnerId: {
14
+ type: "string",
15
+ description: "Target merchant partner ID (8 alphanumeric characters, e.g., 'PZAYNMVE')"
16
+ },
17
+ oauth2Token: {
18
+ type: "string",
19
+ description: "OAuth2 access token obtained from the merchant"
20
+ }
21
+ };
22
+
23
+ // Common ISV validation and credential setup
24
+ function validateISVAuth(args) {
25
+ const { merchantPartnerId, oauth2Token } = args;
26
+
27
+ if (!merchantPartnerId) {
28
+ throw new Error("Merchant Partner ID is required for ISV operations");
29
+ }
30
+
31
+ if (!oauth2Token) {
32
+ throw new Error("OAuth2 token is required for ISV operations");
33
+ }
34
+
35
+ const isvPartnerId = getPartnerIdSafe();
36
+ const privateKey = getPrivateKeySafe();
37
+
38
+ if (!isvPartnerId || !privateKey) {
39
+ throw new Error("ISV credentials are required");
40
+ }
41
+
42
+ return { isvPartnerId, privateKey, merchantPartnerId, oauth2Token };
43
+ }
44
+
45
+ /**
46
+ * Create price schedule tool implementation for ISVs
47
+ */
48
+ export const createScheduleTool = {
49
+ name: "payware_products_create_schedule",
50
+ description: "Create a price schedule for a merchant's product (ISV operation)",
51
+
52
+ inputSchema: {
53
+ type: "object",
54
+ properties: {
55
+ ...ISV_AUTH_PROPS,
56
+ productId: {
57
+ type: "string",
58
+ description: "Product identifier (starts with 'pr')",
59
+ pattern: "^pr[a-zA-Z0-9]+$"
60
+ },
61
+ description: {
62
+ type: "string",
63
+ description: "Schedule description",
64
+ maxLength: 300
65
+ },
66
+ priceCorrection: {
67
+ type: "string",
68
+ enum: Object.values(PRICE_CORRECTION_TYPES),
69
+ description: "Price correction direction",
70
+ default: PRICE_CORRECTION_TYPES.DISCOUNT
71
+ },
72
+ correctionType: {
73
+ type: "string",
74
+ enum: Object.values(CORRECTION_TYPES),
75
+ description: "Price correction method",
76
+ default: CORRECTION_TYPES.PERCENTAGE
77
+ },
78
+ correctionValue: {
79
+ type: "string",
80
+ description: "Correction value (positive number with max 2 decimals)",
81
+ default: "0.00"
82
+ },
83
+ dateFrom: {
84
+ type: "string",
85
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$",
86
+ description: "Schedule start date (YYYY-MM-DD format)"
87
+ },
88
+ dateTo: {
89
+ type: "string",
90
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$",
91
+ description: "Schedule end date (YYYY-MM-DD format)"
92
+ },
93
+ useSandbox: {
94
+ type: "boolean",
95
+ description: "Use sandbox environment",
96
+ default: true
97
+ }
98
+ },
99
+ required: ["merchantPartnerId", "oauth2Token", "productId"]
100
+ },
101
+
102
+ async handler(args) {
103
+ const { productId, description, priceCorrection, correctionType, correctionValue, dateFrom, dateTo, useSandbox = true } = args;
104
+ const { isvPartnerId, privateKey, merchantPartnerId, oauth2Token } = validateISVAuth(args);
105
+
106
+ if (!productId) {
107
+ throw new Error("Product ID is required");
108
+ }
109
+
110
+ try {
111
+ const result = await createPriceSchedule({
112
+ productId,
113
+ description,
114
+ priceCorrection,
115
+ correctionType,
116
+ correctionValue,
117
+ dateFrom,
118
+ dateTo,
119
+ partnerType: 'isv',
120
+ isvPartnerId,
121
+ privateKey,
122
+ merchantPartnerId,
123
+ oauth2Token,
124
+ useSandbox
125
+ });
126
+
127
+ const schedule = result.data;
128
+
129
+ return {
130
+ content: [{
131
+ type: "text",
132
+ text: `📅 **Price Schedule Created Successfully (ISV -> Merchant: ${merchantPartnerId})**
133
+
134
+ **Schedule Details:**
135
+ - ID: ${schedule.id}
136
+ - Product ID: ${schedule.productId}
137
+ - Description: ${schedule.description || 'No description'}
138
+ - Type: ${schedule.priceCorrection} (${schedule.correctionType})
139
+ - Value: ${schedule.correctionValue}${schedule.correctionType === 'PERCENTAGE' ? '%' : ''}
140
+
141
+ **Pricing:**
142
+ - Regular Price: ${schedule.regularPrice}
143
+ - Sale Price: ${schedule.salePrice}
144
+
145
+ **Active Period:**
146
+ - From: ${schedule.dateFrom}
147
+ - To: ${schedule.dateTo}
148
+
149
+ **ISV Integration Details:**
150
+ - ISV Partner: ${isvPartnerId}
151
+ - Target Merchant: ${merchantPartnerId}
152
+ - OAuth2 Token: ${oauth2Token.substring(0, 8)}...`
153
+ }]
154
+ };
155
+ } catch (error) {
156
+ return {
157
+ content: [{
158
+ type: "text",
159
+ text: `❌ **Schedule Creation Failed**
160
+
161
+ **Error:** ${error.message}
162
+ **Product ID:** ${productId}
163
+ **ISV -> Merchant:** ${isvPartnerId} -> ${merchantPartnerId}`
164
+ }]
165
+ };
166
+ }
167
+ }
168
+ };
169
+
170
+ /**
171
+ * Get product schedules tool implementation for ISVs
172
+ */
173
+ export const getSchedulesTool = {
174
+ name: "payware_products_get_schedules",
175
+ description: "Get all price schedules for a merchant's product (ISV operation)",
176
+
177
+ inputSchema: {
178
+ type: "object",
179
+ properties: {
180
+ ...ISV_AUTH_PROPS,
181
+ productId: {
182
+ type: "string",
183
+ description: "Product identifier (starts with 'pr')",
184
+ pattern: "^pr[a-zA-Z0-9]+$"
185
+ },
186
+ useSandbox: {
187
+ type: "boolean",
188
+ description: "Use sandbox environment",
189
+ default: true
190
+ }
191
+ },
192
+ required: ["merchantPartnerId", "oauth2Token", "productId"]
193
+ },
194
+
195
+ async handler(args) {
196
+ const { productId, useSandbox = true } = args;
197
+ const { isvPartnerId, privateKey, merchantPartnerId, oauth2Token } = validateISVAuth(args);
198
+
199
+ try {
200
+ const result = await getProductSchedules({
201
+ productId,
202
+ partnerType: 'isv',
203
+ isvPartnerId,
204
+ privateKey,
205
+ merchantPartnerId,
206
+ oauth2Token,
207
+ useSandbox
208
+ });
209
+
210
+ const schedules = result.data;
211
+ const scheduleCount = Array.isArray(schedules) ? schedules.length : 0;
212
+
213
+ let schedulesList = '';
214
+ if (Array.isArray(schedules) && schedules.length > 0) {
215
+ schedulesList = schedules.map(schedule =>
216
+ `**Schedule ${schedule.id}:**
217
+ - Description: ${schedule.description || 'No description'}
218
+ - Type: ${schedule.priceCorrection} ${schedule.correctionValue}${schedule.correctionType === 'PERCENTAGE' ? '%' : ''}
219
+ - Period: ${schedule.dateFrom} to ${schedule.dateTo}
220
+ - Sale Price: ${schedule.salePrice}`
221
+ ).join('\n\n');
222
+ } else {
223
+ schedulesList = 'No price schedules found for this product.';
224
+ }
225
+
226
+ return {
227
+ content: [{
228
+ type: "text",
229
+ text: `📅 **Product Price Schedules (ISV -> Merchant: ${merchantPartnerId})**
230
+
231
+ **Product ID:** ${productId}
232
+ **Total Schedules:** ${scheduleCount}
233
+
234
+ **ISV Integration Details:**
235
+ - ISV Partner: ${isvPartnerId}
236
+ - Target Merchant: ${merchantPartnerId}
237
+
238
+ **Schedules:**
239
+ ${schedulesList}`
240
+ }]
241
+ };
242
+ } catch (error) {
243
+ return {
244
+ content: [{
245
+ type: "text",
246
+ text: `❌ **Failed to Get Schedules**
247
+
248
+ **Error:** ${error.message}
249
+ **Product ID:** ${productId}`
250
+ }]
251
+ };
252
+ }
253
+ }
254
+ };
255
+
256
+ /**
257
+ * Get specific schedule tool implementation for ISVs
258
+ */
259
+ export const getScheduleTool = {
260
+ name: "payware_products_get_schedule",
261
+ description: "Get detailed information about a specific price schedule (ISV operation)",
262
+
263
+ inputSchema: {
264
+ type: "object",
265
+ properties: {
266
+ ...ISV_AUTH_PROPS,
267
+ productId: {
268
+ type: "string",
269
+ description: "Product identifier (starts with 'pr')",
270
+ pattern: "^pr[a-zA-Z0-9]+$"
271
+ },
272
+ scheduleId: {
273
+ type: "number",
274
+ description: "Schedule identifier"
275
+ },
276
+ useSandbox: {
277
+ type: "boolean",
278
+ description: "Use sandbox environment",
279
+ default: true
280
+ }
281
+ },
282
+ required: ["merchantPartnerId", "oauth2Token", "productId", "scheduleId"]
283
+ },
284
+
285
+ async handler(args) {
286
+ const { productId, scheduleId, useSandbox = true } = args;
287
+ const { isvPartnerId, privateKey, merchantPartnerId, oauth2Token } = validateISVAuth(args);
288
+
289
+ try {
290
+ const result = await getSchedule({
291
+ productId,
292
+ scheduleId,
293
+ partnerType: 'isv',
294
+ isvPartnerId,
295
+ privateKey,
296
+ merchantPartnerId,
297
+ oauth2Token,
298
+ useSandbox
299
+ });
300
+
301
+ const schedule = result.data;
302
+
303
+ return {
304
+ content: [{
305
+ type: "text",
306
+ text: `📅 **Schedule Details (ISV -> Merchant: ${merchantPartnerId})**
307
+
308
+ **Schedule Information:**
309
+ - ID: ${schedule.id}
310
+ - Product ID: ${schedule.productId}
311
+ - Description: ${schedule.description || 'No description'}
312
+
313
+ **Price Configuration:**
314
+ - Type: ${schedule.priceCorrection} (${schedule.correctionType})
315
+ - Value: ${schedule.correctionValue}${schedule.correctionType === 'PERCENTAGE' ? '%' : ''}
316
+ - Regular Price: ${schedule.regularPrice}
317
+ - Sale Price: ${schedule.salePrice}
318
+
319
+ **Active Period:**
320
+ - From: ${schedule.dateFrom}
321
+ - To: ${schedule.dateTo}`
322
+ }]
323
+ };
324
+ } catch (error) {
325
+ return {
326
+ content: [{
327
+ type: "text",
328
+ text: `❌ **Failed to Get Schedule**
329
+
330
+ **Error:** ${error.message}
331
+ **Product ID:** ${productId}
332
+ **Schedule ID:** ${scheduleId}`
333
+ }]
334
+ };
335
+ }
336
+ }
337
+ };
338
+
339
+ /**
340
+ * Update schedule tool implementation for ISVs
341
+ */
342
+ export const updateScheduleTool = {
343
+ name: "payware_products_update_schedule",
344
+ description: "Update an existing price schedule (ISV operation)",
345
+
346
+ inputSchema: {
347
+ type: "object",
348
+ properties: {
349
+ ...ISV_AUTH_PROPS,
350
+ productId: {
351
+ type: "string",
352
+ description: "Product identifier (starts with 'pr')",
353
+ pattern: "^pr[a-zA-Z0-9]+$"
354
+ },
355
+ scheduleId: {
356
+ type: "number",
357
+ description: "Schedule identifier"
358
+ },
359
+ description: {
360
+ type: "string",
361
+ description: "Schedule description",
362
+ maxLength: 300
363
+ },
364
+ priceCorrection: {
365
+ type: "string",
366
+ enum: Object.values(PRICE_CORRECTION_TYPES),
367
+ description: "Price correction direction"
368
+ },
369
+ correctionType: {
370
+ type: "string",
371
+ enum: Object.values(CORRECTION_TYPES),
372
+ description: "Price correction method"
373
+ },
374
+ correctionValue: {
375
+ type: "string",
376
+ description: "Correction value (positive number with max 2 decimals)"
377
+ },
378
+ dateFrom: {
379
+ type: "string",
380
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$",
381
+ description: "Schedule start date (YYYY-MM-DD format)"
382
+ },
383
+ dateTo: {
384
+ type: "string",
385
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$",
386
+ description: "Schedule end date (YYYY-MM-DD format)"
387
+ },
388
+ useSandbox: {
389
+ type: "boolean",
390
+ description: "Use sandbox environment",
391
+ default: true
392
+ }
393
+ },
394
+ required: ["merchantPartnerId", "oauth2Token", "productId", "scheduleId"]
395
+ },
396
+
397
+ async handler(args) {
398
+ const { productId, scheduleId, description, priceCorrection, correctionType, correctionValue, dateFrom, dateTo, useSandbox = true } = args;
399
+ const { isvPartnerId, privateKey, merchantPartnerId, oauth2Token } = validateISVAuth(args);
400
+
401
+ try {
402
+ const result = await updatePriceSchedule({
403
+ productId,
404
+ scheduleId,
405
+ description,
406
+ priceCorrection,
407
+ correctionType,
408
+ correctionValue,
409
+ dateFrom,
410
+ dateTo,
411
+ partnerType: 'isv',
412
+ isvPartnerId,
413
+ privateKey,
414
+ merchantPartnerId,
415
+ oauth2Token,
416
+ useSandbox
417
+ });
418
+
419
+ const schedule = result.data;
420
+
421
+ return {
422
+ content: [{
423
+ type: "text",
424
+ text: `✅ **Schedule Updated Successfully (ISV -> Merchant: ${merchantPartnerId})**
425
+
426
+ **Updated Schedule:**
427
+ - ID: ${schedule.id}
428
+ - Product ID: ${schedule.productId}
429
+ - Description: ${schedule.description || 'No description'}
430
+ - Type: ${schedule.priceCorrection} (${schedule.correctionType})
431
+ - Value: ${schedule.correctionValue}${schedule.correctionType === 'PERCENTAGE' ? '%' : ''}
432
+ - Sale Price: ${schedule.salePrice}`
433
+ }]
434
+ };
435
+ } catch (error) {
436
+ return {
437
+ content: [{
438
+ type: "text",
439
+ text: `❌ **Schedule Update Failed**
440
+
441
+ **Error:** ${error.message}
442
+ **Product ID:** ${productId}
443
+ **Schedule ID:** ${scheduleId}`
444
+ }]
445
+ };
446
+ }
447
+ }
448
+ };
449
+
450
+ /**
451
+ * Delete schedule tool implementation for ISVs
452
+ */
453
+ export const deleteScheduleTool = {
454
+ name: "payware_products_delete_schedule",
455
+ description: "Delete a price schedule (ISV operation). This action cannot be undone.",
456
+
457
+ inputSchema: {
458
+ type: "object",
459
+ properties: {
460
+ ...ISV_AUTH_PROPS,
461
+ productId: {
462
+ type: "string",
463
+ description: "Product identifier (starts with 'pr')",
464
+ pattern: "^pr[a-zA-Z0-9]+$"
465
+ },
466
+ scheduleId: {
467
+ type: "number",
468
+ description: "Schedule identifier"
469
+ },
470
+ useSandbox: {
471
+ type: "boolean",
472
+ description: "Use sandbox environment",
473
+ default: true
474
+ }
475
+ },
476
+ required: ["merchantPartnerId", "oauth2Token", "productId", "scheduleId"]
477
+ },
478
+
479
+ async handler(args) {
480
+ const { productId, scheduleId, useSandbox = true } = args;
481
+ const { isvPartnerId, privateKey, merchantPartnerId, oauth2Token } = validateISVAuth(args);
482
+
483
+ try {
484
+ const result = await deletePriceSchedule({
485
+ productId,
486
+ scheduleId,
487
+ partnerType: 'isv',
488
+ isvPartnerId,
489
+ privateKey,
490
+ merchantPartnerId,
491
+ oauth2Token,
492
+ useSandbox
493
+ });
494
+
495
+ return {
496
+ content: [{
497
+ type: "text",
498
+ text: `🗑️ **Schedule Deleted Successfully (ISV -> Merchant: ${merchantPartnerId})**
499
+
500
+ **Deleted Schedule:**
501
+ - Product ID: ${productId}
502
+ - Schedule ID: ${scheduleId}
503
+
504
+ **Important Notes:**
505
+ ⚠️ This action cannot be undone
506
+ ⚠️ Product pricing may change if this was an active schedule`
507
+ }]
508
+ };
509
+ } catch (error) {
510
+ return {
511
+ content: [{
512
+ type: "text",
513
+ text: `❌ **Schedule Deletion Failed**
514
+
515
+ **Error:** ${error.message}
516
+ **Product ID:** ${productId}
517
+ **Schedule ID:** ${scheduleId}`
518
+ }]
519
+ };
520
+ }
521
+ }
522
+ };