@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.
- package/.env.example +92 -0
- package/MCP-SETUP.md +190 -0
- package/README.md +483 -0
- package/check-keys.js +52 -0
- package/keys/README.md +112 -0
- package/mcp-config.json +9 -0
- package/package.json +66 -0
- package/payware-mcp-config.json +12 -0
- package/src/auth/rsa-keys.js +82 -0
- package/src/auth/sandbox-setup.js +187 -0
- package/src/config/env.js +229 -0
- package/src/config/partner-types.js +143 -0
- package/src/core/auth/jwt-factory.js +182 -0
- package/src/core/auth/jwt-token.js +735 -0
- package/src/core/utils/json-serializer.js +100 -0
- package/src/core/utils/key-utils.js +133 -0
- package/src/index.js +237 -0
- package/src/isv/data/index.js +291 -0
- package/src/isv/deep-links/delete-product-link.js +154 -0
- package/src/isv/deep-links/delete-transaction-link.js +154 -0
- package/src/isv/deep-links/get-product-link.js +167 -0
- package/src/isv/deep-links/get-transaction-link.js +167 -0
- package/src/isv/deep-links/index.js +23 -0
- package/src/isv/index.js +103 -0
- package/src/isv/oauth2/create-token-simple.js +46 -0
- package/src/isv/oauth2/get-token-info.js +157 -0
- package/src/isv/oauth2/obtain-token.js +189 -0
- package/src/isv/oauth2/token-helper.js +151 -0
- package/src/isv/products/audios.js +470 -0
- package/src/isv/products/create-product.js +314 -0
- package/src/isv/products/delete-product.js +119 -0
- package/src/isv/products/get-product-image.js +247 -0
- package/src/isv/products/get-product.js +168 -0
- package/src/isv/products/index.js +65 -0
- package/src/isv/products/list-products.js +136 -0
- package/src/isv/products/schedules.js +522 -0
- package/src/isv/products/update-product.js +265 -0
- package/src/isv/transactions/cancel-transaction.js +129 -0
- package/src/isv/transactions/create-transaction.js +361 -0
- package/src/isv/transactions/get-status.js +217 -0
- package/src/isv/transactions/process-transaction.js +145 -0
- package/src/isv/transactions/simulate-callback.js +146 -0
- package/src/isv/transactions/transaction-history.js +186 -0
- package/src/isv/utils/auth.js +159 -0
- package/src/mcp-proxy.js +150 -0
- package/src/merchant/data/export-report.js +108 -0
- package/src/merchant/data/generate-report.js +151 -0
- package/src/merchant/data/get-report-status.js +120 -0
- package/src/merchant/data/index.js +351 -0
- package/src/merchant/deep-links/delete-product-link.js +121 -0
- package/src/merchant/deep-links/delete-transaction-link.js +121 -0
- package/src/merchant/deep-links/get-product-link.js +134 -0
- package/src/merchant/deep-links/get-transaction-link.js +134 -0
- package/src/merchant/deep-links/index.js +23 -0
- package/src/merchant/index.js +92 -0
- package/src/merchant/products/audios.js +606 -0
- package/src/merchant/products/create-product.js +288 -0
- package/src/merchant/products/delete-product.js +111 -0
- package/src/merchant/products/get-product-image.js +252 -0
- package/src/merchant/products/get-product.js +144 -0
- package/src/merchant/products/index.js +65 -0
- package/src/merchant/products/list-products.js +112 -0
- package/src/merchant/products/schedules.js +646 -0
- package/src/merchant/products/update-product.js +282 -0
- package/src/merchant/transactions/cancel-transaction.js +241 -0
- package/src/merchant/transactions/create-transaction.js +482 -0
- package/src/merchant/transactions/get-status.js +196 -0
- package/src/merchant/transactions/process-transaction.js +349 -0
- package/src/merchant/transactions/simulate-callback.js +246 -0
- package/src/merchant/transactions/transaction-history.js +258 -0
- package/src/payment-institution/data/index.js +280 -0
- package/src/payment-institution/deep-links/delete-transaction-link.js +128 -0
- package/src/payment-institution/deep-links/get-transaction-link.js +141 -0
- package/src/payment-institution/deep-links/index.js +17 -0
- package/src/payment-institution/index.js +92 -0
- package/src/payment-institution/transactions/create-pi-transaction.js +484 -0
- package/src/payment-institution/transactions/finalize-transaction.js +340 -0
- package/src/payment-institution/transactions/get-transaction-history.js +269 -0
- package/src/payment-institution/transactions/get-transaction-status.js +234 -0
- package/src/payment-institution/transactions/process-pi-transaction.js +421 -0
- package/src/payment-institution/transactions/simulate-pi-callback.js +326 -0
- package/src/payment-institution/transactions/soundbite-transaction.js +269 -0
- package/src/proxy-server.js +205 -0
- package/src/shared/data/data-api.js +372 -0
- package/src/shared/deep-links/api.js +214 -0
- package/src/shared/index.js +44 -0
- package/src/shared/products/products-api.js +872 -0
- package/src/tools/advanced-code-generator.js +2247 -0
- package/src/utils/code-examples/common/auth-examples.js +1482 -0
- package/src/utils/code-examples/common/helpers.js +416 -0
- package/src/utils/code-examples/common/utils-examples.js +591 -0
- package/src/utils/code-examples/frameworks/examples.js +859 -0
- package/src/utils/code-examples/index.js +441 -0
- package/src/utils/code-examples/isv/oauth2.js +600 -0
- package/src/utils/code-examples/isv/products.js +666 -0
- package/src/utils/code-examples/isv/transactions.js +813 -0
- package/src/utils/code-examples/merchant/products.js +497 -0
- package/src/utils/code-examples/merchant/transactions.js +623 -0
- package/src/utils/code-examples/payment-institution/transactions.js +388 -0
- package/src/utils/code-examples/shared/data.js +607 -0
- package/src/utils/code-examples/shared/deep-links.js +662 -0
- package/src/utils/code-examples/shared/soundbites.js +808 -0
- package/src/utils/code-examples.js +646 -0
- package/src/utils/format-request.js +363 -0
- package/src/utils/json-formatter.js +249 -0
- package/src/utils/server-info.js +132 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createProduct } from '../../shared/products/products-api.js';
|
|
2
|
+
import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
3
|
+
import { PRODUCT_TYPES, OVERLAP_PRIORITY } from '../../shared/products/products-api.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create product tool implementation for ISVs
|
|
7
|
+
*/
|
|
8
|
+
export const createProductTool = {
|
|
9
|
+
name: "payware_products_create_product",
|
|
10
|
+
description: `Create a new product for inventory management and payment processing on behalf of a merchant (ISV operation).
|
|
11
|
+
|
|
12
|
+
**ISV Authentication**: Requires ISV credentials and OAuth2 token from target merchant.
|
|
13
|
+
|
|
14
|
+
**Product Structure:**
|
|
15
|
+
📦 **PRODUCT METADATA**: name, shortDescription, longDescription, sku, upc, shippable, active, shop
|
|
16
|
+
💰 **PRODUCT DATA** (prData object): type, regularPrice, currency, overlapPriority, timeToLive, activeFrom, activeTo, timeZone
|
|
17
|
+
⚙️ **PRODUCT OPTIONS** (prOptions object): imageUrl, termsUrl, termsText
|
|
18
|
+
|
|
19
|
+
**Required:** merchantPartnerId, oauth2Token, name`,
|
|
20
|
+
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
// ISV Authentication
|
|
25
|
+
merchantPartnerId: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Target merchant partner ID (8 alphanumeric characters, e.g., 'PZAYNMVE')"
|
|
28
|
+
},
|
|
29
|
+
oauth2Token: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "OAuth2 access token obtained from the merchant"
|
|
32
|
+
},
|
|
33
|
+
// Product fields
|
|
34
|
+
name: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Product recognizable name (required)",
|
|
37
|
+
maxLength: 50
|
|
38
|
+
},
|
|
39
|
+
shortDescription: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Short product description",
|
|
42
|
+
maxLength: 150
|
|
43
|
+
},
|
|
44
|
+
longDescription: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "Long product description",
|
|
47
|
+
maxLength: 1500
|
|
48
|
+
},
|
|
49
|
+
sku: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Stock Keeping Unit (SKU)",
|
|
52
|
+
maxLength: 25
|
|
53
|
+
},
|
|
54
|
+
upc: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "Universal Product Code (UPC)",
|
|
57
|
+
maxLength: 15
|
|
58
|
+
},
|
|
59
|
+
shippable: {
|
|
60
|
+
type: "string",
|
|
61
|
+
enum: ["TRUE", "FALSE"],
|
|
62
|
+
description: "Indicates if product requires delivery address",
|
|
63
|
+
default: "FALSE"
|
|
64
|
+
},
|
|
65
|
+
active: {
|
|
66
|
+
type: "string",
|
|
67
|
+
enum: ["TRUE", "FALSE"],
|
|
68
|
+
description: "Indicates if product can serve as payment source",
|
|
69
|
+
default: "FALSE"
|
|
70
|
+
},
|
|
71
|
+
shop: {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Shop code (if not supplied, default shop is used)",
|
|
74
|
+
maxLength: 10
|
|
75
|
+
},
|
|
76
|
+
// Product Data Properties
|
|
77
|
+
productType: {
|
|
78
|
+
type: "string",
|
|
79
|
+
enum: Object.values(PRODUCT_TYPES),
|
|
80
|
+
description: "Type of product",
|
|
81
|
+
default: PRODUCT_TYPES.ITEM
|
|
82
|
+
},
|
|
83
|
+
regularPrice: {
|
|
84
|
+
type: "string",
|
|
85
|
+
description: "Product regular price (positive number with max 2 decimals)",
|
|
86
|
+
default: "0.00"
|
|
87
|
+
},
|
|
88
|
+
currency: {
|
|
89
|
+
type: "string",
|
|
90
|
+
pattern: "^[A-Z]{3}$",
|
|
91
|
+
description: "Price currency (3-character ISO code)",
|
|
92
|
+
default: "EUR"
|
|
93
|
+
},
|
|
94
|
+
overlapPriority: {
|
|
95
|
+
type: "string",
|
|
96
|
+
enum: Object.values(OVERLAP_PRIORITY),
|
|
97
|
+
description: "Priority when overlapping price schedules exist",
|
|
98
|
+
default: OVERLAP_PRIORITY.LOWEST
|
|
99
|
+
},
|
|
100
|
+
timeToLive: {
|
|
101
|
+
type: "number",
|
|
102
|
+
description: "Time allowed for product payment in seconds (60-2592000)",
|
|
103
|
+
minimum: 60,
|
|
104
|
+
maximum: 2592000,
|
|
105
|
+
default: 86400
|
|
106
|
+
},
|
|
107
|
+
activeFrom: {
|
|
108
|
+
type: "string",
|
|
109
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
110
|
+
description: "Product active state starting date (YYYY-MM-DD format)"
|
|
111
|
+
},
|
|
112
|
+
activeTo: {
|
|
113
|
+
type: "string",
|
|
114
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
115
|
+
description: "Product active state ending date (YYYY-MM-DD format)"
|
|
116
|
+
},
|
|
117
|
+
timeZone: {
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "Product state scheduling timezone (IANA format, e.g., 'Europe/Sofia')",
|
|
120
|
+
default: "GMT"
|
|
121
|
+
},
|
|
122
|
+
// Product Options Properties
|
|
123
|
+
imageUrl: {
|
|
124
|
+
type: "string",
|
|
125
|
+
description: "URL pointing to external product image resource",
|
|
126
|
+
maxLength: 150,
|
|
127
|
+
format: "uri"
|
|
128
|
+
},
|
|
129
|
+
termsUrl: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "URL pointing to external terms and conditions resource",
|
|
132
|
+
maxLength: 150,
|
|
133
|
+
format: "uri"
|
|
134
|
+
},
|
|
135
|
+
termsText: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Terms and conditions text",
|
|
138
|
+
maxLength: 3000
|
|
139
|
+
},
|
|
140
|
+
// ISV Environment
|
|
141
|
+
useSandbox: {
|
|
142
|
+
type: "boolean",
|
|
143
|
+
description: "Use sandbox environment",
|
|
144
|
+
default: true
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
required: ["merchantPartnerId", "oauth2Token", "name"]
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
async handler(args) {
|
|
151
|
+
const {
|
|
152
|
+
merchantPartnerId,
|
|
153
|
+
oauth2Token,
|
|
154
|
+
name,
|
|
155
|
+
shortDescription,
|
|
156
|
+
longDescription,
|
|
157
|
+
sku,
|
|
158
|
+
upc,
|
|
159
|
+
shippable = "FALSE",
|
|
160
|
+
active = "FALSE",
|
|
161
|
+
shop,
|
|
162
|
+
productType = PRODUCT_TYPES.ITEM,
|
|
163
|
+
regularPrice = "0.00",
|
|
164
|
+
currency = "EUR",
|
|
165
|
+
overlapPriority = OVERLAP_PRIORITY.LOWEST,
|
|
166
|
+
timeToLive = 86400,
|
|
167
|
+
activeFrom,
|
|
168
|
+
activeTo,
|
|
169
|
+
timeZone = "GMT",
|
|
170
|
+
imageUrl,
|
|
171
|
+
termsUrl,
|
|
172
|
+
termsText,
|
|
173
|
+
useSandbox = true
|
|
174
|
+
} = args;
|
|
175
|
+
|
|
176
|
+
// ISV validation
|
|
177
|
+
if (!merchantPartnerId) {
|
|
178
|
+
throw new Error("Merchant Partner ID is required for ISV operations");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!oauth2Token) {
|
|
182
|
+
throw new Error("OAuth2 token is required for ISV operations");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!name) {
|
|
186
|
+
throw new Error("Product name is required");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Get ISV credentials
|
|
190
|
+
const isvPartnerId = getPartnerIdSafe();
|
|
191
|
+
const privateKey = getPrivateKeySafe(useSandbox);
|
|
192
|
+
|
|
193
|
+
if (!isvPartnerId) {
|
|
194
|
+
throw new Error("ISV Partner ID is required. Set PAYWARE_PARTNER_ID environment variable.");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!privateKey) {
|
|
198
|
+
throw new Error("Private key is required. Set environment-specific private key variable.");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Build prData object
|
|
202
|
+
const prData = {
|
|
203
|
+
type: productType,
|
|
204
|
+
regularPrice,
|
|
205
|
+
currency,
|
|
206
|
+
overlapPriority,
|
|
207
|
+
timeToLive,
|
|
208
|
+
timeZone
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (activeFrom) prData.activeFrom = activeFrom;
|
|
212
|
+
if (activeTo) prData.activeTo = activeTo;
|
|
213
|
+
|
|
214
|
+
// Build prOptions object
|
|
215
|
+
const prOptions = {};
|
|
216
|
+
if (imageUrl) prOptions.imageUrl = imageUrl;
|
|
217
|
+
if (termsUrl) prOptions.termsUrl = termsUrl;
|
|
218
|
+
if (termsText) prOptions.termsText = termsText;
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
const result = await createProduct({
|
|
222
|
+
name,
|
|
223
|
+
shortDescription,
|
|
224
|
+
longDescription,
|
|
225
|
+
sku,
|
|
226
|
+
upc,
|
|
227
|
+
shippable,
|
|
228
|
+
active,
|
|
229
|
+
shop,
|
|
230
|
+
prData,
|
|
231
|
+
prOptions,
|
|
232
|
+
partnerType: 'isv',
|
|
233
|
+
isvPartnerId,
|
|
234
|
+
privateKey,
|
|
235
|
+
merchantPartnerId,
|
|
236
|
+
oauth2Token,
|
|
237
|
+
useSandbox
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const product = result.data;
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
content: [{
|
|
244
|
+
type: "text",
|
|
245
|
+
text: `📦 **Product Created Successfully (ISV -> Merchant: ${merchantPartnerId})**
|
|
246
|
+
|
|
247
|
+
**Product Details:**
|
|
248
|
+
- ID: ${product.productId}
|
|
249
|
+
- Name: ${product.name}
|
|
250
|
+
- Type: ${product.type}
|
|
251
|
+
- Price: ${product.regularPrice} ${product.currencyCode}
|
|
252
|
+
- Status: ${product.active ? '✅ Active' : '⏸️ Inactive'}
|
|
253
|
+
- Shop: ${product.shopCode} (${product.shopName})
|
|
254
|
+
${product.shortDescription ? `- Description: ${product.shortDescription}` : ''}
|
|
255
|
+
${product.sku ? `- SKU: ${product.sku}` : ''}
|
|
256
|
+
${product.upc ? `- UPC: ${product.upc}` : ''}
|
|
257
|
+
|
|
258
|
+
**Product Settings:**
|
|
259
|
+
- Shippable: ${product.shippable ? 'Yes' : 'No'}
|
|
260
|
+
- Time to Live: ${product.timeToLive} seconds
|
|
261
|
+
- Sale Price: ${product.salePrice} ${product.currencyCode}
|
|
262
|
+
- Overlap Priority: ${product.overlapPriority}
|
|
263
|
+
|
|
264
|
+
**Active Period:**
|
|
265
|
+
- From: ${product.activeFromZoned || product.activeFrom}
|
|
266
|
+
- To: ${product.activeToZoned || product.activeTo}
|
|
267
|
+
- Timezone: ${product.timeZone}
|
|
268
|
+
|
|
269
|
+
**ISV Integration Details:**
|
|
270
|
+
- ISV Partner: ${isvPartnerId}
|
|
271
|
+
- Target Merchant: ${merchantPartnerId}
|
|
272
|
+
- OAuth2 Token: ${oauth2Token.substring(0, 8)}...
|
|
273
|
+
|
|
274
|
+
**API Response:**
|
|
275
|
+
\`\`\`json
|
|
276
|
+
${JSON.stringify(product, null, 2)}
|
|
277
|
+
\`\`\`
|
|
278
|
+
|
|
279
|
+
**API Call Details:**
|
|
280
|
+
- Endpoint: ${result.requestInfo.method} ${result.requestInfo.url}
|
|
281
|
+
- Status: ${result.requestInfo.statusCode}
|
|
282
|
+
|
|
283
|
+
**Next Steps:**
|
|
284
|
+
1. Save the product ID: \`${product.productId}\`
|
|
285
|
+
2. Use \`payware_products_get_product\` to view product details
|
|
286
|
+
3. Use \`payware_products_create_schedule\` to add price schedules
|
|
287
|
+
4. Use \`payware_products_register_audio\` to add soundbites`
|
|
288
|
+
}]
|
|
289
|
+
};
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return {
|
|
292
|
+
content: [{
|
|
293
|
+
type: "text",
|
|
294
|
+
text: `❌ **Product Creation Failed**
|
|
295
|
+
|
|
296
|
+
**Error Details:**
|
|
297
|
+
- Message: ${error.message}
|
|
298
|
+
|
|
299
|
+
**ISV Authentication Check:**
|
|
300
|
+
- ISV Partner ID: ${isvPartnerId}
|
|
301
|
+
- Merchant Partner ID: ${merchantPartnerId || 'Missing'}
|
|
302
|
+
- OAuth2 Token: ${oauth2Token ? 'Provided' : 'Missing'}
|
|
303
|
+
|
|
304
|
+
**Troubleshooting:**
|
|
305
|
+
1. Verify OAuth2 token is valid and not expired
|
|
306
|
+
2. Ensure merchant partner ID is correct (8 characters)
|
|
307
|
+
3. Check product parameters (name, price format, dates)
|
|
308
|
+
4. Confirm ISV has authorization to act on behalf of merchant
|
|
309
|
+
5. Verify private key matches public key registered with payware`
|
|
310
|
+
}]
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { deleteProduct } from '../../shared/products/products-api.js';
|
|
2
|
+
import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Delete product tool implementation for ISVs
|
|
6
|
+
*/
|
|
7
|
+
export const deleteProductTool = {
|
|
8
|
+
name: "payware_products_delete_product",
|
|
9
|
+
description: "Delete a product from a merchant account (ISV operation). This action cannot be undone.",
|
|
10
|
+
|
|
11
|
+
inputSchema: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
// ISV Authentication
|
|
15
|
+
merchantPartnerId: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Target merchant partner ID (8 alphanumeric characters, e.g., 'PZAYNMVE')"
|
|
18
|
+
},
|
|
19
|
+
oauth2Token: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "OAuth2 access token obtained from the merchant"
|
|
22
|
+
},
|
|
23
|
+
productId: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Product identifier to delete (starts with 'pr')",
|
|
26
|
+
pattern: "^pr[a-zA-Z0-9]+$"
|
|
27
|
+
},
|
|
28
|
+
useSandbox: {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
description: "Use sandbox environment",
|
|
31
|
+
default: true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
required: ["merchantPartnerId", "oauth2Token", "productId"]
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
async handler(args) {
|
|
38
|
+
const {
|
|
39
|
+
merchantPartnerId,
|
|
40
|
+
oauth2Token,
|
|
41
|
+
productId,
|
|
42
|
+
useSandbox = true
|
|
43
|
+
} = args;
|
|
44
|
+
|
|
45
|
+
// ISV validation
|
|
46
|
+
if (!merchantPartnerId) {
|
|
47
|
+
throw new Error("Merchant Partner ID is required for ISV operations");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!oauth2Token) {
|
|
51
|
+
throw new Error("OAuth2 token is required for ISV operations");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!productId) {
|
|
55
|
+
throw new Error("Product ID is required");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Get ISV credentials
|
|
59
|
+
const isvPartnerId = getPartnerIdSafe();
|
|
60
|
+
const privateKey = getPrivateKeySafe();
|
|
61
|
+
|
|
62
|
+
if (!isvPartnerId || !privateKey) {
|
|
63
|
+
throw new Error("ISV credentials are required");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const result = await deleteProduct({
|
|
68
|
+
productId,
|
|
69
|
+
partnerType: 'isv',
|
|
70
|
+
isvPartnerId,
|
|
71
|
+
privateKey,
|
|
72
|
+
merchantPartnerId,
|
|
73
|
+
oauth2Token,
|
|
74
|
+
useSandbox
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
content: [{
|
|
79
|
+
type: "text",
|
|
80
|
+
text: `🗑️ **Product Deleted Successfully (ISV -> Merchant: ${merchantPartnerId})**
|
|
81
|
+
|
|
82
|
+
**Deleted Product:**
|
|
83
|
+
- ID: ${productId}
|
|
84
|
+
- Status: Successfully removed from merchant account
|
|
85
|
+
|
|
86
|
+
**ISV Integration Details:**
|
|
87
|
+
- ISV Partner: ${isvPartnerId}
|
|
88
|
+
- Target Merchant: ${merchantPartnerId}
|
|
89
|
+
- OAuth2 Token: ${oauth2Token.substring(0, 8)}...
|
|
90
|
+
|
|
91
|
+
**API Call Details:**
|
|
92
|
+
- Endpoint: ${result.requestInfo.method} ${result.requestInfo.url}
|
|
93
|
+
- Status: ${result.requestInfo.statusCode}
|
|
94
|
+
|
|
95
|
+
**Important Notes:**
|
|
96
|
+
⚠️ This action cannot be undone
|
|
97
|
+
⚠️ Any associated price schedules and audios have also been deleted
|
|
98
|
+
⚠️ Active transactions using this product may be affected`
|
|
99
|
+
}]
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return {
|
|
103
|
+
content: [{
|
|
104
|
+
type: "text",
|
|
105
|
+
text: `❌ **Product Deletion Failed**
|
|
106
|
+
|
|
107
|
+
**Error Details:**
|
|
108
|
+
- Message: ${error.message}
|
|
109
|
+
- Product ID: ${productId}
|
|
110
|
+
|
|
111
|
+
**ISV Authentication Check:**
|
|
112
|
+
- ISV Partner ID: ${isvPartnerId}
|
|
113
|
+
- Merchant Partner ID: ${merchantPartnerId || 'Missing'}
|
|
114
|
+
- OAuth2 Token: ${oauth2Token ? 'Provided' : 'Missing'}`
|
|
115
|
+
}]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { getProductImage } from '../../shared/products/products-api.js';
|
|
2
|
+
import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
3
|
+
import { IMAGE_TYPES, IMAGE_FORMATS, QR_ERROR_CORRECTION, BARCODE_LOCATIONS } from '../../shared/products/products-api.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get product image tool implementation for ISVs
|
|
7
|
+
*/
|
|
8
|
+
export const getProductImageTool = {
|
|
9
|
+
name: "payware_products_get_product_image",
|
|
10
|
+
description: `Generate a QR code or barcode image for a merchant's product (ISV operation).`,
|
|
11
|
+
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
// ISV Authentication
|
|
16
|
+
merchantPartnerId: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Target merchant partner ID (8 alphanumeric characters, e.g., 'PZAYNMVE')"
|
|
19
|
+
},
|
|
20
|
+
oauth2Token: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "OAuth2 access token obtained from the merchant"
|
|
23
|
+
},
|
|
24
|
+
productId: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Product identifier (starts with 'pr')",
|
|
27
|
+
pattern: "^pr[a-zA-Z0-9]+$"
|
|
28
|
+
},
|
|
29
|
+
type: {
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: Object.values(IMAGE_TYPES),
|
|
32
|
+
description: "Type of image to generate",
|
|
33
|
+
default: IMAGE_TYPES.QR
|
|
34
|
+
},
|
|
35
|
+
// QR Code Options
|
|
36
|
+
qrFormat: {
|
|
37
|
+
type: "string",
|
|
38
|
+
enum: Object.values(IMAGE_FORMATS),
|
|
39
|
+
description: "QR code image format (applies when type=QR)",
|
|
40
|
+
default: IMAGE_FORMATS.SVG
|
|
41
|
+
},
|
|
42
|
+
qrBorder: {
|
|
43
|
+
type: "number",
|
|
44
|
+
minimum: 1,
|
|
45
|
+
maximum: 10,
|
|
46
|
+
description: "QR code border size in modules (applies when type=QR)",
|
|
47
|
+
default: 4
|
|
48
|
+
},
|
|
49
|
+
qrErrorCorrection: {
|
|
50
|
+
type: "string",
|
|
51
|
+
enum: Object.values(QR_ERROR_CORRECTION),
|
|
52
|
+
description: "QR code error correction level (applies when type=QR)",
|
|
53
|
+
default: QR_ERROR_CORRECTION.QUARTILE
|
|
54
|
+
},
|
|
55
|
+
qrScale: {
|
|
56
|
+
type: "number",
|
|
57
|
+
minimum: 1,
|
|
58
|
+
maximum: 100,
|
|
59
|
+
description: "QR code module size in pixels, irrelevant for SVG (applies when type=QR)",
|
|
60
|
+
default: 16
|
|
61
|
+
},
|
|
62
|
+
qrVersion: {
|
|
63
|
+
type: "number",
|
|
64
|
+
minimum: 1,
|
|
65
|
+
maximum: 40,
|
|
66
|
+
description: "QR code version, higher versions store more data (applies when type=QR)",
|
|
67
|
+
default: 10
|
|
68
|
+
},
|
|
69
|
+
// Barcode Options
|
|
70
|
+
barFormat: {
|
|
71
|
+
type: "string",
|
|
72
|
+
enum: Object.values(IMAGE_FORMATS),
|
|
73
|
+
description: "Barcode image format (applies when type=BARCODE)",
|
|
74
|
+
default: IMAGE_FORMATS.SVG
|
|
75
|
+
},
|
|
76
|
+
barModuleWidth: {
|
|
77
|
+
type: "number",
|
|
78
|
+
minimum: 1,
|
|
79
|
+
maximum: 10,
|
|
80
|
+
description: "Barcode module width in pixels (applies when type=BARCODE)",
|
|
81
|
+
default: 2
|
|
82
|
+
},
|
|
83
|
+
barBarHeight: {
|
|
84
|
+
type: "number",
|
|
85
|
+
minimum: 15,
|
|
86
|
+
maximum: 1000,
|
|
87
|
+
description: "Barcode height in pixels (applies when type=BARCODE)",
|
|
88
|
+
default: 100
|
|
89
|
+
},
|
|
90
|
+
barFontSize: {
|
|
91
|
+
type: "number",
|
|
92
|
+
minimum: 0,
|
|
93
|
+
maximum: 24,
|
|
94
|
+
description: "Barcode font size in pixels (applies when type=BARCODE)",
|
|
95
|
+
default: 12
|
|
96
|
+
},
|
|
97
|
+
barHumanReadableLocation: {
|
|
98
|
+
type: "string",
|
|
99
|
+
enum: Object.values(BARCODE_LOCATIONS),
|
|
100
|
+
description: "Barcode text position (applies when type=BARCODE)",
|
|
101
|
+
default: BARCODE_LOCATIONS.NONE
|
|
102
|
+
},
|
|
103
|
+
useSandbox: {
|
|
104
|
+
type: "boolean",
|
|
105
|
+
description: "Use sandbox environment",
|
|
106
|
+
default: true
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
required: ["merchantPartnerId", "oauth2Token", "productId"]
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
async handler(args) {
|
|
113
|
+
const {
|
|
114
|
+
merchantPartnerId,
|
|
115
|
+
oauth2Token,
|
|
116
|
+
productId,
|
|
117
|
+
type = IMAGE_TYPES.QR,
|
|
118
|
+
qrFormat = IMAGE_FORMATS.SVG,
|
|
119
|
+
qrBorder = 4,
|
|
120
|
+
qrErrorCorrection = QR_ERROR_CORRECTION.QUARTILE,
|
|
121
|
+
qrScale = 16,
|
|
122
|
+
qrVersion = 10,
|
|
123
|
+
barFormat = IMAGE_FORMATS.SVG,
|
|
124
|
+
barModuleWidth = 2,
|
|
125
|
+
barBarHeight = 100,
|
|
126
|
+
barFontSize = 12,
|
|
127
|
+
barHumanReadableLocation = BARCODE_LOCATIONS.NONE,
|
|
128
|
+
useSandbox = true
|
|
129
|
+
} = args;
|
|
130
|
+
|
|
131
|
+
// ISV validation
|
|
132
|
+
if (!merchantPartnerId) {
|
|
133
|
+
throw new Error("Merchant Partner ID is required for ISV operations");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!oauth2Token) {
|
|
137
|
+
throw new Error("OAuth2 token is required for ISV operations");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!productId) {
|
|
141
|
+
throw new Error("Product ID is required");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Get ISV credentials
|
|
145
|
+
const isvPartnerId = getPartnerIdSafe();
|
|
146
|
+
const privateKey = getPrivateKeySafe();
|
|
147
|
+
|
|
148
|
+
if (!isvPartnerId || !privateKey) {
|
|
149
|
+
throw new Error("ISV credentials are required");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Build options based on type
|
|
153
|
+
const qrOptions = type === IMAGE_TYPES.QR ? {
|
|
154
|
+
qrFormat,
|
|
155
|
+
qrBorder,
|
|
156
|
+
qrErrorCorrection,
|
|
157
|
+
qrScale,
|
|
158
|
+
qrVersion
|
|
159
|
+
} : {};
|
|
160
|
+
|
|
161
|
+
const barOptions = type === IMAGE_TYPES.BARCODE ? {
|
|
162
|
+
barFormat,
|
|
163
|
+
barModuleWidth,
|
|
164
|
+
barBarHeight,
|
|
165
|
+
barFontSize,
|
|
166
|
+
barHumanReadableLocation
|
|
167
|
+
} : {};
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const result = await getProductImage({
|
|
171
|
+
productId,
|
|
172
|
+
type,
|
|
173
|
+
qrOptions,
|
|
174
|
+
barOptions,
|
|
175
|
+
partnerType: 'isv',
|
|
176
|
+
isvPartnerId,
|
|
177
|
+
privateKey,
|
|
178
|
+
merchantPartnerId,
|
|
179
|
+
oauth2Token,
|
|
180
|
+
useSandbox
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const imageData = result.data;
|
|
184
|
+
const format = imageData.format;
|
|
185
|
+
const imageType = imageData.type;
|
|
186
|
+
|
|
187
|
+
// Truncate image data for display
|
|
188
|
+
const truncatedData = imageData.imageData.length > 100
|
|
189
|
+
? `${imageData.imageData.substring(0, 100)}... (${imageData.imageData.length} total characters)`
|
|
190
|
+
: imageData.imageData;
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
content: [{
|
|
194
|
+
type: "text",
|
|
195
|
+
text: `🖼️ **Product Image Generated Successfully (ISV -> Merchant: ${merchantPartnerId})**
|
|
196
|
+
|
|
197
|
+
**Image Details:**
|
|
198
|
+
- Product ID: ${imageData.id}
|
|
199
|
+
- Type: ${imageType}
|
|
200
|
+
- Format: ${format}
|
|
201
|
+
- Data Length: ${imageData.imageData.length} characters
|
|
202
|
+
|
|
203
|
+
**ISV Integration Details:**
|
|
204
|
+
- ISV Partner: ${isvPartnerId}
|
|
205
|
+
- Target Merchant: ${merchantPartnerId}
|
|
206
|
+
- OAuth2 Token: ${oauth2Token.substring(0, 8)}...
|
|
207
|
+
|
|
208
|
+
**Configuration Used:**
|
|
209
|
+
${type === IMAGE_TYPES.QR ? `**QR Code Settings:**
|
|
210
|
+
- Format: ${qrFormat}
|
|
211
|
+
- Border: ${qrBorder} modules
|
|
212
|
+
- Error Correction: ${qrErrorCorrection}
|
|
213
|
+
- Scale: ${qrScale}px per module
|
|
214
|
+
- Version: ${qrVersion}` : ''}
|
|
215
|
+
${type === IMAGE_TYPES.BARCODE ? `**Barcode Settings:**
|
|
216
|
+
- Format: ${barFormat}
|
|
217
|
+
- Module Width: ${barModuleWidth}px
|
|
218
|
+
- Height: ${barBarHeight}px
|
|
219
|
+
- Font Size: ${barFontSize}px
|
|
220
|
+
- Text Location: ${barHumanReadableLocation}` : ''}
|
|
221
|
+
|
|
222
|
+
**Image Data (Base64):**
|
|
223
|
+
\`\`\`
|
|
224
|
+
${truncatedData}
|
|
225
|
+
\`\`\``
|
|
226
|
+
}]
|
|
227
|
+
};
|
|
228
|
+
} catch (error) {
|
|
229
|
+
return {
|
|
230
|
+
content: [{
|
|
231
|
+
type: "text",
|
|
232
|
+
text: `❌ **Image Generation Failed**
|
|
233
|
+
|
|
234
|
+
**Error Details:**
|
|
235
|
+
- Message: ${error.message}
|
|
236
|
+
- Product ID: ${productId}
|
|
237
|
+
- Image Type: ${type}
|
|
238
|
+
|
|
239
|
+
**ISV Authentication Check:**
|
|
240
|
+
- ISV Partner ID: ${isvPartnerId}
|
|
241
|
+
- Merchant Partner ID: ${merchantPartnerId || 'Missing'}
|
|
242
|
+
- OAuth2 Token: ${oauth2Token ? 'Provided' : 'Missing'}`
|
|
243
|
+
}]
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|