@payware/mcp-server 1.1.1 → 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/.env.example +0 -0
- package/README.md +22 -16
- package/check-keys.js +0 -0
- package/keys/README.md +0 -0
- package/mcp-config.json +0 -0
- package/package.json +69 -66
- package/payware-mcp-config.json +0 -0
- package/src/auth/rsa-keys.js +0 -0
- package/src/auth/sandbox-setup.js +186 -186
- package/src/config/env.js +0 -0
- package/src/config/partner-types.js +0 -0
- package/src/core/auth/jwt-factory.js +4 -4
- package/src/core/auth/jwt-token.js +107 -66
- package/src/core/utils/json-serializer.js +5 -5
- package/src/core/utils/key-utils.js +0 -0
- package/src/index.js +0 -0
- package/src/isv/data/index.js +0 -0
- package/src/isv/deep-links/delete-product-link.js +0 -0
- package/src/isv/deep-links/delete-transaction-link.js +0 -0
- package/src/isv/deep-links/get-product-link.js +0 -0
- package/src/isv/deep-links/get-transaction-link.js +0 -0
- package/src/isv/deep-links/index.js +0 -0
- package/src/isv/index.js +29 -1
- package/src/isv/invitations/index.js +471 -0
- package/src/isv/oauth2/create-token-simple.js +0 -0
- package/src/isv/oauth2/get-token-info.js +0 -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/audios.js +0 -0
- package/src/isv/products/create-product.js +313 -313
- package/src/isv/products/delete-product.js +0 -0
- package/src/isv/products/get-product-image.js +0 -0
- package/src/isv/products/get-product.js +0 -0
- package/src/isv/products/index.js +0 -0
- package/src/isv/products/list-products.js +0 -0
- package/src/isv/products/schedules.js +0 -0
- 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 +43 -12
- package/src/isv/transactions/create-transaction.js +22 -6
- 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/isv/utils/auth.js +2 -2
- package/src/mcp-proxy.js +0 -0
- package/src/merchant/data/export-report.js +0 -0
- package/src/merchant/data/generate-report.js +19 -1
- package/src/merchant/data/get-export-list.js +0 -0
- package/src/merchant/data/get-report-requests.js +0 -0
- package/src/merchant/data/get-report-status.js +0 -0
- package/src/merchant/data/index.js +0 -0
- package/src/merchant/data/list-reports.js +0 -0
- package/src/merchant/deep-links/delete-product-link.js +0 -0
- package/src/merchant/deep-links/delete-transaction-link.js +0 -0
- package/src/merchant/deep-links/get-product-link.js +0 -0
- package/src/merchant/deep-links/get-transaction-link.js +0 -0
- package/src/merchant/deep-links/index.js +0 -0
- package/src/merchant/index.js +21 -1
- package/src/merchant/logs/index.js +366 -0
- package/src/merchant/products/audios.js +0 -0
- package/src/merchant/products/create-product.js +287 -287
- package/src/merchant/products/delete-product.js +0 -0
- package/src/merchant/products/get-product-image.js +0 -0
- package/src/merchant/products/get-product.js +0 -0
- package/src/merchant/products/index.js +0 -0
- package/src/merchant/products/list-products.js +0 -0
- package/src/merchant/products/schedules.js +0 -0
- package/src/merchant/products/update-product.js +281 -281
- package/src/merchant/shops/index.js +18 -0
- package/src/merchant/transactions/cancel-transaction.js +16 -19
- package/src/merchant/transactions/create-transaction.js +99 -19
- package/src/merchant/transactions/get-status.js +41 -12
- package/src/merchant/transactions/process-transaction.js +8 -16
- package/src/merchant/transactions/simulate-callback.js +68 -9
- package/src/merchant/transactions/transaction-history.js +275 -257
- package/src/payment-institution/data/index.js +0 -0
- package/src/payment-institution/deep-links/delete-transaction-link.js +0 -0
- package/src/payment-institution/deep-links/get-transaction-link.js +0 -0
- package/src/payment-institution/deep-links/index.js +0 -0
- package/src/payment-institution/index.js +0 -0
- package/src/payment-institution/transactions/create-pi-transaction.js +6 -14
- package/src/payment-institution/transactions/finalize-transaction.js +333 -340
- package/src/payment-institution/transactions/get-transaction-history.js +3 -11
- package/src/payment-institution/transactions/get-transaction-status.js +39 -12
- package/src/payment-institution/transactions/process-pi-transaction.js +5 -13
- package/src/payment-institution/transactions/simulate-pi-callback.js +49 -9
- package/src/payment-institution/transactions/soundbite-transaction.js +5 -13
- package/src/proxy-server.js +0 -0
- 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/index.js +0 -0
- 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/common/utils-examples.js +0 -0
- package/src/utils/code-examples/frameworks/examples.js +4 -4
- package/src/utils/code-examples/index.js +0 -0
- package/src/utils/code-examples/isv/oauth2.js +458 -600
- package/src/utils/code-examples/isv/products.js +8 -8
- package/src/utils/code-examples/isv/transactions.js +815 -812
- package/src/utils/code-examples/merchant/products.js +0 -0
- package/src/utils/code-examples/merchant/transactions.js +9 -9
- package/src/utils/code-examples/payment-institution/transactions.js +0 -0
- package/src/utils/code-examples/shared/data.js +0 -0
- package/src/utils/code-examples/shared/deep-links.js +0 -0
- package/src/utils/code-examples/shared/soundbites.js +0 -0
- package/src/utils/code-examples.js +24 -24
- package/src/utils/format-request.js +3 -3
- package/src/utils/json-formatter.js +20 -20
- package/src/utils/server-info.js +0 -0
- package/MCP-SETUP.md +0 -190
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { createAuthHeaders } from '../auth-headers.js';
|
|
3
|
+
import { apiErrorResult } from '../api-errors.js';
|
|
4
|
+
import { getSandboxUrl, getProductionUrl } from '../../config/env.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shops - the merchant outlets a transaction, product or POI belongs to.
|
|
8
|
+
*
|
|
9
|
+
* `shopCode` is required or defaulted on most write paths in this server (creating a transaction,
|
|
10
|
+
* creating a product, creating a POI, batching POIs), and until now nothing here could tell you what
|
|
11
|
+
* a valid one was. An assistant had two options: leave `shop` out and hope the merchant's default is
|
|
12
|
+
* the right outlet, or invent a code and get a 400. Listing them is one GET.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* List the shops the caller can act on.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} params
|
|
19
|
+
* @param {string} params.partnerType 'merchant' | 'isv'
|
|
20
|
+
* @param {boolean} params.useSandbox
|
|
21
|
+
* @returns {Object} { success, shops, count, requestId, timestamp } or an apiErrorResult
|
|
22
|
+
*/
|
|
23
|
+
export async function listShops({ partnerType, useSandbox = true, ...authParams }) {
|
|
24
|
+
const headers = await createAuthHeaders(partnerType, authParams);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const baseUrl = useSandbox ? getSandboxUrl() : getProductionUrl();
|
|
28
|
+
const response = await axios.get(`${baseUrl}/shops`, { headers });
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
success: true,
|
|
32
|
+
shops: response.data,
|
|
33
|
+
count: Array.isArray(response.data) ? response.data.length : 0,
|
|
34
|
+
requestId: response.headers['x-request-id'],
|
|
35
|
+
timestamp: new Date().toISOString()
|
|
36
|
+
};
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return apiErrorResult(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Shared list-shops tool. Registered for both the merchant and ISV roles; `partnerType` decides how
|
|
44
|
+
* the request is signed and, on the server side, whose shops come back.
|
|
45
|
+
*/
|
|
46
|
+
export function buildListShopsTool({ partnerType, resolveAuth }) {
|
|
47
|
+
const isIsv = partnerType === 'isv';
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
name: 'payware_shops_list',
|
|
51
|
+
description: `List the merchant outlets (shops) the caller can act on.
|
|
52
|
+
|
|
53
|
+
**Endpoint:** GET /shops
|
|
54
|
+
|
|
55
|
+
**Use this before any call that takes a \`shop\` / \`shopCode\`.** Creating a transaction, creating a
|
|
56
|
+
product, creating a POI and batching POIs all take one, and an invalid code is a 400
|
|
57
|
+
(\`ERR_INVALID_SHOP_CODE\`). Omitting it falls back to the merchant's default shop, which is a
|
|
58
|
+
reasonable guess for a single-outlet merchant and the wrong outlet for everyone else - the sale lands
|
|
59
|
+
against the wrong shop, and nothing about the response says so.
|
|
60
|
+
|
|
61
|
+
**Returned per shop:** \`shopCode\` (the value to pass), \`name\`, and the address/contact fields the
|
|
62
|
+
merchant configured.
|
|
63
|
+
${isIsv ? `
|
|
64
|
+
⚠️ **ISVs see only their assigned shops.** This returns the shops the merchant put in your scope, not
|
|
65
|
+
every shop the merchant owns. That is deliberate and it is the same rule the write paths enforce:
|
|
66
|
+
naming a shop outside your scope answers **403 \`ERR_SHOP_NOT_IN_SCOPE\`**. So if a shop you expect is
|
|
67
|
+
missing here, the merchant has not assigned it - ask them to, rather than passing the code anyway.
|
|
68
|
+
|
|
69
|
+
⚠️ **The MERCHANT's plan governs.** An on-behalf call inherits the acting merchant's plan, so this
|
|
70
|
+
answers **403** when that merchant is on **Basic**.
|
|
71
|
+
` : `
|
|
72
|
+
⚠️ **Requires Standard or Premium.** A Basic merchant gets **403**.
|
|
73
|
+
`}
|
|
74
|
+
**Note on financial institutions:** banks do not own shops. A bank principal calling this gets 403,
|
|
75
|
+
not an empty list.`,
|
|
76
|
+
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
required: isIsv ? ['merchantPartnerId', 'oauth2Token'] : [],
|
|
80
|
+
properties: {
|
|
81
|
+
...(isIsv
|
|
82
|
+
? {
|
|
83
|
+
merchantPartnerId: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'Partner ID of the target merchant (8 alphanumeric characters)'
|
|
86
|
+
},
|
|
87
|
+
oauth2Token: {
|
|
88
|
+
type: 'string',
|
|
89
|
+
description: 'OAuth2 access token obtained from the merchant'
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
: {
|
|
93
|
+
partnerId: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
description: 'Partner ID from the payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.'
|
|
96
|
+
},
|
|
97
|
+
privateKey: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'RSA private key for JWT signing. Uses the environment-specific key as default.'
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
useSandbox: {
|
|
103
|
+
type: 'boolean',
|
|
104
|
+
description: 'Use sandbox environment for testing',
|
|
105
|
+
default: true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
async handler(args) {
|
|
111
|
+
const { useSandbox = true } = args;
|
|
112
|
+
const authParams = resolveAuth(args);
|
|
113
|
+
const result = await listShops({ partnerType, useSandbox, ...authParams });
|
|
114
|
+
|
|
115
|
+
if (!result.success) {
|
|
116
|
+
return {
|
|
117
|
+
content: [{
|
|
118
|
+
type: 'text',
|
|
119
|
+
text: `❌ **Failed to List Shops**
|
|
120
|
+
|
|
121
|
+
- Message: ${result.error.message}
|
|
122
|
+
- Status: ${result.error.status || 'N/A'}
|
|
123
|
+
- Code: ${result.error.errorCode || 'N/A'}
|
|
124
|
+
${result.error.correlationId ? `- Correlation ID: ${result.error.correlationId}` : ''}
|
|
125
|
+
${result.error.guidance ? `\n${result.error.guidance}` : ''}
|
|
126
|
+
|
|
127
|
+
**Timestamp:** ${result.timestamp}`
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const shops = Array.isArray(result.shops) ? result.shops : [];
|
|
133
|
+
const list = shops.map(shop => {
|
|
134
|
+
const location = [shop.city, shop.country].filter(Boolean).join(', ');
|
|
135
|
+
return `🏬 **${shop.name || '(unnamed)'}** - \`${shop.shopCode}\`${location ? `\n ${location}` : ''}`;
|
|
136
|
+
}).join('\n');
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
content: [{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: `🏬 **Shops (${result.count})**
|
|
142
|
+
|
|
143
|
+
${list || 'No shops returned.'}
|
|
144
|
+
|
|
145
|
+
Pass a \`shopCode\` above as the \`shop\` parameter when creating a transaction, product or POI.
|
|
146
|
+
${shops.length === 0 ? `
|
|
147
|
+
**An empty list is not necessarily an error.**${isIsv ? ' As an ISV you see only the shops this merchant assigned to your scope - an empty list means none have been assigned yet.' : ' It means no shop is configured for this merchant yet.'}` : ''}
|
|
148
|
+
|
|
149
|
+
**Request ID:** ${result.requestId || 'N/A'}
|
|
150
|
+
**Timestamp:** ${result.timestamp}`
|
|
151
|
+
}]
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|