@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.
Files changed (127) hide show
  1. package/.env.example +0 -0
  2. package/README.md +22 -16
  3. package/check-keys.js +0 -0
  4. package/keys/README.md +0 -0
  5. package/mcp-config.json +0 -0
  6. package/package.json +69 -66
  7. package/payware-mcp-config.json +0 -0
  8. package/src/auth/rsa-keys.js +0 -0
  9. package/src/auth/sandbox-setup.js +186 -186
  10. package/src/config/env.js +0 -0
  11. package/src/config/partner-types.js +0 -0
  12. package/src/core/auth/jwt-factory.js +4 -4
  13. package/src/core/auth/jwt-token.js +107 -66
  14. package/src/core/utils/json-serializer.js +5 -5
  15. package/src/core/utils/key-utils.js +0 -0
  16. package/src/index.js +0 -0
  17. package/src/isv/data/index.js +0 -0
  18. package/src/isv/deep-links/delete-product-link.js +0 -0
  19. package/src/isv/deep-links/delete-transaction-link.js +0 -0
  20. package/src/isv/deep-links/get-product-link.js +0 -0
  21. package/src/isv/deep-links/get-transaction-link.js +0 -0
  22. package/src/isv/deep-links/index.js +0 -0
  23. package/src/isv/index.js +29 -1
  24. package/src/isv/invitations/index.js +471 -0
  25. package/src/isv/oauth2/create-token-simple.js +0 -0
  26. package/src/isv/oauth2/get-token-info.js +0 -0
  27. package/src/isv/oauth2/obtain-token.js +19 -8
  28. package/src/isv/oauth2/token-helper.js +5 -2
  29. package/src/isv/poi/cancel-price.js +2 -10
  30. package/src/isv/poi/create.js +19 -0
  31. package/src/isv/poi/get-poi.js +2 -10
  32. package/src/isv/poi/get-qrcode.js +2 -10
  33. package/src/isv/poi/get-status.js +2 -10
  34. package/src/isv/poi/index.js +5 -0
  35. package/src/isv/poi/list-pois.js +2 -10
  36. package/src/isv/poi/set-price.js +217 -225
  37. package/src/isv/products/audios.js +0 -0
  38. package/src/isv/products/create-product.js +313 -313
  39. package/src/isv/products/delete-product.js +0 -0
  40. package/src/isv/products/get-product-image.js +0 -0
  41. package/src/isv/products/get-product.js +0 -0
  42. package/src/isv/products/index.js +0 -0
  43. package/src/isv/products/list-products.js +0 -0
  44. package/src/isv/products/schedules.js +0 -0
  45. package/src/isv/products/update-product.js +264 -264
  46. package/src/isv/reference/index.js +249 -0
  47. package/src/isv/shops/index.js +22 -0
  48. package/src/isv/transactions/cancel-transaction.js +43 -12
  49. package/src/isv/transactions/create-transaction.js +22 -6
  50. package/src/isv/transactions/get-status.js +18 -11
  51. package/src/isv/transactions/process-transaction.js +160 -42
  52. package/src/isv/transactions/simulate-callback.js +128 -109
  53. package/src/isv/transactions/transaction-history.js +86 -90
  54. package/src/isv/utils/auth.js +2 -2
  55. package/src/mcp-proxy.js +0 -0
  56. package/src/merchant/data/export-report.js +0 -0
  57. package/src/merchant/data/generate-report.js +19 -1
  58. package/src/merchant/data/get-export-list.js +0 -0
  59. package/src/merchant/data/get-report-requests.js +0 -0
  60. package/src/merchant/data/get-report-status.js +0 -0
  61. package/src/merchant/data/index.js +0 -0
  62. package/src/merchant/data/list-reports.js +0 -0
  63. package/src/merchant/deep-links/delete-product-link.js +0 -0
  64. package/src/merchant/deep-links/delete-transaction-link.js +0 -0
  65. package/src/merchant/deep-links/get-product-link.js +0 -0
  66. package/src/merchant/deep-links/get-transaction-link.js +0 -0
  67. package/src/merchant/deep-links/index.js +0 -0
  68. package/src/merchant/index.js +21 -1
  69. package/src/merchant/logs/index.js +366 -0
  70. package/src/merchant/products/audios.js +0 -0
  71. package/src/merchant/products/create-product.js +287 -287
  72. package/src/merchant/products/delete-product.js +0 -0
  73. package/src/merchant/products/get-product-image.js +0 -0
  74. package/src/merchant/products/get-product.js +0 -0
  75. package/src/merchant/products/index.js +0 -0
  76. package/src/merchant/products/list-products.js +0 -0
  77. package/src/merchant/products/schedules.js +0 -0
  78. package/src/merchant/products/update-product.js +281 -281
  79. package/src/merchant/shops/index.js +18 -0
  80. package/src/merchant/transactions/cancel-transaction.js +16 -19
  81. package/src/merchant/transactions/create-transaction.js +99 -19
  82. package/src/merchant/transactions/get-status.js +41 -12
  83. package/src/merchant/transactions/process-transaction.js +8 -16
  84. package/src/merchant/transactions/simulate-callback.js +68 -9
  85. package/src/merchant/transactions/transaction-history.js +275 -257
  86. package/src/payment-institution/data/index.js +0 -0
  87. package/src/payment-institution/deep-links/delete-transaction-link.js +0 -0
  88. package/src/payment-institution/deep-links/get-transaction-link.js +0 -0
  89. package/src/payment-institution/deep-links/index.js +0 -0
  90. package/src/payment-institution/index.js +0 -0
  91. package/src/payment-institution/transactions/create-pi-transaction.js +6 -14
  92. package/src/payment-institution/transactions/finalize-transaction.js +333 -340
  93. package/src/payment-institution/transactions/get-transaction-history.js +3 -11
  94. package/src/payment-institution/transactions/get-transaction-status.js +39 -12
  95. package/src/payment-institution/transactions/process-pi-transaction.js +5 -13
  96. package/src/payment-institution/transactions/simulate-pi-callback.js +49 -9
  97. package/src/payment-institution/transactions/soundbite-transaction.js +5 -13
  98. package/src/proxy-server.js +0 -0
  99. package/src/shared/api-errors.js +188 -0
  100. package/src/shared/auth-headers.js +62 -0
  101. package/src/shared/data/data-api.js +11 -10
  102. package/src/shared/deep-links/api.js +5 -4
  103. package/src/shared/index.js +0 -0
  104. package/src/shared/logs/logs-api.js +242 -0
  105. package/src/shared/poi/poi-create-api.js +419 -0
  106. package/src/shared/products/products-api.js +17 -16
  107. package/src/shared/shops/shops-api.js +155 -0
  108. package/src/tools/advanced-code-generator.js +2255 -2246
  109. package/src/utils/code-examples/common/auth-examples.js +1484 -1481
  110. package/src/utils/code-examples/common/helpers.js +7 -4
  111. package/src/utils/code-examples/common/utils-examples.js +0 -0
  112. package/src/utils/code-examples/frameworks/examples.js +4 -4
  113. package/src/utils/code-examples/index.js +0 -0
  114. package/src/utils/code-examples/isv/oauth2.js +458 -600
  115. package/src/utils/code-examples/isv/products.js +8 -8
  116. package/src/utils/code-examples/isv/transactions.js +815 -812
  117. package/src/utils/code-examples/merchant/products.js +0 -0
  118. package/src/utils/code-examples/merchant/transactions.js +9 -9
  119. package/src/utils/code-examples/payment-institution/transactions.js +0 -0
  120. package/src/utils/code-examples/shared/data.js +0 -0
  121. package/src/utils/code-examples/shared/deep-links.js +0 -0
  122. package/src/utils/code-examples/shared/soundbites.js +0 -0
  123. package/src/utils/code-examples.js +24 -24
  124. package/src/utils/format-request.js +3 -3
  125. package/src/utils/json-formatter.js +20 -20
  126. package/src/utils/server-info.js +0 -0
  127. 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
+ }