@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,258 @@
1
+ import axios from 'axios';
2
+ import { createJWTToken } from '../../core/auth/jwt-token.js';
3
+ import { getSandboxUrl, getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
4
+
5
+ /**
6
+ * Get transaction history from payware API (for completed/expired transactions)
7
+ * @param {Object} params - Parameters for history request
8
+ * @returns {Object} Transaction history response
9
+ */
10
+ export async function getTransactionHistory({ transactionId, partnerId, privateKey, useSandbox = true }) {
11
+ if (!transactionId) {
12
+ throw new Error('Transaction ID is required');
13
+ }
14
+
15
+ if (!partnerId || !privateKey) {
16
+ throw new Error('Partner ID and private key are required for proper JWT creation');
17
+ }
18
+
19
+ // Create JWT token without body (GET request - no contentMd5 required)
20
+ const tokenData = createJWTToken(partnerId, privateKey, null);
21
+
22
+ // Required headers as per payware API documentation
23
+ const headers = {
24
+ 'Authorization': `Bearer ${tokenData.token}`,
25
+ 'Content-Type': 'application/json',
26
+ 'Api-Version': '1' // Required: current API version
27
+ };
28
+
29
+ try {
30
+ const baseUrl = useSandbox ? getSandboxUrl() : getProductionUrl();
31
+ const response = await axios.get(`${baseUrl}/transactions-history/${transactionId}`, { headers });
32
+
33
+ return {
34
+ success: true,
35
+ transaction: response.data,
36
+ requestId: response.headers['x-request-id'],
37
+ timestamp: new Date().toISOString()
38
+ };
39
+ } catch (error) {
40
+ return {
41
+ success: false,
42
+ error: {
43
+ message: error.response?.data?.message || error.message,
44
+ status: error.response?.status,
45
+ code: error.response?.data?.errorCode,
46
+ details: error.response?.data,
47
+ throttled: error.response?.status === 415
48
+ },
49
+ timestamp: new Date().toISOString()
50
+ };
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Format transaction history for display
56
+ */
57
+ function formatTransactionHistory(transaction) {
58
+ const statusEmojis = {
59
+ 'CONFIRMED': '✅',
60
+ 'DECLINED': '❌',
61
+ 'FAILED': '💥',
62
+ 'CANCELLED': '🚫',
63
+ 'EXPIRED': '⏰'
64
+ };
65
+
66
+ const typeEmojis = {
67
+ 'DEFAULT': '💳',
68
+ 'SHIPPABLE': '📦',
69
+ 'VOUCHER': '🎫',
70
+ 'CHEQUE': '📝'
71
+ };
72
+
73
+ const status = transaction.status || 'UNKNOWN';
74
+ const type = transaction.transactionType || 'DEFAULT';
75
+ const statusEmoji = statusEmojis[status] || '❓';
76
+ const typeEmoji = typeEmojis[type] || '💳';
77
+
78
+ return {
79
+ statusEmoji,
80
+ typeEmoji,
81
+ status,
82
+ type,
83
+ formattedStatus: `${statusEmoji} ${status}`,
84
+ formattedType: `${typeEmoji} ${type}`
85
+ };
86
+ }
87
+
88
+ /**
89
+ * Get transaction history tool implementation
90
+ */
91
+ export const getTransactionHistoryTool = {
92
+ name: "payware_operations_get_transaction_history",
93
+ description: `Get history of completed/finalized transactions with final statuses (throttled endpoint).
94
+
95
+ **Endpoint:** GET /transactions-history/{transactionId}
96
+ **Use Case:** Retrieve transactions with final statuses: CONFIRMED, DECLINED, FAILED, EXPIRED, CANCELLED.
97
+ **⚠️ THROTTLED:** This endpoint may return HTTP 415 Too Many Requests - implement retry logic.
98
+ **Note:** For ACTIVE transactions, use 'payware_transactions_get_transaction_status' instead.`,
99
+ inputSchema: {
100
+ type: "object",
101
+ properties: {
102
+ transactionId: {
103
+ type: "string",
104
+ description: "Transaction ID to get history for. Format: 2-char prefix + 8-char ID. Supports: 'pw' (standard), 'pr' (product), 'ps' (soundbite)",
105
+ pattern: "^(pw|pr|ps)[0-9A-Za-z]{8}$"
106
+ },
107
+ partnerId: {
108
+ type: "string",
109
+ description: "Partner ID from payware dashboard. Can use PAYWARE_PARTNER_ID env var as default.",
110
+ default: getPartnerIdSafe()
111
+ },
112
+ privateKey: {
113
+ type: "string",
114
+ description: "RSA private key for JWT token creation. Can use PAYWARE_PRIVATE_KEY_PATH env var as default.",
115
+ default: getPrivateKeySafe()
116
+ },
117
+ useSandbox: {
118
+ type: "boolean",
119
+ description: "Use sandbox environment for testing",
120
+ default: true
121
+ }
122
+ },
123
+ required: ["transactionId"],
124
+ additionalProperties: false
125
+ },
126
+
127
+ async handler(args) {
128
+ const { transactionId, partnerId = getPartnerIdSafe(), privateKey = getPrivateKeySafe(args.useSandbox ?? true), useSandbox = true } = args;
129
+
130
+ if (!transactionId) {
131
+ throw new Error("Transaction ID is required");
132
+ }
133
+
134
+ if (!partnerId) {
135
+ throw new Error("Partner ID is required. Provide via 'partnerId' parameter or set PAYWARE_PARTNER_ID environment variable.");
136
+ }
137
+
138
+ if (!privateKey) {
139
+ throw new Error("Private key is required. Provide via 'privateKey' parameter or set PAYWARE_PRIVATE_KEY environment variable.");
140
+ }
141
+
142
+ const result = await getTransactionHistory({ transactionId, partnerId, privateKey, useSandbox });
143
+
144
+ if (result.success) {
145
+ const formatInfo = formatTransactionHistory(result.transaction);
146
+
147
+ // Format dates
148
+ const created = result.transaction.created ? new Date(result.transaction.created * 1000).toISOString() : 'N/A';
149
+ const finalized = result.transaction.finalized ? new Date(result.transaction.finalized * 1000).toISOString() : 'N/A';
150
+
151
+ return {
152
+ content: [{
153
+ type: "text",
154
+ text: `📊 **Transaction History Retrieved**
155
+
156
+ **Transaction:** ${transactionId}
157
+ **Type:** ${formatInfo.formattedType}
158
+ **Status:** ${formatInfo.formattedStatus}
159
+
160
+ **Transaction Details:**
161
+ - ID: ${result.transaction.transactionId || 'N/A'}
162
+ - Initiated By: ${result.transaction.initiatedBy || 'N/A'}
163
+ - Amount: ${result.transaction.amount ? `${result.transaction.amount} ${result.transaction.currency}` : 'N/A'}
164
+ - Reason: ${result.transaction.reasonL1 || 'N/A'}${result.transaction.reasonL2 ? ` (${result.transaction.reasonL2})` : ''}
165
+
166
+ **Parties:**
167
+ - Payee: ${result.transaction.payeeFriendlyName || 'N/A'} (${result.transaction.payeeAccount || 'N/A'})
168
+ - Payer: ${result.transaction.payerFriendlyName || 'N/A'} (${result.transaction.payerAccount || 'N/A'})
169
+ - Payee BIC: ${result.transaction.payeeBIC || 'N/A'}
170
+ - Payer BIC: ${result.transaction.payerBIC || 'N/A'}
171
+
172
+ **Timeline:**
173
+ - Created: ${created}
174
+ - Finalized: ${finalized}
175
+ - Time to Live: ${result.transaction.timeToLive || 'N/A'} seconds
176
+
177
+ **Status Information:**
178
+ ${result.transaction.status ? `- Final Status: ${formatInfo.formattedStatus}` : ''}
179
+ ${result.transaction.statusMessage ? `- Status Message: ${result.transaction.statusMessage}` : ''}
180
+
181
+ ${result.transaction.deliveryAddress ? `
182
+ **Delivery Address:**
183
+ - Name: ${result.transaction.deliveryAddress.fullName || 'N/A'}
184
+ - Address: ${result.transaction.deliveryAddress.streetAddressLine1 || 'N/A'}
185
+ ${result.transaction.deliveryAddress.streetAddressLine2 ? ` ${result.transaction.deliveryAddress.streetAddressLine2}` : ''}
186
+ - City: ${result.transaction.deliveryAddress.city || 'N/A'}, ${result.transaction.deliveryAddress.zipCode || 'N/A'}
187
+ - Region: ${result.transaction.deliveryAddress.region || 'N/A'}
188
+ - Country: ${result.transaction.deliveryAddress.country || 'N/A'}
189
+ - Phone: ${result.transaction.deliveryAddress.phoneNumber || 'N/A'}
190
+ - Email: ${result.transaction.deliveryAddress.email || 'N/A'}
191
+ ` : ''}
192
+
193
+ **Full Response:**
194
+ \`\`\`json
195
+ ${JSON.stringify(result.transaction, null, 2)}
196
+ \`\`\`
197
+
198
+ **Request ID:** ${result.requestId || 'N/A'}
199
+ **Timestamp:** ${result.timestamp}
200
+
201
+ **Status Meanings:**
202
+ - ✅ CONFIRMED: Successfully finalized
203
+ - ❌ DECLINED: Declined by the user, processing or finalizing payment institutions
204
+ - 💥 FAILED: Failed due to technical reasons or other
205
+ - 🚫 CANCELLED: Transaction canceled by the originator
206
+ - ⏰ EXPIRED: Time to live of the transaction has passed
207
+
208
+ **Note:** This endpoint is throttled and only returns transactions with final statuses. ACTIVE transactions cannot be retrieved here.`
209
+ }]
210
+ };
211
+ } else {
212
+ let errorText = `❌ **Failed to Get Transaction History**
213
+
214
+ **Transaction ID:** ${transactionId}
215
+
216
+ **Error Details:**
217
+ - Message: ${result.error.message}
218
+ - Status: ${result.error.status || 'N/A'}
219
+ - Code: ${result.error.code || 'N/A'}`;
220
+
221
+ if (result.error.throttled) {
222
+ errorText += `
223
+
224
+ **⚠️ THROTTLED REQUEST**
225
+ This endpoint has rate limiting. You've made too many requests recently.
226
+ Please wait before trying again.`;
227
+ }
228
+
229
+ errorText += `
230
+
231
+ **Full Error Response:**
232
+ \`\`\`json
233
+ ${JSON.stringify(result.error.details || result.error, null, 2)}
234
+ \`\`\`
235
+
236
+ **Timestamp:** ${result.timestamp}
237
+
238
+ **Common Issues:**
239
+ 1. **ERR_MISSING_TRANSACTION**: Transaction ID not found
240
+ 2. **Too Many Requests (415)**: API rate limit exceeded
241
+ 3. **ERR_METHOD_NOT_ALLOWED**: HTTP method issue
242
+
243
+ **Troubleshooting:**
244
+ 1. Verify transaction ID is correct: 10 characters total, starts with 'pw' (standard), 'pr' (product), or 'ps' (soundbite)
245
+ 2. Ensure transaction exists and you have access to it
246
+ 3. If getting rate limit errors, wait 60 seconds before retrying
247
+ 4. For ACTIVE transactions, use 'payware_transactions_get_transaction_status' instead
248
+ 5. This endpoint only returns transactions with final statuses (CONFIRMED, DECLINED, FAILED, EXPIRED, CANCELLED)`;
249
+
250
+ return {
251
+ content: [{
252
+ type: "text",
253
+ text: errorText
254
+ }]
255
+ };
256
+ }
257
+ }
258
+ };
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Payment Institution Data Tools - Complete Data API Implementation
3
+ * Production-only tools for data retrieval, reporting, and export functionality for Payment Institutions
4
+ */
5
+
6
+ import {
7
+ generateReport,
8
+ getReportStatus,
9
+ exportReport,
10
+ getExportStatus,
11
+ downloadExport,
12
+ cancelReport,
13
+ cancelExport,
14
+ REPORT_TYPES,
15
+ EXPORT_FORMATS,
16
+ LOCALES
17
+ } from '../../shared/data/data-api.js';
18
+ import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
19
+
20
+ // Create a payment institution tool factory
21
+ const createPIDataTool = (toolName, apiFunction, description, additionalParams = {}) => ({
22
+ name: `payware_data_${toolName}`,
23
+ description: `${description} (Payment Institution data access)`,
24
+ inputSchema: {
25
+ type: "object",
26
+ additionalProperties: false,
27
+ properties: {
28
+ partnerId: {
29
+ type: "string",
30
+ description: "Payment Institution Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
31
+ default: getPartnerIdSafe()
32
+ },
33
+ privateKey: {
34
+ type: "string",
35
+ description: "Payment Institution RSA private key for authentication. Uses environment-specific private key as default.",
36
+ default: getPrivateKeySafe()
37
+ },
38
+ ...additionalParams
39
+ },
40
+ required: Object.keys(additionalParams)
41
+ },
42
+
43
+ async handler(args) {
44
+ const {
45
+ partnerId = getPartnerIdSafe(),
46
+ privateKey = getPrivateKeySafe()
47
+ } = args;
48
+
49
+ if (!partnerId || !privateKey) {
50
+ throw new Error("Payment Institution Partner ID and private key are required. Set PAYWARE_PARTNER_ID and environment-specific private key variables or provide them as parameters.");
51
+ }
52
+
53
+ try {
54
+ const result = await apiFunction({
55
+ ...args,
56
+ partnerType: 'payment_institution',
57
+ partnerId,
58
+ privateKey
59
+ });
60
+
61
+ return {
62
+ content: [{
63
+ type: "text",
64
+ text: `🏦 **Payment Institution ${description}**\n\n${JSON.stringify(result.data, null, 2)}\n\n**Payment Institution Context:**\n- Partner ID: ${partnerId}\n- Role: Payment Institution (P2P transactions)`
65
+ }]
66
+ };
67
+ } catch (error) {
68
+ throw new Error(`Payment Institution failed to ${toolName.replace('_', ' ')}: ${error.message}`);
69
+ }
70
+ }
71
+ });
72
+
73
+ /**
74
+ * Generate report tool for Payment Institutions
75
+ */
76
+ export const generateReportTool = {
77
+ name: "payware_data_generate_report",
78
+ description: "Generate an asynchronous data report for Payment Institution analysis. Focuses on P2P transaction flows and cross-institution payments. Production only.",
79
+ inputSchema: {
80
+ type: "object",
81
+ additionalProperties: false,
82
+ properties: {
83
+ reportUnitId: {
84
+ type: "string",
85
+ description: "The ID of the report to generate",
86
+ enum: Object.values(REPORT_TYPES),
87
+ default: REPORT_TYPES.PROCESSED_TRANSACTIONS
88
+ },
89
+ dateFrom: {
90
+ type: "string",
91
+ description: "Start date for the reporting period (YYYY-MM-DD format). Required for premium reports.",
92
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
93
+ },
94
+ dateTo: {
95
+ type: "string",
96
+ description: "End date for the reporting period (YYYY-MM-DD format). Required for premium reports.",
97
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
98
+ },
99
+ ignorePagination: {
100
+ type: "boolean",
101
+ description: "If true, return report as single continuous document. If false, paginate results.",
102
+ default: false
103
+ },
104
+ locale: {
105
+ type: "string",
106
+ description: "Locale for the report",
107
+ enum: Object.values(LOCALES),
108
+ default: LOCALES.ENGLISH_US
109
+ },
110
+ timeZone: {
111
+ type: "string",
112
+ description: "Timezone for date calculations (e.g., 'Europe/Sofia', 'America/New_York')",
113
+ default: "GMT"
114
+ },
115
+ partnerId: {
116
+ type: "string",
117
+ description: "Payment Institution Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
118
+ default: getPartnerIdSafe()
119
+ },
120
+ privateKey: {
121
+ type: "string",
122
+ description: "Payment Institution RSA private key for authentication. Uses environment-specific private key as default.",
123
+ default: getPrivateKeySafe()
124
+ }
125
+ },
126
+ required: ["reportUnitId"]
127
+ },
128
+
129
+ async handler(args) {
130
+ const {
131
+ reportUnitId,
132
+ dateFrom,
133
+ dateTo,
134
+ ignorePagination = false,
135
+ locale = LOCALES.ENGLISH_US,
136
+ timeZone = 'GMT',
137
+ partnerId = getPartnerIdSafe(),
138
+ privateKey = getPrivateKeySafe()
139
+ } = args;
140
+
141
+ if (!partnerId || !privateKey) {
142
+ throw new Error("Payment Institution Partner ID and private key are required. Set PAYWARE_PARTNER_ID and environment-specific private key variables or provide them as parameters.");
143
+ }
144
+
145
+ // Check for required date range on premium reports
146
+ const premiumReports = [
147
+ REPORT_TYPES.PROCESSED_TRANSACTIONS,
148
+ REPORT_TYPES.SCHEDULES_LIST,
149
+ REPORT_TYPES.TRANSACTIONS_PER_PRODUCT,
150
+ REPORT_TYPES.SALES_PER_PRODUCT,
151
+ REPORT_TYPES.TRANSACTIONS_PER_WEBPOS
152
+ ];
153
+
154
+ if (premiumReports.includes(reportUnitId) && (!dateFrom || !dateTo)) {
155
+ throw new Error(`Report "${reportUnitId}" requires dateFrom and dateTo parameters (YYYY-MM-DD format)`);
156
+ }
157
+
158
+ try {
159
+ const result = await generateReport({
160
+ reportUnitId,
161
+ dateFrom,
162
+ dateTo,
163
+ ignorePagination,
164
+ locale,
165
+ timeZone,
166
+ partnerType: 'payment_institution',
167
+ partnerId,
168
+ privateKey
169
+ });
170
+
171
+ const reportType = Object.keys(REPORT_TYPES).find(key => REPORT_TYPES[key] === reportUnitId) || reportUnitId;
172
+
173
+ return {
174
+ content: [{
175
+ type: "text",
176
+ text: `🏦 **Payment Institution Data Report Generation Started**
177
+
178
+ **Report Details:**
179
+ - Type: ${reportType}
180
+ - Report Unit ID: ${reportUnitId}
181
+ - Request ID: ${result.data.requestId}
182
+ - Status: ${result.data.status}
183
+ - Generated: ${result.data.generatedAt}
184
+
185
+ **Payment Institution Context:**
186
+ - Partner ID: ${partnerId}
187
+ - Role: Payment Institution (handles P2P transactions)
188
+ - Access: Cross-institution payment flows
189
+
190
+ **Report Parameters:**
191
+ - Date Range: ${dateFrom || 'Default'} to ${dateTo || 'Default'}
192
+ - Timezone: ${timeZone}
193
+ - Locale: ${locale}
194
+ - Pagination: ${ignorePagination ? 'Disabled (single document)' : 'Enabled'}
195
+
196
+ **Next Steps:**
197
+ 1. Save the Request ID: \`${result.data.requestId}\`
198
+ 2. Use "Get Report Status" tool to monitor progress
199
+ 3. When status is "READY", use "Export Report" tool to get the data
200
+
201
+ **Payment Institution Reports Include:**
202
+ - P2P transaction flows (SRC/DST roles)
203
+ - Cross-institution payment data
204
+ - Settlement and reconciliation data
205
+ - Transaction fees and commissions
206
+ - Partner network activity
207
+
208
+ **⚠️ Production Only:**
209
+ This feature is only available in the production environment, not in sandbox.
210
+
211
+ **Note:** Payment Institution reports may include additional data specific to P2P transactions and cross-institution flows that are not available to regular merchants.`
212
+ }]
213
+ };
214
+ } catch (error) {
215
+ throw new Error(`Failed to generate Payment Institution report: ${error.message}`);
216
+ }
217
+ }
218
+ };
219
+
220
+ // Create all other PI data tools
221
+ export const getReportStatusTool = createPIDataTool('get_report_status', getReportStatus, 'Get Report Status', {
222
+ requestId: {
223
+ type: "string",
224
+ description: "The request ID returned from the report generation request (UUID format)"
225
+ }
226
+ });
227
+
228
+ export const exportReportTool = createPIDataTool('export_report', exportReport, 'Export Report', {
229
+ requestId: {
230
+ type: "string",
231
+ description: "The request ID from the report generation (UUID format)"
232
+ },
233
+ outputFormat: {
234
+ type: "string",
235
+ description: "Export format",
236
+ enum: Object.values(EXPORT_FORMATS),
237
+ default: EXPORT_FORMATS.PDF
238
+ }
239
+ });
240
+
241
+ export const getExportStatusTool = createPIDataTool('get_export_status', getExportStatus, 'Get Export Status', {
242
+ exportId: {
243
+ type: "string",
244
+ description: "The export ID returned from the export request (UUID format)"
245
+ }
246
+ });
247
+
248
+ export const downloadExportTool = createPIDataTool('download_export', downloadExport, 'Download Export', {
249
+ exportId: {
250
+ type: "string",
251
+ description: "The export ID from the export request (UUID format)"
252
+ }
253
+ });
254
+
255
+ export const cancelReportTool = createPIDataTool('cancel_report', cancelReport, 'Cancel Report', {
256
+ requestId: {
257
+ type: "string",
258
+ description: "The request ID of the report to cancel (UUID format)"
259
+ }
260
+ });
261
+
262
+ export const cancelExportTool = createPIDataTool('cancel_export', cancelExport, 'Cancel Export', {
263
+ exportId: {
264
+ type: "string",
265
+ description: "The export ID of the export to cancel (UUID format)"
266
+ }
267
+ });
268
+
269
+ /**
270
+ * All Payment Institution data tools
271
+ */
272
+ export const paymentInstitutionDataTools = [
273
+ generateReportTool,
274
+ getReportStatusTool,
275
+ exportReportTool,
276
+ getExportStatusTool,
277
+ downloadExportTool,
278
+ cancelReportTool,
279
+ cancelExportTool
280
+ ];
@@ -0,0 +1,128 @@
1
+ import { deleteTransactionDeepLink } from '../../shared/deep-links/api.js';
2
+ import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
3
+
4
+ /**
5
+ * Delete deep link for a payment institution transaction
6
+ */
7
+ export const deleteTransactionLinkTool = {
8
+ name: "payware_deep_links_delete_transaction_link",
9
+ description: `Delete an active deep link for a transaction where the payment institution acts as source (SRC) or destination (DST). Once deleted, the deep link URL will no longer redirect to the payware mobile app.
10
+
11
+ **Use Cases:**
12
+ - Remove expired transaction links
13
+ - Clean up after transaction completion
14
+ - Security cleanup for sensitive P2P transactions
15
+
16
+ **Important Notes:**
17
+ - Deep links are only supported in production environment
18
+ - Once deleted, the link cannot be recovered - you'll need to create a new one
19
+ - Payment institutions only manage transaction links (no product links)
20
+ - This operation is irreversible`,
21
+
22
+ inputSchema: {
23
+ type: "object",
24
+ properties: {
25
+ transactionId: {
26
+ type: "string",
27
+ description: "The transaction identifier (e.g., 'pw7e4rCToG')",
28
+ pattern: "^[a-zA-Z0-9]+$"
29
+ },
30
+ partnerId: {
31
+ type: "string",
32
+ description: "Payment Institution Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
33
+ default: getPartnerIdSafe()
34
+ },
35
+ privateKey: {
36
+ type: "string",
37
+ description: "RSA private key for JWT token creation. Uses environment-specific private key as default.",
38
+ default: getPrivateKeySafe()
39
+ }
40
+ },
41
+ required: ["transactionId"]
42
+ },
43
+
44
+ async handler(args) {
45
+ const {
46
+ transactionId,
47
+ partnerId = getPartnerIdSafe(),
48
+ privateKey = getPrivateKeySafe()
49
+ } = args;
50
+
51
+ if (!transactionId) {
52
+ throw new Error("transactionId is required");
53
+ }
54
+
55
+ if (!partnerId) {
56
+ throw new Error("Partner ID is required. Provide via 'partnerId' parameter or set PAYWARE_PARTNER_ID environment variable.");
57
+ }
58
+
59
+ if (!privateKey) {
60
+ throw new Error("Private key is required. Provide via 'privateKey' parameter or set PAYWARE_PRIVATE_KEY environment variable.");
61
+ }
62
+
63
+ try {
64
+ const result = await deleteTransactionDeepLink({
65
+ transactionId,
66
+ partnerType: 'payment_institution',
67
+ partnerId,
68
+ privateKey
69
+ });
70
+
71
+ return {
72
+ content: [{
73
+ type: "text",
74
+ text: `✅ **Transaction Deep Link Deleted (Payment Institution)**
75
+
76
+ **Deletion Details:**
77
+ - Transaction ID: ${transactionId}
78
+ - Status: Successfully deleted
79
+ - Link URL: https://url.payware.eu/${transactionId} (now inactive)
80
+
81
+ **Payment Institution Info:**
82
+ - Partner ID: ${partnerId}
83
+ - Role: SRC/DST for P2P transactions
84
+
85
+ **API Call Details:**
86
+ - Endpoint: DELETE ${result.requestInfo.url}
87
+ - Status: ${result.requestInfo.statusCode}
88
+ - Method: ${result.requestInfo.method}
89
+
90
+ **Result:**
91
+ - The deep link is no longer active
92
+ - Mobile redirects will no longer work
93
+ - URL will return an error if accessed
94
+
95
+ **Important Notes:**
96
+ ⚠️ This operation is irreversible
97
+ ⚠️ Create a new link if needed using \`payware_deep_links_get_transaction_link\`
98
+ ⚠️ Any existing shared links will stop working immediately`
99
+ }]
100
+ };
101
+ } catch (error) {
102
+ return {
103
+ content: [{
104
+ type: "text",
105
+ text: `❌ **Failed to Delete Transaction Deep Link (Payment Institution)**
106
+
107
+ **Error Details:**
108
+ - Transaction ID: ${transactionId}
109
+ - Message: ${error.message}
110
+
111
+ **Common Issues:**
112
+ 1. **Link not found**: Deep link may already be deleted or never existed
113
+ 2. **Authentication failed**: Verify partner ID and private key
114
+ 3. **Authorization failed**: Ensure PI is SRC or DST for this transaction
115
+ 4. **Sandbox environment**: Deep links are production-only
116
+ 5. **Invalid transaction ID**: Ensure transaction ID format is correct
117
+
118
+ **Troubleshooting:**
119
+ 1. Check if deep link exists using \`payware_deep_links_get_transaction_link\`
120
+ 2. Verify running in production environment
121
+ 3. Ensure JWT authentication is working
122
+ 4. Confirm payment institution role in transaction
123
+ 5. Ensure transaction ID is correct`
124
+ }]
125
+ };
126
+ }
127
+ }
128
+ };