@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,288 +1,288 @@
|
|
|
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 merchants
|
|
7
|
-
*/
|
|
8
|
-
export const createProductTool = {
|
|
9
|
-
name: "payware_products_create_product",
|
|
10
|
-
description: `Create a new product for inventory management and payment processing.
|
|
11
|
-
|
|
12
|
-
**Product Structure:**
|
|
13
|
-
π¦ **PRODUCT METADATA**: name, shortDescription, longDescription, sku, upc, shippable, active, shop
|
|
14
|
-
π° **PRODUCT DATA** (prData object): type, regularPrice, currency, overlapPriority, timeToLive, activeFrom, activeTo, timeZone
|
|
15
|
-
βοΈ **PRODUCT OPTIONS** (prOptions object): imageUrl, termsUrl, termsText
|
|
16
|
-
|
|
17
|
-
**Required:** name
|
|
18
|
-
**Optional:** All other parameters have sensible defaults`,
|
|
19
|
-
|
|
20
|
-
inputSchema: {
|
|
21
|
-
type: "object",
|
|
22
|
-
properties: {
|
|
23
|
-
name: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Product recognizable name (required)",
|
|
26
|
-
maxLength: 50
|
|
27
|
-
},
|
|
28
|
-
shortDescription: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Short product description",
|
|
31
|
-
maxLength: 150
|
|
32
|
-
},
|
|
33
|
-
longDescription: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Long product description",
|
|
36
|
-
maxLength: 1500
|
|
37
|
-
},
|
|
38
|
-
sku: {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "Stock Keeping Unit (SKU)",
|
|
41
|
-
maxLength: 25
|
|
42
|
-
},
|
|
43
|
-
upc: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "Universal Product Code (UPC)",
|
|
46
|
-
maxLength: 15
|
|
47
|
-
},
|
|
48
|
-
shippable: {
|
|
49
|
-
type: "string",
|
|
50
|
-
enum: ["TRUE", "FALSE"],
|
|
51
|
-
description: "Indicates if product requires delivery address",
|
|
52
|
-
default: "FALSE"
|
|
53
|
-
},
|
|
54
|
-
active: {
|
|
55
|
-
type: "string",
|
|
56
|
-
enum: ["TRUE", "FALSE"],
|
|
57
|
-
description: "Indicates if product can serve as payment source",
|
|
58
|
-
default: "FALSE"
|
|
59
|
-
},
|
|
60
|
-
shop: {
|
|
61
|
-
type: "string",
|
|
62
|
-
description: "Shop code (if not supplied, default shop is used)",
|
|
63
|
-
maxLength: 10
|
|
64
|
-
},
|
|
65
|
-
// Product Data Properties
|
|
66
|
-
productType: {
|
|
67
|
-
type: "string",
|
|
68
|
-
enum: Object.values(PRODUCT_TYPES),
|
|
69
|
-
description: "Type of product",
|
|
70
|
-
default: PRODUCT_TYPES.ITEM
|
|
71
|
-
},
|
|
72
|
-
regularPrice: {
|
|
73
|
-
type: "string",
|
|
74
|
-
description: "Product regular price
|
|
75
|
-
default: "0.00"
|
|
76
|
-
},
|
|
77
|
-
currency: {
|
|
78
|
-
type: "string",
|
|
79
|
-
pattern: "^[A-Z]{3}$",
|
|
80
|
-
description: "Price currency (3-character ISO code)",
|
|
81
|
-
default: "EUR"
|
|
82
|
-
},
|
|
83
|
-
overlapPriority: {
|
|
84
|
-
type: "string",
|
|
85
|
-
enum: Object.values(OVERLAP_PRIORITY),
|
|
86
|
-
description: "Priority when overlapping price schedules exist",
|
|
87
|
-
default: OVERLAP_PRIORITY.LOWEST
|
|
88
|
-
},
|
|
89
|
-
timeToLive: {
|
|
90
|
-
type: "number",
|
|
91
|
-
description: "Time allowed for product payment in seconds (60-2592000)",
|
|
92
|
-
minimum: 60,
|
|
93
|
-
maximum: 2592000,
|
|
94
|
-
default: 86400
|
|
95
|
-
},
|
|
96
|
-
activeFrom: {
|
|
97
|
-
type: "string",
|
|
98
|
-
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
99
|
-
description: "Product active state starting date (YYYY-MM-DD format)"
|
|
100
|
-
},
|
|
101
|
-
activeTo: {
|
|
102
|
-
type: "string",
|
|
103
|
-
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
104
|
-
description: "Product active state ending date (YYYY-MM-DD format)"
|
|
105
|
-
},
|
|
106
|
-
timeZone: {
|
|
107
|
-
type: "string",
|
|
108
|
-
description: "Product state scheduling timezone (IANA format, e.g., 'Europe/Sofia')",
|
|
109
|
-
default: "GMT"
|
|
110
|
-
},
|
|
111
|
-
// Product Options Properties
|
|
112
|
-
imageUrl: {
|
|
113
|
-
type: "string",
|
|
114
|
-
description: "URL pointing to external product image resource",
|
|
115
|
-
maxLength: 150,
|
|
116
|
-
format: "uri"
|
|
117
|
-
},
|
|
118
|
-
termsUrl: {
|
|
119
|
-
type: "string",
|
|
120
|
-
description: "URL pointing to external terms and conditions resource",
|
|
121
|
-
maxLength: 150,
|
|
122
|
-
format: "uri"
|
|
123
|
-
},
|
|
124
|
-
termsText: {
|
|
125
|
-
type: "string",
|
|
126
|
-
description: "Terms and conditions text",
|
|
127
|
-
maxLength: 3000
|
|
128
|
-
},
|
|
129
|
-
// Authentication
|
|
130
|
-
partnerId: {
|
|
131
|
-
type: "string",
|
|
132
|
-
description: "Merchant partner ID (uses PAYWARE_PARTNER_ID env var as default)",
|
|
133
|
-
default: getPartnerIdSafe()
|
|
134
|
-
},
|
|
135
|
-
privateKey: {
|
|
136
|
-
type: "string",
|
|
137
|
-
description: "RSA private key for authentication (uses environment-specific private key as default)",
|
|
138
|
-
default: getPrivateKeySafe(true)
|
|
139
|
-
},
|
|
140
|
-
useSandbox: {
|
|
141
|
-
type: "boolean",
|
|
142
|
-
description: "Use sandbox environment",
|
|
143
|
-
default: true
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
required: ["name"]
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
async handler(args) {
|
|
150
|
-
const {
|
|
151
|
-
name,
|
|
152
|
-
shortDescription,
|
|
153
|
-
longDescription,
|
|
154
|
-
sku,
|
|
155
|
-
upc,
|
|
156
|
-
shippable = "FALSE",
|
|
157
|
-
active = "FALSE",
|
|
158
|
-
shop,
|
|
159
|
-
productType = PRODUCT_TYPES.ITEM,
|
|
160
|
-
regularPrice = "0.00",
|
|
161
|
-
currency = "EUR",
|
|
162
|
-
overlapPriority = OVERLAP_PRIORITY.LOWEST,
|
|
163
|
-
timeToLive = 86400,
|
|
164
|
-
activeFrom,
|
|
165
|
-
activeTo,
|
|
166
|
-
timeZone = "GMT",
|
|
167
|
-
imageUrl,
|
|
168
|
-
termsUrl,
|
|
169
|
-
termsText,
|
|
170
|
-
partnerId = getPartnerIdSafe(),
|
|
171
|
-
privateKey = getPrivateKeySafe(args.useSandbox ?? true),
|
|
172
|
-
useSandbox = true
|
|
173
|
-
} = args;
|
|
174
|
-
|
|
175
|
-
if (!name) {
|
|
176
|
-
throw new Error("Product name is required");
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (!partnerId) {
|
|
180
|
-
throw new Error("Partner ID is required. Provide via 'partnerId' parameter or set PAYWARE_PARTNER_ID environment variable.");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!privateKey) {
|
|
184
|
-
throw new Error("Private key is required. Provide via 'privateKey' parameter or set environment-specific private key variable.");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Build prData object
|
|
188
|
-
const prData = {
|
|
189
|
-
type: productType,
|
|
190
|
-
regularPrice,
|
|
191
|
-
currency,
|
|
192
|
-
overlapPriority,
|
|
193
|
-
timeToLive,
|
|
194
|
-
timeZone
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
if (activeFrom) prData.activeFrom = activeFrom;
|
|
198
|
-
if (activeTo) prData.activeTo = activeTo;
|
|
199
|
-
|
|
200
|
-
// Build prOptions object
|
|
201
|
-
const prOptions = {};
|
|
202
|
-
if (imageUrl) prOptions.imageUrl = imageUrl;
|
|
203
|
-
if (termsUrl) prOptions.termsUrl = termsUrl;
|
|
204
|
-
if (termsText) prOptions.termsText = termsText;
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
const result = await createProduct({
|
|
208
|
-
name,
|
|
209
|
-
shortDescription,
|
|
210
|
-
longDescription,
|
|
211
|
-
sku,
|
|
212
|
-
upc,
|
|
213
|
-
shippable,
|
|
214
|
-
active,
|
|
215
|
-
shop,
|
|
216
|
-
prData,
|
|
217
|
-
prOptions,
|
|
218
|
-
partnerType: 'merchant',
|
|
219
|
-
partnerId,
|
|
220
|
-
privateKey,
|
|
221
|
-
useSandbox
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
const product = result.data;
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
content: [{
|
|
228
|
-
type: "text",
|
|
229
|
-
text: `π¦ **Product Created Successfully**
|
|
230
|
-
|
|
231
|
-
**Product Details:**
|
|
232
|
-
- ID: ${product.productId}
|
|
233
|
-
- Name: ${product.name}
|
|
234
|
-
- Type: ${product.type}
|
|
235
|
-
- Price: ${product.regularPrice} ${product.currencyCode}
|
|
236
|
-
- Status: ${product.active ? 'β
Active' : 'βΈοΈ Inactive'}
|
|
237
|
-
- Shop: ${product.shopCode} (${product.shopName})
|
|
238
|
-
${product.shortDescription ? `- Description: ${product.shortDescription}` : ''}
|
|
239
|
-
${product.sku ? `- SKU: ${product.sku}` : ''}
|
|
240
|
-
${product.upc ? `- UPC: ${product.upc}` : ''}
|
|
241
|
-
|
|
242
|
-
**Product Settings:**
|
|
243
|
-
- Shippable: ${product.shippable ? 'Yes' : 'No'}
|
|
244
|
-
- Time to Live: ${product.timeToLive} seconds
|
|
245
|
-
- Sale Price: ${product.salePrice} ${product.currencyCode}
|
|
246
|
-
- Overlap Priority: ${product.overlapPriority}
|
|
247
|
-
|
|
248
|
-
**Active Period:**
|
|
249
|
-
- From: ${product.activeFromZoned || product.activeFrom}
|
|
250
|
-
- To: ${product.activeToZoned || product.activeTo}
|
|
251
|
-
- Timezone: ${product.timeZone}
|
|
252
|
-
|
|
253
|
-
**API Response:**
|
|
254
|
-
\`\`\`json
|
|
255
|
-
${JSON.stringify(product, null, 2)}
|
|
256
|
-
\`\`\`
|
|
257
|
-
|
|
258
|
-
**API Call Details:**
|
|
259
|
-
- Endpoint: ${result.requestInfo.method} ${result.requestInfo.url}
|
|
260
|
-
- Status: ${result.requestInfo.statusCode}
|
|
261
|
-
|
|
262
|
-
**Next Steps:**
|
|
263
|
-
1. Save the product ID: \`${product.productId}\`
|
|
264
|
-
2. Use \`payware_products_get_product\` to view product details
|
|
265
|
-
3. Use \`payware_products_create_schedule\` to add price schedules
|
|
266
|
-
4. Use \`payware_products_register_audio\` to add soundbites`
|
|
267
|
-
}]
|
|
268
|
-
};
|
|
269
|
-
} catch (error) {
|
|
270
|
-
return {
|
|
271
|
-
content: [{
|
|
272
|
-
type: "text",
|
|
273
|
-
text: `β **Product Creation Failed**
|
|
274
|
-
|
|
275
|
-
**Error Details:**
|
|
276
|
-
- Message: ${error.message}
|
|
277
|
-
|
|
278
|
-
**Troubleshooting:**
|
|
279
|
-
1. Verify JWT token is valid and not expired
|
|
280
|
-
2. Check product parameters (name, price format, dates)
|
|
281
|
-
3. Ensure private key matches public key registered with payware
|
|
282
|
-
4. Verify partner ID and API access
|
|
283
|
-
5. Check sandbox API status`
|
|
284
|
-
}]
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
}
|
|
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 merchants
|
|
7
|
+
*/
|
|
8
|
+
export const createProductTool = {
|
|
9
|
+
name: "payware_products_create_product",
|
|
10
|
+
description: `Create a new product for inventory management and payment processing.
|
|
11
|
+
|
|
12
|
+
**Product Structure:**
|
|
13
|
+
π¦ **PRODUCT METADATA**: name, shortDescription, longDescription, sku, upc, shippable, active, shop
|
|
14
|
+
π° **PRODUCT DATA** (prData object): type, regularPrice, currency, overlapPriority, timeToLive, activeFrom, activeTo, timeZone
|
|
15
|
+
βοΈ **PRODUCT OPTIONS** (prOptions object): imageUrl, termsUrl, termsText
|
|
16
|
+
|
|
17
|
+
**Required:** name
|
|
18
|
+
**Optional:** All other parameters have sensible defaults`,
|
|
19
|
+
|
|
20
|
+
inputSchema: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
name: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Product recognizable name (required)",
|
|
26
|
+
maxLength: 50
|
|
27
|
+
},
|
|
28
|
+
shortDescription: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Short product description",
|
|
31
|
+
maxLength: 150
|
|
32
|
+
},
|
|
33
|
+
longDescription: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "Long product description",
|
|
36
|
+
maxLength: 1500
|
|
37
|
+
},
|
|
38
|
+
sku: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Stock Keeping Unit (SKU)",
|
|
41
|
+
maxLength: 25
|
|
42
|
+
},
|
|
43
|
+
upc: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "Universal Product Code (UPC)",
|
|
46
|
+
maxLength: 15
|
|
47
|
+
},
|
|
48
|
+
shippable: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["TRUE", "FALSE"],
|
|
51
|
+
description: "Indicates if product requires delivery address",
|
|
52
|
+
default: "FALSE"
|
|
53
|
+
},
|
|
54
|
+
active: {
|
|
55
|
+
type: "string",
|
|
56
|
+
enum: ["TRUE", "FALSE"],
|
|
57
|
+
description: "Indicates if product can serve as payment source",
|
|
58
|
+
default: "FALSE"
|
|
59
|
+
},
|
|
60
|
+
shop: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "Shop code (if not supplied, default shop is used)",
|
|
63
|
+
maxLength: 10
|
|
64
|
+
},
|
|
65
|
+
// Product Data Properties
|
|
66
|
+
productType: {
|
|
67
|
+
type: "string",
|
|
68
|
+
enum: Object.values(PRODUCT_TYPES),
|
|
69
|
+
description: "Type of product",
|
|
70
|
+
default: PRODUCT_TYPES.ITEM
|
|
71
|
+
},
|
|
72
|
+
regularPrice: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Product regular price as a decimal string. Zero or positive, at most 12 integer digits, and no more decimals than the currency's minor unit (0 for JPY, 2 for EUR, 3 for KWD, 8 for BTC). Returned as a string too.",
|
|
75
|
+
default: "0.00"
|
|
76
|
+
},
|
|
77
|
+
currency: {
|
|
78
|
+
type: "string",
|
|
79
|
+
pattern: "^[A-Z]{3}$",
|
|
80
|
+
description: "Price currency (3-character ISO code)",
|
|
81
|
+
default: "EUR"
|
|
82
|
+
},
|
|
83
|
+
overlapPriority: {
|
|
84
|
+
type: "string",
|
|
85
|
+
enum: Object.values(OVERLAP_PRIORITY),
|
|
86
|
+
description: "Priority when overlapping price schedules exist",
|
|
87
|
+
default: OVERLAP_PRIORITY.LOWEST
|
|
88
|
+
},
|
|
89
|
+
timeToLive: {
|
|
90
|
+
type: "number",
|
|
91
|
+
description: "Time allowed for product payment in seconds (60-2592000)",
|
|
92
|
+
minimum: 60,
|
|
93
|
+
maximum: 2592000,
|
|
94
|
+
default: 86400
|
|
95
|
+
},
|
|
96
|
+
activeFrom: {
|
|
97
|
+
type: "string",
|
|
98
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
99
|
+
description: "Product active state starting date (YYYY-MM-DD format)"
|
|
100
|
+
},
|
|
101
|
+
activeTo: {
|
|
102
|
+
type: "string",
|
|
103
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
104
|
+
description: "Product active state ending date (YYYY-MM-DD format)"
|
|
105
|
+
},
|
|
106
|
+
timeZone: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: "Product state scheduling timezone (IANA format, e.g., 'Europe/Sofia')",
|
|
109
|
+
default: "GMT"
|
|
110
|
+
},
|
|
111
|
+
// Product Options Properties
|
|
112
|
+
imageUrl: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "URL pointing to external product image resource",
|
|
115
|
+
maxLength: 150,
|
|
116
|
+
format: "uri"
|
|
117
|
+
},
|
|
118
|
+
termsUrl: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "URL pointing to external terms and conditions resource",
|
|
121
|
+
maxLength: 150,
|
|
122
|
+
format: "uri"
|
|
123
|
+
},
|
|
124
|
+
termsText: {
|
|
125
|
+
type: "string",
|
|
126
|
+
description: "Terms and conditions text",
|
|
127
|
+
maxLength: 3000
|
|
128
|
+
},
|
|
129
|
+
// Authentication
|
|
130
|
+
partnerId: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Merchant partner ID (uses PAYWARE_PARTNER_ID env var as default)",
|
|
133
|
+
default: getPartnerIdSafe()
|
|
134
|
+
},
|
|
135
|
+
privateKey: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "RSA private key for authentication (uses environment-specific private key as default)",
|
|
138
|
+
default: getPrivateKeySafe(true)
|
|
139
|
+
},
|
|
140
|
+
useSandbox: {
|
|
141
|
+
type: "boolean",
|
|
142
|
+
description: "Use sandbox environment",
|
|
143
|
+
default: true
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
required: ["name"]
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
async handler(args) {
|
|
150
|
+
const {
|
|
151
|
+
name,
|
|
152
|
+
shortDescription,
|
|
153
|
+
longDescription,
|
|
154
|
+
sku,
|
|
155
|
+
upc,
|
|
156
|
+
shippable = "FALSE",
|
|
157
|
+
active = "FALSE",
|
|
158
|
+
shop,
|
|
159
|
+
productType = PRODUCT_TYPES.ITEM,
|
|
160
|
+
regularPrice = "0.00",
|
|
161
|
+
currency = "EUR",
|
|
162
|
+
overlapPriority = OVERLAP_PRIORITY.LOWEST,
|
|
163
|
+
timeToLive = 86400,
|
|
164
|
+
activeFrom,
|
|
165
|
+
activeTo,
|
|
166
|
+
timeZone = "GMT",
|
|
167
|
+
imageUrl,
|
|
168
|
+
termsUrl,
|
|
169
|
+
termsText,
|
|
170
|
+
partnerId = getPartnerIdSafe(),
|
|
171
|
+
privateKey = getPrivateKeySafe(args.useSandbox ?? true),
|
|
172
|
+
useSandbox = true
|
|
173
|
+
} = args;
|
|
174
|
+
|
|
175
|
+
if (!name) {
|
|
176
|
+
throw new Error("Product name is required");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!partnerId) {
|
|
180
|
+
throw new Error("Partner ID is required. Provide via 'partnerId' parameter or set PAYWARE_PARTNER_ID environment variable.");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!privateKey) {
|
|
184
|
+
throw new Error("Private key is required. Provide via 'privateKey' parameter or set environment-specific private key variable.");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Build prData object
|
|
188
|
+
const prData = {
|
|
189
|
+
type: productType,
|
|
190
|
+
regularPrice,
|
|
191
|
+
currency,
|
|
192
|
+
overlapPriority,
|
|
193
|
+
timeToLive,
|
|
194
|
+
timeZone
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
if (activeFrom) prData.activeFrom = activeFrom;
|
|
198
|
+
if (activeTo) prData.activeTo = activeTo;
|
|
199
|
+
|
|
200
|
+
// Build prOptions object
|
|
201
|
+
const prOptions = {};
|
|
202
|
+
if (imageUrl) prOptions.imageUrl = imageUrl;
|
|
203
|
+
if (termsUrl) prOptions.termsUrl = termsUrl;
|
|
204
|
+
if (termsText) prOptions.termsText = termsText;
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const result = await createProduct({
|
|
208
|
+
name,
|
|
209
|
+
shortDescription,
|
|
210
|
+
longDescription,
|
|
211
|
+
sku,
|
|
212
|
+
upc,
|
|
213
|
+
shippable,
|
|
214
|
+
active,
|
|
215
|
+
shop,
|
|
216
|
+
prData,
|
|
217
|
+
prOptions,
|
|
218
|
+
partnerType: 'merchant',
|
|
219
|
+
partnerId,
|
|
220
|
+
privateKey,
|
|
221
|
+
useSandbox
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const product = result.data;
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
content: [{
|
|
228
|
+
type: "text",
|
|
229
|
+
text: `π¦ **Product Created Successfully**
|
|
230
|
+
|
|
231
|
+
**Product Details:**
|
|
232
|
+
- ID: ${product.productId}
|
|
233
|
+
- Name: ${product.name}
|
|
234
|
+
- Type: ${product.type}
|
|
235
|
+
- Price: ${product.regularPrice} ${product.currencyCode}
|
|
236
|
+
- Status: ${product.active ? 'β
Active' : 'βΈοΈ Inactive'}
|
|
237
|
+
- Shop: ${product.shopCode} (${product.shopName})
|
|
238
|
+
${product.shortDescription ? `- Description: ${product.shortDescription}` : ''}
|
|
239
|
+
${product.sku ? `- SKU: ${product.sku}` : ''}
|
|
240
|
+
${product.upc ? `- UPC: ${product.upc}` : ''}
|
|
241
|
+
|
|
242
|
+
**Product Settings:**
|
|
243
|
+
- Shippable: ${product.shippable ? 'Yes' : 'No'}
|
|
244
|
+
- Time to Live: ${product.timeToLive} seconds
|
|
245
|
+
- Sale Price: ${product.salePrice} ${product.currencyCode}
|
|
246
|
+
- Overlap Priority: ${product.overlapPriority}
|
|
247
|
+
|
|
248
|
+
**Active Period:**
|
|
249
|
+
- From: ${product.activeFromZoned || product.activeFrom}
|
|
250
|
+
- To: ${product.activeToZoned || product.activeTo}
|
|
251
|
+
- Timezone: ${product.timeZone}
|
|
252
|
+
|
|
253
|
+
**API Response:**
|
|
254
|
+
\`\`\`json
|
|
255
|
+
${JSON.stringify(product, null, 2)}
|
|
256
|
+
\`\`\`
|
|
257
|
+
|
|
258
|
+
**API Call Details:**
|
|
259
|
+
- Endpoint: ${result.requestInfo.method} ${result.requestInfo.url}
|
|
260
|
+
- Status: ${result.requestInfo.statusCode}
|
|
261
|
+
|
|
262
|
+
**Next Steps:**
|
|
263
|
+
1. Save the product ID: \`${product.productId}\`
|
|
264
|
+
2. Use \`payware_products_get_product\` to view product details
|
|
265
|
+
3. Use \`payware_products_create_schedule\` to add price schedules
|
|
266
|
+
4. Use \`payware_products_register_audio\` to add soundbites`
|
|
267
|
+
}]
|
|
268
|
+
};
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return {
|
|
271
|
+
content: [{
|
|
272
|
+
type: "text",
|
|
273
|
+
text: `β **Product Creation Failed**
|
|
274
|
+
|
|
275
|
+
**Error Details:**
|
|
276
|
+
- Message: ${error.message}
|
|
277
|
+
|
|
278
|
+
**Troubleshooting:**
|
|
279
|
+
1. Verify JWT token is valid and not expired
|
|
280
|
+
2. Check product parameters (name, price format, dates)
|
|
281
|
+
3. Ensure private key matches public key registered with payware
|
|
282
|
+
4. Verify partner ID and API access
|
|
283
|
+
5. Check sandbox API status`
|
|
284
|
+
}]
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
288
|
};
|