@payware/mcp-server 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/package.json +69 -66
- package/src/auth/sandbox-setup.js +186 -186
- package/src/isv/index.js +29 -1
- package/src/isv/invitations/index.js +471 -0
- package/src/isv/oauth2/obtain-token.js +19 -8
- package/src/isv/oauth2/token-helper.js +5 -2
- package/src/isv/poi/cancel-price.js +2 -10
- package/src/isv/poi/create.js +19 -0
- package/src/isv/poi/get-poi.js +2 -10
- package/src/isv/poi/get-qrcode.js +2 -10
- package/src/isv/poi/get-status.js +2 -10
- package/src/isv/poi/index.js +5 -0
- package/src/isv/poi/list-pois.js +2 -10
- package/src/isv/poi/set-price.js +217 -225
- package/src/isv/products/create-product.js +313 -313
- package/src/isv/products/update-product.js +264 -264
- package/src/isv/reference/index.js +249 -0
- package/src/isv/shops/index.js +22 -0
- package/src/isv/transactions/cancel-transaction.js +41 -10
- package/src/isv/transactions/create-transaction.js +20 -4
- package/src/isv/transactions/get-status.js +18 -11
- package/src/isv/transactions/process-transaction.js +160 -42
- package/src/isv/transactions/simulate-callback.js +128 -109
- package/src/isv/transactions/transaction-history.js +86 -90
- package/src/merchant/data/generate-report.js +19 -1
- package/src/merchant/index.js +21 -1
- package/src/merchant/logs/index.js +366 -0
- package/src/merchant/products/create-product.js +287 -287
- package/src/merchant/products/update-product.js +281 -281
- package/src/merchant/shops/index.js +18 -0
- package/src/merchant/transactions/cancel-transaction.js +10 -13
- package/src/merchant/transactions/create-transaction.js +88 -8
- package/src/merchant/transactions/get-status.js +40 -11
- package/src/merchant/transactions/process-transaction.js +2 -10
- package/src/merchant/transactions/simulate-callback.js +68 -9
- package/src/merchant/transactions/transaction-history.js +275 -257
- package/src/payment-institution/transactions/create-pi-transaction.js +2 -10
- package/src/payment-institution/transactions/finalize-transaction.js +333 -340
- package/src/payment-institution/transactions/get-transaction-history.js +2 -10
- package/src/payment-institution/transactions/get-transaction-status.js +38 -11
- package/src/payment-institution/transactions/process-pi-transaction.js +2 -10
- package/src/payment-institution/transactions/simulate-pi-callback.js +49 -9
- package/src/payment-institution/transactions/soundbite-transaction.js +2 -10
- package/src/shared/api-errors.js +188 -0
- package/src/shared/auth-headers.js +62 -0
- package/src/shared/data/data-api.js +11 -10
- package/src/shared/deep-links/api.js +5 -4
- package/src/shared/logs/logs-api.js +242 -0
- package/src/shared/poi/poi-create-api.js +419 -0
- package/src/shared/products/products-api.js +17 -16
- package/src/shared/shops/shops-api.js +155 -0
- package/src/tools/advanced-code-generator.js +2255 -2246
- package/src/utils/code-examples/common/auth-examples.js +1484 -1481
- package/src/utils/code-examples/common/helpers.js +7 -4
- package/src/utils/code-examples/isv/oauth2.js +458 -600
- package/src/utils/code-examples/isv/transactions.js +815 -812
- package/MCP-SETUP.md +0 -190
|
@@ -1,341 +1,334 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { createJWTToken } from '../../core/auth/jwt-token.js';
|
|
3
|
-
import { createMinimizedJSON } from '../../core/utils/json-serializer.js';
|
|
4
|
-
import { getSandboxUrl, getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
...(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
- **
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
description: "
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
${
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
**
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
**
|
|
318
|
-
|
|
319
|
-
**
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
5. Include amount, fee, currency for CONFIRMED status
|
|
335
|
-
6. Verify you are authorized to finalize this transaction
|
|
336
|
-
7. Ensure currency matches the original transaction currency`
|
|
337
|
-
}]
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { createJWTToken } from '../../core/auth/jwt-token.js';
|
|
3
|
+
import { createMinimizedJSON } from '../../core/utils/json-serializer.js';
|
|
4
|
+
import { getSandboxUrl, getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
5
|
+
import { apiErrorResult } from '../../shared/api-errors.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Finalize a transaction as a payment institution via payware API
|
|
9
|
+
* Payment institutions can update transaction status after execution in their network
|
|
10
|
+
* @param {Object} params - Transaction finalization parameters
|
|
11
|
+
* @returns {Object} Transaction finalization response
|
|
12
|
+
*/
|
|
13
|
+
export async function finalizeTransaction({
|
|
14
|
+
transactionId,
|
|
15
|
+
status,
|
|
16
|
+
statusMessage,
|
|
17
|
+
amount,
|
|
18
|
+
fee,
|
|
19
|
+
currency,
|
|
20
|
+
partnerId,
|
|
21
|
+
privateKey,
|
|
22
|
+
useSandbox = true
|
|
23
|
+
}) {
|
|
24
|
+
if (!transactionId) {
|
|
25
|
+
throw new Error('Transaction ID is required');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!status || !['CONFIRMED', 'CANCELLED', 'DECLINED', 'FAILED'].includes(status)) {
|
|
29
|
+
throw new Error('status is required and must be one of: CONFIRMED, CANCELLED, DECLINED, FAILED');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (['CANCELLED', 'DECLINED', 'FAILED'].includes(status) && !statusMessage) {
|
|
33
|
+
throw new Error(`statusMessage is required for status: ${status}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (status === 'CONFIRMED') {
|
|
37
|
+
if (!amount) {
|
|
38
|
+
throw new Error('amount is required for CONFIRMED transactions');
|
|
39
|
+
}
|
|
40
|
+
if (!currency) {
|
|
41
|
+
throw new Error('currency is required for CONFIRMED transactions');
|
|
42
|
+
}
|
|
43
|
+
if (fee === undefined) {
|
|
44
|
+
throw new Error('fee is required for CONFIRMED transactions (use 0 for no fee)');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!partnerId || !privateKey) {
|
|
49
|
+
throw new Error('Partner ID and private key are required for proper JWT creation');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Build request body according to payment institution API documentation
|
|
53
|
+
const requestBody = {
|
|
54
|
+
status,
|
|
55
|
+
...(statusMessage && { statusMessage }),
|
|
56
|
+
...(status === 'CONFIRMED' && {
|
|
57
|
+
amount: amount.toString(),
|
|
58
|
+
fee: fee.toString(),
|
|
59
|
+
currency
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Convert to deterministic minimized JSON for SHA-256 calculation
|
|
64
|
+
const minimizedBodyString = createMinimizedJSON(requestBody);
|
|
65
|
+
|
|
66
|
+
// Create JWT token with contentSha256 for the request body (PATCH requires contentSha256)
|
|
67
|
+
const tokenData = createJWTToken(partnerId, privateKey, minimizedBodyString);
|
|
68
|
+
|
|
69
|
+
// Required headers as per payware API documentation
|
|
70
|
+
const headers = {
|
|
71
|
+
'Authorization': `Bearer ${tokenData.token}`,
|
|
72
|
+
'Content-Type': 'application/json',
|
|
73
|
+
'Api-Version': '1' // Required: current API version
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const baseUrl = useSandbox ? getSandboxUrl() : getProductionUrl();
|
|
78
|
+
// Send the exact minimized JSON string that was used for SHA-256 calculation
|
|
79
|
+
const response = await axios.patch(`${baseUrl}/transactions/${transactionId}`, minimizedBodyString, {
|
|
80
|
+
headers,
|
|
81
|
+
// Tell axios to send the string as-is, don't serialize it again
|
|
82
|
+
transformRequest: [(data) => data]
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
transaction: response.data,
|
|
88
|
+
requestId: response.headers['x-request-id'],
|
|
89
|
+
timestamp: new Date().toISOString()
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return apiErrorResult(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Finalize transaction tool implementation
|
|
98
|
+
*/
|
|
99
|
+
export const finalizeTransactionTool = {
|
|
100
|
+
name: "payware_operations_finalize_transaction",
|
|
101
|
+
description: `Finalize a transaction as a payment institution. This updates the transaction status after execution in your payment network.
|
|
102
|
+
|
|
103
|
+
**Payment Institution Finalization:**
|
|
104
|
+
- **CONFIRMED**: Transaction executed successfully (requires amount, fee, currency)
|
|
105
|
+
- **CANCELLED**: Transaction cancelled by creator
|
|
106
|
+
- **DECLINED**: Transaction declined by payment institution (requires statusMessage)
|
|
107
|
+
- **FAILED**: Transaction failed during execution (requires statusMessage)
|
|
108
|
+
|
|
109
|
+
**Requirements:**
|
|
110
|
+
- Only payment institutions can finalize transactions
|
|
111
|
+
- Currency must match the processing currency of the transaction
|
|
112
|
+
- Amount/fee required for CONFIRMED status
|
|
113
|
+
- StatusMessage required for CANCELLED/DECLINED/FAILED status
|
|
114
|
+
- **fee**: payware calculates it, the institution executes it. Echo the \`fee\` from the process response verbatim - do not recompute it from \`feeFixed\`/\`feeRate\` and do not re-round it, or the call is rejected with ERR_FEE_MISMATCH.
|
|
115
|
+
|
|
116
|
+
**API Request Structure:**
|
|
117
|
+
\`\`\`json
|
|
118
|
+
{
|
|
119
|
+
"status": "CONFIRMED",
|
|
120
|
+
"amount": "57.60",
|
|
121
|
+
"fee": "0.29",
|
|
122
|
+
"currency": "EUR"
|
|
123
|
+
}
|
|
124
|
+
\`\`\``,
|
|
125
|
+
inputSchema: {
|
|
126
|
+
type: "object",
|
|
127
|
+
properties: {
|
|
128
|
+
transactionId: {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "Transaction ID to finalize. Format: 2-char prefix + 8-char ID. Supports: 'pw' (standard), 'pr' (product), 'ps' (soundbite)",
|
|
131
|
+
pattern: "^(pw|pr|ps)[0-9A-Za-z]{8}$"
|
|
132
|
+
},
|
|
133
|
+
status: {
|
|
134
|
+
type: "string",
|
|
135
|
+
enum: ["CONFIRMED", "CANCELLED", "DECLINED", "FAILED"],
|
|
136
|
+
description: "Final transaction status"
|
|
137
|
+
},
|
|
138
|
+
statusMessage: {
|
|
139
|
+
type: "string",
|
|
140
|
+
description: "Transaction failure/cancellation reason (required for CANCELLED, DECLINED, FAILED)",
|
|
141
|
+
maxLength: 100
|
|
142
|
+
},
|
|
143
|
+
amount: {
|
|
144
|
+
type: ["number", "string"],
|
|
145
|
+
description: "Final transaction amount (required for CONFIRMED status)",
|
|
146
|
+
minimum: 0.01,
|
|
147
|
+
maximum: 9999999999999.99
|
|
148
|
+
},
|
|
149
|
+
fee: {
|
|
150
|
+
type: ["number", "string"],
|
|
151
|
+
description: "The payware transaction fee. Echo back the `fee` value from the process/get response EXACTLY - payware calculates the fee and the institution executes it. Do not recompute it from feeFixed/feeRate and do not re-round it; it already carries the currency's smallest payable unit (2 decimals for EUR/USD, 0 for JPY, 3 for KWD). A recomputed value is rejected with ERR_FEE_MISMATCH. Required for CONFIRMED status; use 0 when no fee applies.",
|
|
152
|
+
minimum: 0,
|
|
153
|
+
maximum: 9999999999999.99
|
|
154
|
+
},
|
|
155
|
+
currency: {
|
|
156
|
+
type: "string",
|
|
157
|
+
pattern: "^[A-Z]{3}$",
|
|
158
|
+
description: "Transaction currency (required for CONFIRMED status, must match processing currency)"
|
|
159
|
+
},
|
|
160
|
+
partnerId: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: "Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
|
|
163
|
+
default: getPartnerIdSafe()
|
|
164
|
+
},
|
|
165
|
+
privateKey: {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: "RSA private key for JWT token creation. Uses environment-specific private key as default.",
|
|
168
|
+
default: getPrivateKeySafe()
|
|
169
|
+
},
|
|
170
|
+
useSandbox: {
|
|
171
|
+
type: "boolean",
|
|
172
|
+
description: "Use sandbox environment for testing",
|
|
173
|
+
default: true
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
required: ["transactionId", "status"]
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
async handler(args) {
|
|
180
|
+
const {
|
|
181
|
+
transactionId,
|
|
182
|
+
status,
|
|
183
|
+
statusMessage,
|
|
184
|
+
amount,
|
|
185
|
+
fee,
|
|
186
|
+
currency,
|
|
187
|
+
partnerId = getPartnerIdSafe(),
|
|
188
|
+
privateKey = getPrivateKeySafe(args.useSandbox ?? true),
|
|
189
|
+
useSandbox = true
|
|
190
|
+
} = args;
|
|
191
|
+
|
|
192
|
+
if (!transactionId) {
|
|
193
|
+
throw new Error("Transaction ID is required");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!status) {
|
|
197
|
+
throw new Error("status is required and must be one of: CONFIRMED, CANCELLED, DECLINED, FAILED");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Validate status-specific requirements
|
|
201
|
+
if (['CANCELLED', 'DECLINED', 'FAILED'].includes(status) && !statusMessage) {
|
|
202
|
+
throw new Error(`statusMessage is required for status: ${status}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (status === 'CONFIRMED') {
|
|
206
|
+
if (!amount) {
|
|
207
|
+
throw new Error("amount is required for CONFIRMED transactions");
|
|
208
|
+
}
|
|
209
|
+
if (!currency) {
|
|
210
|
+
throw new Error("currency is required for CONFIRMED transactions");
|
|
211
|
+
}
|
|
212
|
+
if (fee === undefined) {
|
|
213
|
+
throw new Error("fee is required for CONFIRMED transactions (use 0 for no fee)");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!partnerId) {
|
|
218
|
+
throw new Error("Partner ID is required. Provide via 'partnerId' parameter or set PAYWARE_PARTNER_ID environment variable.");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!privateKey) {
|
|
222
|
+
throw new Error("Private key is required. Provide via 'privateKey' parameter or set PAYWARE_PRIVATE_KEY environment variable.");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const result = await finalizeTransaction({
|
|
226
|
+
transactionId,
|
|
227
|
+
status,
|
|
228
|
+
statusMessage,
|
|
229
|
+
amount,
|
|
230
|
+
fee,
|
|
231
|
+
currency,
|
|
232
|
+
partnerId,
|
|
233
|
+
privateKey,
|
|
234
|
+
useSandbox
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (result.success) {
|
|
238
|
+
const statusEmojis = {
|
|
239
|
+
CONFIRMED: '✅',
|
|
240
|
+
CANCELLED: '🚫',
|
|
241
|
+
DECLINED: '❌',
|
|
242
|
+
FAILED: '💥'
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const statusEmoji = statusEmojis[status] || '📄';
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
content: [{
|
|
249
|
+
type: "text",
|
|
250
|
+
text: `${statusEmoji} **Transaction Finalized Successfully**
|
|
251
|
+
|
|
252
|
+
**Transaction ID:** ${transactionId}
|
|
253
|
+
**Final Status:** ${status}
|
|
254
|
+
|
|
255
|
+
**Finalization Details:**
|
|
256
|
+
${statusMessage ? `- Status Message: ${statusMessage}` : ''}
|
|
257
|
+
${amount ? `- Final Amount: ${amount} ${currency}` : ''}
|
|
258
|
+
${fee !== undefined ? `- Fee Collected: ${fee} ${currency}` : ''}
|
|
259
|
+
${result.transaction.paymentMethod ? `- Payment Method: ${result.transaction.paymentMethod}` : ''}
|
|
260
|
+
|
|
261
|
+
**Transaction Response:**
|
|
262
|
+
\`\`\`json
|
|
263
|
+
${JSON.stringify(result.transaction, null, 2)}
|
|
264
|
+
\`\`\`
|
|
265
|
+
|
|
266
|
+
**API Call Details:**
|
|
267
|
+
- Endpoint: PATCH ${baseUrl}/transactions/${transactionId}
|
|
268
|
+
- Request ID: ${result.requestId || 'N/A'}
|
|
269
|
+
- Timestamp: ${result.timestamp}
|
|
270
|
+
|
|
271
|
+
**Callbacks Triggered:**
|
|
272
|
+
- **TRANSACTION_FINALIZED** callback sent to all parties
|
|
273
|
+
- Transaction moved to historical records
|
|
274
|
+
- Final status permanently recorded
|
|
275
|
+
|
|
276
|
+
**Next Steps:**
|
|
277
|
+
${status === 'CONFIRMED' ?
|
|
278
|
+
`1. ✅ Payment completed successfully
|
|
279
|
+
2. Transaction funds should be processed in your network
|
|
280
|
+
3. Use \`payware_pi_get_transaction_history\` to retrieve details later` :
|
|
281
|
+
`1. ⚠️ Payment not completed due to: ${statusMessage || status}
|
|
282
|
+
2. Transaction marked as ${status} in payware system
|
|
283
|
+
3. All parties notified via callbacks`
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
**⚠️ Important:**
|
|
287
|
+
- Transaction finalization is **permanent** and cannot be reversed
|
|
288
|
+
- This transaction is now complete in the payware system`
|
|
289
|
+
}]
|
|
290
|
+
};
|
|
291
|
+
} else {
|
|
292
|
+
return {
|
|
293
|
+
content: [{
|
|
294
|
+
type: "text",
|
|
295
|
+
text: `❌ **Transaction Finalization Failed**
|
|
296
|
+
|
|
297
|
+
**Transaction ID:** ${transactionId}
|
|
298
|
+
**Attempted Status:** ${status}
|
|
299
|
+
|
|
300
|
+
**Error Details:**
|
|
301
|
+
- Message: ${result.error.message}
|
|
302
|
+
- Status: ${result.error.status || 'N/A'}
|
|
303
|
+
- Code: ${result.error.code || 'N/A'}
|
|
304
|
+
|
|
305
|
+
**Full Error Response:**
|
|
306
|
+
\`\`\`json
|
|
307
|
+
${JSON.stringify(result.error.details || result.error, null, 2)}
|
|
308
|
+
\`\`\`
|
|
309
|
+
|
|
310
|
+
**Timestamp:** ${result.timestamp}
|
|
311
|
+
|
|
312
|
+
**Common Finalization Issues:**
|
|
313
|
+
1. **ERR_MISSING_TRANSACTION**: Transaction ID not found or expired
|
|
314
|
+
2. **ERR_TRANSACTION_NOT_PROCESSED**: Transaction hasn't been processed yet
|
|
315
|
+
3. **ERR_ALREADY_PROCESSED**: Transaction already finalized
|
|
316
|
+
4. **ERR_INVALID_STATUS**: Invalid status value provided
|
|
317
|
+
5. **ERR_MISSING_STATUS_MESSAGE**: Status message required for failed/declined/cancelled
|
|
318
|
+
6. **ERR_SPECIFYING_CURRENCY_NOT_ALLOWED**: Currency doesn't match transaction currency
|
|
319
|
+
7. **ERR_INVALID_AMOUNT**: Amount validation failed
|
|
320
|
+
8. **ERR_UNAUTHORIZED_OPERATION**: Not authorized to finalize this transaction
|
|
321
|
+
|
|
322
|
+
**Troubleshooting:**
|
|
323
|
+
1. Verify transaction ID is correct: 10 characters total, starts with 'pw' (standard), 'pr' (product), or 'ps' (soundbite)
|
|
324
|
+
2. Ensure transaction has been processed first
|
|
325
|
+
3. Check status is one of: CONFIRMED, CANCELLED, DECLINED, FAILED
|
|
326
|
+
4. Provide statusMessage for non-CONFIRMED statuses
|
|
327
|
+
5. Include amount, fee, currency for CONFIRMED status
|
|
328
|
+
6. Verify you are authorized to finalize this transaction
|
|
329
|
+
7. Ensure currency matches the original transaction currency`
|
|
330
|
+
}]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
341
334
|
};
|