@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,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partner type definitions and configurations for payware MCP
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const PARTNER_TYPES = {
|
|
6
|
+
MERCHANT: 'merchant',
|
|
7
|
+
ISV: 'isv',
|
|
8
|
+
PAYMENT_INSTITUTION: 'payment_institution'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const PARTNER_TYPE_CONFIGS = {
|
|
12
|
+
[PARTNER_TYPES.MERCHANT]: {
|
|
13
|
+
name: 'Merchant',
|
|
14
|
+
description: 'Direct businesses accepting payments',
|
|
15
|
+
authType: 'standard_jwt', // iss=partnerId, aud="https://payware.eu"
|
|
16
|
+
capabilities: [
|
|
17
|
+
'transaction_create',
|
|
18
|
+
'transaction_status',
|
|
19
|
+
'transaction_cancel',
|
|
20
|
+
'transaction_history',
|
|
21
|
+
'products_api',
|
|
22
|
+
'data_api',
|
|
23
|
+
'soundbites'
|
|
24
|
+
],
|
|
25
|
+
requiredEnvVars: [
|
|
26
|
+
'PAYWARE_PARTNER_ID',
|
|
27
|
+
'PAYWARE_PRIVATE_KEY_PATH'
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
[PARTNER_TYPES.ISV]: {
|
|
32
|
+
name: 'Independent Software Vendor',
|
|
33
|
+
description: 'Software providers serving multiple merchants',
|
|
34
|
+
authType: 'oauth2_jwt', // iss=isvId, aud=merchantId, sub=oauth2Token
|
|
35
|
+
capabilities: [
|
|
36
|
+
'oauth2_management',
|
|
37
|
+
'merchant_onboarding',
|
|
38
|
+
'merchant_management',
|
|
39
|
+
'transaction_create_for_merchant',
|
|
40
|
+
'multi_merchant_operations',
|
|
41
|
+
'products_api',
|
|
42
|
+
'data_api',
|
|
43
|
+
'soundbites'
|
|
44
|
+
],
|
|
45
|
+
requiredEnvVars: [
|
|
46
|
+
'PAYWARE_PARTNER_ID',
|
|
47
|
+
'PAYWARE_PRIVATE_KEY_PATH',
|
|
48
|
+
'PAYWARE_OAUTH_CLIENT_ID',
|
|
49
|
+
'PAYWARE_OAUTH_CLIENT_SECRET'
|
|
50
|
+
],
|
|
51
|
+
optionalEnvVars: [
|
|
52
|
+
'PAYWARE_DEFAULT_MERCHANT_ID'
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
[PARTNER_TYPES.PAYMENT_INSTITUTION]: {
|
|
57
|
+
name: 'Payment Institution',
|
|
58
|
+
description: 'Banks, e-wallets, and financial institutions',
|
|
59
|
+
authType: 'standard_jwt', // iss=partnerId, aud="https://payware.eu"
|
|
60
|
+
capabilities: [
|
|
61
|
+
'consumer_payment_processing',
|
|
62
|
+
'p2p_payments',
|
|
63
|
+
'cross_institution_transfers',
|
|
64
|
+
'transaction_verification',
|
|
65
|
+
'data_api',
|
|
66
|
+
'soundbites'
|
|
67
|
+
],
|
|
68
|
+
requiredEnvVars: [
|
|
69
|
+
'PAYWARE_PARTNER_ID',
|
|
70
|
+
'PAYWARE_PRIVATE_KEY_PATH'
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get partner type configuration
|
|
77
|
+
* @param {string} partnerType - The partner type
|
|
78
|
+
* @returns {Object} Partner type configuration
|
|
79
|
+
* @throws {Error} If partner type is invalid
|
|
80
|
+
*/
|
|
81
|
+
export function getPartnerConfig(partnerType) {
|
|
82
|
+
const config = PARTNER_TYPE_CONFIGS[partnerType];
|
|
83
|
+
if (!config) {
|
|
84
|
+
throw new Error(`Invalid partner type: ${partnerType}. Valid types: ${Object.keys(PARTNER_TYPE_CONFIGS).join(', ')}`);
|
|
85
|
+
}
|
|
86
|
+
return config;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check if partner type has specific capability
|
|
91
|
+
* @param {string} partnerType - The partner type
|
|
92
|
+
* @param {string} capability - The capability to check
|
|
93
|
+
* @returns {boolean} True if partner has capability
|
|
94
|
+
*/
|
|
95
|
+
export function hasCapability(partnerType, capability) {
|
|
96
|
+
try {
|
|
97
|
+
const config = getPartnerConfig(partnerType);
|
|
98
|
+
return config.capabilities.includes(capability);
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get authentication type for partner
|
|
106
|
+
* @param {string} partnerType - The partner type
|
|
107
|
+
* @returns {string} Authentication type
|
|
108
|
+
*/
|
|
109
|
+
export function getAuthType(partnerType) {
|
|
110
|
+
const config = getPartnerConfig(partnerType);
|
|
111
|
+
return config.authType;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Validate partner type
|
|
116
|
+
* @param {string} partnerType - The partner type to validate
|
|
117
|
+
* @returns {boolean} True if valid
|
|
118
|
+
*/
|
|
119
|
+
export function isValidPartnerType(partnerType) {
|
|
120
|
+
return Object.values(PARTNER_TYPES).includes(partnerType);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get all valid partner types
|
|
125
|
+
* @returns {string[]} Array of valid partner types
|
|
126
|
+
*/
|
|
127
|
+
export function getValidPartnerTypes() {
|
|
128
|
+
return Object.values(PARTNER_TYPES);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get partner type display information
|
|
133
|
+
* @param {string} partnerType - The partner type
|
|
134
|
+
* @returns {Object} Display information with name and description
|
|
135
|
+
*/
|
|
136
|
+
export function getPartnerDisplayInfo(partnerType) {
|
|
137
|
+
const config = getPartnerConfig(partnerType);
|
|
138
|
+
return {
|
|
139
|
+
type: partnerType,
|
|
140
|
+
name: config.name,
|
|
141
|
+
description: config.description
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT factory for different partner types
|
|
3
|
+
* Handles the different authentication patterns required by merchant, ISV, and payment institution partners
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createJWTToken } from './jwt-token.js';
|
|
7
|
+
import { getPartnerTypeSafe, isISV, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create JWT token appropriate for the current partner type
|
|
11
|
+
* @param {Object} options - JWT creation options
|
|
12
|
+
* @param {string} options.partnerId - Partner ID (defaults to env var)
|
|
13
|
+
* @param {string} options.privateKey - Private key (defaults to env var)
|
|
14
|
+
* @param {Object} options.requestBody - Request body for POST/PUT/PATCH requests
|
|
15
|
+
* @param {string} options.merchantId - Target merchant ID (ISV only)
|
|
16
|
+
* @param {string} options.oauth2Token - OAuth2 token (ISV only)
|
|
17
|
+
* @returns {Object} JWT token data
|
|
18
|
+
*/
|
|
19
|
+
export async function createJWTForPartner(options = {}) {
|
|
20
|
+
const partnerType = getPartnerTypeSafe();
|
|
21
|
+
const {
|
|
22
|
+
partnerId = getPartnerIdSafe(),
|
|
23
|
+
privateKey = getPrivateKeySafe(),
|
|
24
|
+
requestBody = null,
|
|
25
|
+
merchantId = null,
|
|
26
|
+
oauth2Token = null
|
|
27
|
+
} = options;
|
|
28
|
+
|
|
29
|
+
switch (partnerType) {
|
|
30
|
+
case 'merchant':
|
|
31
|
+
case 'payment_institution':
|
|
32
|
+
return createStandardJWT({
|
|
33
|
+
partnerId,
|
|
34
|
+
privateKey,
|
|
35
|
+
requestBody
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
case 'isv':
|
|
39
|
+
return await createISVJWT({
|
|
40
|
+
isvPartnerId: partnerId,
|
|
41
|
+
merchantPartnerId: merchantId,
|
|
42
|
+
oauth2Token,
|
|
43
|
+
privateKey,
|
|
44
|
+
requestBody
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Unsupported partner type: ${partnerType}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create standard JWT for merchant and payment institution partners
|
|
54
|
+
* @param {Object} options - JWT options
|
|
55
|
+
* @returns {Object} JWT token data
|
|
56
|
+
*/
|
|
57
|
+
function createStandardJWT({ partnerId, privateKey, requestBody }) {
|
|
58
|
+
if (!partnerId || !privateKey) {
|
|
59
|
+
throw new Error('Partner ID and private key are required for standard JWT creation');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return createJWTToken(partnerId, privateKey, requestBody);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create ISV JWT with OAuth2 token and merchant audience
|
|
67
|
+
* @param {Object} options - ISV JWT options
|
|
68
|
+
* @returns {Object} JWT token data with ISV-specific claims
|
|
69
|
+
*/
|
|
70
|
+
async function createISVJWT({ isvPartnerId, merchantPartnerId, oauth2Token, privateKey, requestBody }) {
|
|
71
|
+
if (!isvPartnerId || !privateKey) {
|
|
72
|
+
throw new Error('ISV Partner ID and private key are required for ISV JWT creation');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!merchantPartnerId) {
|
|
76
|
+
throw new Error('Merchant Partner ID is required for ISV JWT creation');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!oauth2Token) {
|
|
80
|
+
throw new Error('OAuth2 token is required for ISV JWT creation');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// For ISV, we need to create a custom JWT with different audience and subject
|
|
84
|
+
const now = Math.floor(Date.now() / 1000);
|
|
85
|
+
|
|
86
|
+
// Create the JWT with ISV-specific claims
|
|
87
|
+
const payload = {
|
|
88
|
+
iss: isvPartnerId, // ISV's partner ID
|
|
89
|
+
aud: merchantPartnerId, // Target merchant's partner ID
|
|
90
|
+
sub: oauth2Token, // OAuth2 token granting permission
|
|
91
|
+
iat: now
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Use the base JWT creation with custom payload
|
|
95
|
+
return await createJWTTokenWithCustomPayload(payload, privateKey, requestBody);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create JWT token with custom payload (for ISV use case)
|
|
100
|
+
* @param {Object} payload - Custom JWT payload
|
|
101
|
+
* @param {string} privateKey - Private key for signing
|
|
102
|
+
* @param {Object} requestBody - Request body for content MD5
|
|
103
|
+
* @returns {Object} JWT token data
|
|
104
|
+
*/
|
|
105
|
+
async function createJWTTokenWithCustomPayload(payload, privateKey, requestBody) {
|
|
106
|
+
// Dynamic imports to avoid circular dependencies
|
|
107
|
+
const jwt = await import('jsonwebtoken');
|
|
108
|
+
const crypto = await import('crypto');
|
|
109
|
+
const { normalizePrivateKey } = await import('../utils/key-utils.js');
|
|
110
|
+
|
|
111
|
+
const normalizedKey = normalizePrivateKey(privateKey);
|
|
112
|
+
|
|
113
|
+
// JWT Header
|
|
114
|
+
const header = {
|
|
115
|
+
alg: 'RS256',
|
|
116
|
+
typ: 'JWT'
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Add contentMd5 to header if request body exists
|
|
120
|
+
if (requestBody) {
|
|
121
|
+
const { createMinimizedJSON } = await import('../utils/json-serializer.js');
|
|
122
|
+
const bodyString = createMinimizedJSON(requestBody);
|
|
123
|
+
header.contentMd5 = crypto.default.createHash('md5').update(bodyString, 'utf8').digest('base64');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const token = jwt.default.sign(payload, normalizedKey, {
|
|
127
|
+
algorithm: 'RS256',
|
|
128
|
+
header: header
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
token,
|
|
133
|
+
partnerId: payload.iss,
|
|
134
|
+
audience: payload.aud,
|
|
135
|
+
subject: payload.sub,
|
|
136
|
+
issuedAt: new Date(payload.iat * 1000).toISOString(),
|
|
137
|
+
contentMd5: header.contentMd5 || null,
|
|
138
|
+
hasBody: !!requestBody,
|
|
139
|
+
isISV: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Validate JWT creation parameters based on partner type
|
|
145
|
+
* @param {Object} options - JWT options to validate
|
|
146
|
+
* @throws {Error} If validation fails
|
|
147
|
+
*/
|
|
148
|
+
export function validateJWTOptions(options = {}) {
|
|
149
|
+
const partnerType = getPartnerTypeSafe();
|
|
150
|
+
const { partnerId, privateKey, merchantId, oauth2Token } = options;
|
|
151
|
+
|
|
152
|
+
// Common validation
|
|
153
|
+
if (!partnerId) {
|
|
154
|
+
throw new Error('Partner ID is required');
|
|
155
|
+
}
|
|
156
|
+
if (!privateKey) {
|
|
157
|
+
throw new Error('Private key is required');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ISV-specific validation
|
|
161
|
+
if (partnerType === 'isv') {
|
|
162
|
+
if (!merchantId) {
|
|
163
|
+
throw new Error('Merchant ID is required for ISV partner type');
|
|
164
|
+
}
|
|
165
|
+
if (!oauth2Token) {
|
|
166
|
+
throw new Error('OAuth2 token is required for ISV partner type');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get authentication headers for API requests
|
|
173
|
+
* @param {string} jwt - JWT token
|
|
174
|
+
* @returns {Object} Headers object
|
|
175
|
+
*/
|
|
176
|
+
export function getAuthHeaders(jwt) {
|
|
177
|
+
return {
|
|
178
|
+
'Authorization': `Bearer ${jwt}`,
|
|
179
|
+
'Content-Type': 'application/json',
|
|
180
|
+
'Api-Version': '1'
|
|
181
|
+
};
|
|
182
|
+
}
|