shabaaspay-mcp-server 1.0.1
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/LICENSE +21 -0
- package/dist/api/client.d.ts +60 -0
- package/dist/api/client.js +214 -0
- package/dist/config/index.d.ts +54 -0
- package/dist/config/index.js +79 -0
- package/dist/enricher/action-suggester.d.ts +2 -0
- package/dist/enricher/action-suggester.js +26 -0
- package/dist/enricher/index.d.ts +2 -0
- package/dist/enricher/index.js +166 -0
- package/dist/enricher/status-analyzer.d.ts +6 -0
- package/dist/enricher/status-analyzer.js +71 -0
- package/dist/enricher/summary-generator.d.ts +8 -0
- package/dist/enricher/summary-generator.js +45 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -0
- package/dist/security/auth.d.ts +4 -0
- package/dist/security/auth.js +30 -0
- package/dist/security/policy.d.ts +18 -0
- package/dist/security/policy.js +35 -0
- package/dist/security/rate-limiter.d.ts +13 -0
- package/dist/security/rate-limiter.js +55 -0
- package/dist/security/validator.d.ts +6 -0
- package/dist/security/validator.js +22 -0
- package/dist/server/http-server.d.ts +28 -0
- package/dist/server/http-server.js +524 -0
- package/dist/server/stdio-server.d.ts +13 -0
- package/dist/server/stdio-server.js +114 -0
- package/dist/server-http.d.ts +2 -0
- package/dist/server-http.js +27 -0
- package/dist/tools/auth.d.ts +17 -0
- package/dist/tools/auth.js +51 -0
- package/dist/tools/index.d.ts +159 -0
- package/dist/tools/index.js +14 -0
- package/dist/tools/payment-agreements.d.ts +68 -0
- package/dist/tools/payment-agreements.js +92 -0
- package/dist/tools/payment-initiations.d.ts +84 -0
- package/dist/tools/payment-initiations.js +162 -0
- package/dist/tools/response-helpers.d.ts +4 -0
- package/dist/tools/response-helpers.js +32 -0
- package/dist/types/index.d.ts +184 -0
- package/dist/types/index.js +80 -0
- package/dist/worker.d.ts +15 -0
- package/dist/worker.js +767 -0
- package/package.json +64 -0
- package/readme.md +113 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ShabaasApiClient } from '../api/client.js';
|
|
3
|
+
import { Config } from '../config/index.js';
|
|
4
|
+
export declare function createAuthTools(apiClient: ShabaasApiClient, config: Config): {
|
|
5
|
+
get_auth_token: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputSchema: z.ZodObject<{
|
|
9
|
+
include_token_in_response: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
include_token_in_response: boolean;
|
|
12
|
+
}, {
|
|
13
|
+
include_token_in_response?: boolean | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
execute: (args: any) => Promise<import("../types/index.js").StandardResponse<unknown>>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthTools = createAuthTools;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const response_helpers_js_1 = require("./response-helpers.js");
|
|
6
|
+
function createAuthTools(apiClient, config) {
|
|
7
|
+
return {
|
|
8
|
+
get_auth_token: {
|
|
9
|
+
name: 'get_auth_token',
|
|
10
|
+
description: 'Call ShaBaas authorization endpoint using the configured UUID and return a Bearer token for debugging. ' +
|
|
11
|
+
'The MCP server automatically manages tokens for all other tools, so you typically do not need to call this.',
|
|
12
|
+
inputSchema: zod_1.z.object({
|
|
13
|
+
include_token_in_response: zod_1.z
|
|
14
|
+
.boolean()
|
|
15
|
+
.optional()
|
|
16
|
+
.default(false)
|
|
17
|
+
.describe('If true, include the raw token string in the response data. Default false for safer logging.'),
|
|
18
|
+
}),
|
|
19
|
+
execute: async (args) => {
|
|
20
|
+
try {
|
|
21
|
+
const includeToken = !!args?.include_token_in_response;
|
|
22
|
+
const auth = await apiClient.getAuthToken();
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
data: includeToken ? auth : { fetchedAt: auth.fetchedAt },
|
|
27
|
+
metadata: {
|
|
28
|
+
requestId: `req_${Date.now()}`,
|
|
29
|
+
processingTime: 0,
|
|
30
|
+
environment: config.environment,
|
|
31
|
+
},
|
|
32
|
+
insights: {
|
|
33
|
+
status: 'success',
|
|
34
|
+
canProceed: true,
|
|
35
|
+
nextActions: ['create_payment_agreement', 'get_payment_agreement', 'initiate_payment', 'get_payment_initiation'],
|
|
36
|
+
warnings: includeToken
|
|
37
|
+
? ['Token is included in the response. Treat it as a secret.']
|
|
38
|
+
: ['Token was fetched and cached inside the MCP server. It is not shown in this response.'],
|
|
39
|
+
},
|
|
40
|
+
summary: includeToken
|
|
41
|
+
? 'Authorization token fetched successfully. Token is included in response data.'
|
|
42
|
+
: 'Authorization token fetched successfully and cached inside the MCP server.',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return (0, response_helpers_js_1.toolErrorResponse)(error?.response?.data?.message || error.message || 'Failed to fetch auth token', config.environment, error?.response?.data);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { ShabaasApiClient } from '../api/client.js';
|
|
2
|
+
import { Config } from '../config/index.js';
|
|
3
|
+
export declare function createAllTools(apiClient: ShabaasApiClient, config: Config): {
|
|
4
|
+
initiate_payment: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: import("zod").ZodObject<{
|
|
8
|
+
payment_agreement_id: import("zod").ZodString;
|
|
9
|
+
amount: import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodNumber]>, string | number, string | number>;
|
|
10
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
11
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
12
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
13
|
+
idempotency_key: import("zod").ZodString;
|
|
14
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
15
|
+
payment_agreement_id: string;
|
|
16
|
+
amount: string | number;
|
|
17
|
+
enrich: boolean;
|
|
18
|
+
include_raw: boolean;
|
|
19
|
+
idempotency_key: string;
|
|
20
|
+
description?: string | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
payment_agreement_id: string;
|
|
23
|
+
amount: string | number;
|
|
24
|
+
idempotency_key: string;
|
|
25
|
+
enrich?: boolean | undefined;
|
|
26
|
+
include_raw?: boolean | undefined;
|
|
27
|
+
description?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
execute: (args: any) => Promise<import("../types/index.js").StandardResponse<any> | {
|
|
30
|
+
raw?: import("../types/index.js").ApiResponse<any> | undefined;
|
|
31
|
+
success: boolean;
|
|
32
|
+
timestamp: string;
|
|
33
|
+
data: any;
|
|
34
|
+
metadata: {
|
|
35
|
+
requestId: string;
|
|
36
|
+
processingTime: number;
|
|
37
|
+
environment: "sandbox" | "production";
|
|
38
|
+
};
|
|
39
|
+
insights: {
|
|
40
|
+
status: any;
|
|
41
|
+
canProceed: boolean;
|
|
42
|
+
nextActions: string[];
|
|
43
|
+
warnings: string[];
|
|
44
|
+
};
|
|
45
|
+
summary: string;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
get_payment_initiation: {
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
inputSchema: import("zod").ZodObject<{
|
|
52
|
+
payment_initiation_id: import("zod").ZodString;
|
|
53
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
54
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
55
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
56
|
+
payment_initiation_id: string;
|
|
57
|
+
enrich: boolean;
|
|
58
|
+
include_raw: boolean;
|
|
59
|
+
}, {
|
|
60
|
+
payment_initiation_id: string;
|
|
61
|
+
enrich?: boolean | undefined;
|
|
62
|
+
include_raw?: boolean | undefined;
|
|
63
|
+
}>;
|
|
64
|
+
execute: (args: any) => Promise<import("../types/index.js").StandardResponse<any> | {
|
|
65
|
+
raw?: import("../types/index.js").ApiResponse<any> | undefined;
|
|
66
|
+
success: boolean;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
data: any;
|
|
69
|
+
metadata: {
|
|
70
|
+
requestId: string;
|
|
71
|
+
processingTime: number;
|
|
72
|
+
environment: "sandbox" | "production";
|
|
73
|
+
};
|
|
74
|
+
insights: {
|
|
75
|
+
status: any;
|
|
76
|
+
canProceed: boolean;
|
|
77
|
+
nextActions: string[];
|
|
78
|
+
warnings: string[];
|
|
79
|
+
};
|
|
80
|
+
summary: string;
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
83
|
+
get_payment_agreement: {
|
|
84
|
+
name: string;
|
|
85
|
+
description: string;
|
|
86
|
+
inputSchema: import("zod").ZodObject<{
|
|
87
|
+
payment_agreement_id: import("zod").ZodString;
|
|
88
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
89
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
90
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
91
|
+
payment_agreement_id: string;
|
|
92
|
+
enrich: boolean;
|
|
93
|
+
include_raw: boolean;
|
|
94
|
+
}, {
|
|
95
|
+
payment_agreement_id: string;
|
|
96
|
+
enrich?: boolean | undefined;
|
|
97
|
+
include_raw?: boolean | undefined;
|
|
98
|
+
}>;
|
|
99
|
+
execute: (args: unknown) => Promise<import("../types/index.js").StandardResponse<unknown>>;
|
|
100
|
+
};
|
|
101
|
+
create_payment_agreement: {
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
inputSchema: import("zod").ZodObject<{
|
|
105
|
+
name: import("zod").ZodString;
|
|
106
|
+
type: import("zod").ZodString;
|
|
107
|
+
maximum_amount: import("zod").ZodString;
|
|
108
|
+
frequency: import("zod").ZodString;
|
|
109
|
+
number_of_transactions_permitted: import("zod").ZodNumber;
|
|
110
|
+
pay_id: import("zod").ZodString;
|
|
111
|
+
idempotency_key: import("zod").ZodString;
|
|
112
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
113
|
+
type: string;
|
|
114
|
+
maximum_amount: string;
|
|
115
|
+
name: string;
|
|
116
|
+
frequency: string;
|
|
117
|
+
number_of_transactions_permitted: number;
|
|
118
|
+
pay_id: string;
|
|
119
|
+
idempotency_key: string;
|
|
120
|
+
}, {
|
|
121
|
+
type: string;
|
|
122
|
+
maximum_amount: string;
|
|
123
|
+
name: string;
|
|
124
|
+
frequency: string;
|
|
125
|
+
number_of_transactions_permitted: number;
|
|
126
|
+
pay_id: string;
|
|
127
|
+
idempotency_key: string;
|
|
128
|
+
}>;
|
|
129
|
+
execute: (args: unknown) => Promise<import("../types/index.js").StandardResponse<unknown> | {
|
|
130
|
+
success: boolean;
|
|
131
|
+
timestamp: string;
|
|
132
|
+
data: any;
|
|
133
|
+
metadata: {
|
|
134
|
+
requestId: string;
|
|
135
|
+
processingTime: number;
|
|
136
|
+
environment: "sandbox" | "production";
|
|
137
|
+
};
|
|
138
|
+
insights: {
|
|
139
|
+
status: any;
|
|
140
|
+
canProceed: boolean;
|
|
141
|
+
nextActions: string[];
|
|
142
|
+
warnings: string[];
|
|
143
|
+
};
|
|
144
|
+
summary: string;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
get_auth_token: {
|
|
148
|
+
name: string;
|
|
149
|
+
description: string;
|
|
150
|
+
inputSchema: import("zod").ZodObject<{
|
|
151
|
+
include_token_in_response: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
152
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
153
|
+
include_token_in_response: boolean;
|
|
154
|
+
}, {
|
|
155
|
+
include_token_in_response?: boolean | undefined;
|
|
156
|
+
}>;
|
|
157
|
+
execute: (args: any) => Promise<import("../types/index.js").StandardResponse<unknown>>;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAllTools = createAllTools;
|
|
4
|
+
const payment_agreements_js_1 = require("./payment-agreements.js");
|
|
5
|
+
const payment_initiations_js_1 = require("./payment-initiations.js");
|
|
6
|
+
const auth_js_1 = require("./auth.js");
|
|
7
|
+
function createAllTools(apiClient, config) {
|
|
8
|
+
return {
|
|
9
|
+
...(0, auth_js_1.createAuthTools)(apiClient, config),
|
|
10
|
+
...(0, payment_agreements_js_1.createPaymentAgreementTools)(apiClient, config),
|
|
11
|
+
...(0, payment_initiations_js_1.createPaymentInitiationTools)(apiClient, config),
|
|
12
|
+
// Add more tool categories here
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ShabaasApiClient } from "../api/client.js";
|
|
2
|
+
import { Config } from "../config/index.js";
|
|
3
|
+
export declare function createPaymentAgreementTools(apiClient: ShabaasApiClient, config: Config): {
|
|
4
|
+
get_payment_agreement: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: import("zod").ZodObject<{
|
|
8
|
+
payment_agreement_id: import("zod").ZodString;
|
|
9
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
10
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
11
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
+
payment_agreement_id: string;
|
|
13
|
+
enrich: boolean;
|
|
14
|
+
include_raw: boolean;
|
|
15
|
+
}, {
|
|
16
|
+
payment_agreement_id: string;
|
|
17
|
+
enrich?: boolean | undefined;
|
|
18
|
+
include_raw?: boolean | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
execute: (args: unknown) => Promise<import("../types/index.js").StandardResponse<unknown>>;
|
|
21
|
+
};
|
|
22
|
+
create_payment_agreement: {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
inputSchema: import("zod").ZodObject<{
|
|
26
|
+
name: import("zod").ZodString;
|
|
27
|
+
type: import("zod").ZodString;
|
|
28
|
+
maximum_amount: import("zod").ZodString;
|
|
29
|
+
frequency: import("zod").ZodString;
|
|
30
|
+
number_of_transactions_permitted: import("zod").ZodNumber;
|
|
31
|
+
pay_id: import("zod").ZodString;
|
|
32
|
+
idempotency_key: import("zod").ZodString;
|
|
33
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
34
|
+
type: string;
|
|
35
|
+
maximum_amount: string;
|
|
36
|
+
name: string;
|
|
37
|
+
frequency: string;
|
|
38
|
+
number_of_transactions_permitted: number;
|
|
39
|
+
pay_id: string;
|
|
40
|
+
idempotency_key: string;
|
|
41
|
+
}, {
|
|
42
|
+
type: string;
|
|
43
|
+
maximum_amount: string;
|
|
44
|
+
name: string;
|
|
45
|
+
frequency: string;
|
|
46
|
+
number_of_transactions_permitted: number;
|
|
47
|
+
pay_id: string;
|
|
48
|
+
idempotency_key: string;
|
|
49
|
+
}>;
|
|
50
|
+
execute: (args: unknown) => Promise<import("../types/index.js").StandardResponse<unknown> | {
|
|
51
|
+
success: boolean;
|
|
52
|
+
timestamp: string;
|
|
53
|
+
data: any;
|
|
54
|
+
metadata: {
|
|
55
|
+
requestId: string;
|
|
56
|
+
processingTime: number;
|
|
57
|
+
environment: "sandbox" | "production";
|
|
58
|
+
};
|
|
59
|
+
insights: {
|
|
60
|
+
status: any;
|
|
61
|
+
canProceed: boolean;
|
|
62
|
+
nextActions: string[];
|
|
63
|
+
warnings: string[];
|
|
64
|
+
};
|
|
65
|
+
summary: string;
|
|
66
|
+
}>;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaymentAgreementTools = createPaymentAgreementTools;
|
|
4
|
+
const index_js_1 = require("../enricher/index.js");
|
|
5
|
+
const index_js_2 = require("../types/index.js");
|
|
6
|
+
const validator_js_1 = require("../security/validator.js");
|
|
7
|
+
const response_helpers_js_1 = require("./response-helpers.js");
|
|
8
|
+
function createPaymentAgreementTools(apiClient, config) {
|
|
9
|
+
return {
|
|
10
|
+
get_payment_agreement: {
|
|
11
|
+
name: "get_payment_agreement",
|
|
12
|
+
description: "Retrieve a payment agreement. If enrich is true, return business insights such as readiness, next steps, customer copy and PayTo references.",
|
|
13
|
+
inputSchema: index_js_2.GetPaymentAgreementInputSchema,
|
|
14
|
+
execute: async (args) => {
|
|
15
|
+
const startTime = Date.now();
|
|
16
|
+
const validation = (0, validator_js_1.validateInput)(index_js_2.GetPaymentAgreementInputSchema, args);
|
|
17
|
+
if (!validation.success) {
|
|
18
|
+
return (0, response_helpers_js_1.validationErrorResponse)(validation.errors ?? [], config.environment);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const { payment_agreement_id, enrich } = validation.data;
|
|
22
|
+
const include_raw = validation.data.include_raw ?? false;
|
|
23
|
+
const response = await apiClient.getPaymentAgreement(payment_agreement_id);
|
|
24
|
+
if (!response.data) {
|
|
25
|
+
return (0, response_helpers_js_1.toolErrorResponse)("Payment agreement not found", config.environment, response);
|
|
26
|
+
}
|
|
27
|
+
const agreementData = index_js_2.PaymentAgreementSchema.parse(response.data);
|
|
28
|
+
if (!enrich) {
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
timestamp: new Date().toISOString(),
|
|
32
|
+
data: agreementData,
|
|
33
|
+
metadata: {
|
|
34
|
+
requestId: `req_${Date.now()}`,
|
|
35
|
+
processingTime: Date.now() - startTime,
|
|
36
|
+
environment: config.environment,
|
|
37
|
+
},
|
|
38
|
+
insights: {
|
|
39
|
+
status: agreementData.status,
|
|
40
|
+
canProceed: agreementData.status?.toLowerCase?.() === "active",
|
|
41
|
+
nextActions: ["get_payment_agreement"],
|
|
42
|
+
warnings: ["Enrichment disabled"],
|
|
43
|
+
},
|
|
44
|
+
summary: "Enrichment disabled. Returning agreement data only.",
|
|
45
|
+
...(include_raw ? { raw: response } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return (0, index_js_1.enrichPaymentAgreement)(agreementData, include_raw, response, config.environment);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return (0, response_helpers_js_1.toolErrorResponse)(error.message || "Failed to get payment agreement", config.environment);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
create_payment_agreement: {
|
|
56
|
+
name: "create_payment_agreement",
|
|
57
|
+
description: "Create a new payment agreement. The payer must authorise it in their banking app before it becomes active.",
|
|
58
|
+
inputSchema: index_js_2.CreatePaymentAgreementInputSchema,
|
|
59
|
+
execute: async (args) => {
|
|
60
|
+
const startTime = Date.now();
|
|
61
|
+
const validation = (0, validator_js_1.validateInput)(index_js_2.CreatePaymentAgreementInputSchema, args);
|
|
62
|
+
if (!validation.success) {
|
|
63
|
+
return (0, response_helpers_js_1.validationErrorResponse)(validation.errors ?? [], config.environment);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const data = validation.data;
|
|
67
|
+
const response = await apiClient.createPaymentAgreement(data);
|
|
68
|
+
return {
|
|
69
|
+
success: true,
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
data: response.data,
|
|
72
|
+
metadata: {
|
|
73
|
+
requestId: `req_${Date.now()}`,
|
|
74
|
+
processingTime: Date.now() - startTime,
|
|
75
|
+
environment: config.environment,
|
|
76
|
+
},
|
|
77
|
+
insights: {
|
|
78
|
+
status: response.data?.status || "created",
|
|
79
|
+
canProceed: false,
|
|
80
|
+
nextActions: ["get_payment_agreement"],
|
|
81
|
+
warnings: ["Customer must authorise this payment agreement in their banking app"],
|
|
82
|
+
},
|
|
83
|
+
summary: `Payment agreement created. ID ${response.data?.payment_agreement_id}. Awaiting customer authorisation.`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return (0, response_helpers_js_1.toolErrorResponse)("Failed to create payment agreement", config.environment);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ShabaasApiClient } from '../api/client.js';
|
|
2
|
+
import { Config } from '../config/index.js';
|
|
3
|
+
import { StandardResponse } from '../types/index.js';
|
|
4
|
+
export declare function createPaymentInitiationTools(apiClient: ShabaasApiClient, config: Config): {
|
|
5
|
+
initiate_payment: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputSchema: import("zod").ZodObject<{
|
|
9
|
+
payment_agreement_id: import("zod").ZodString;
|
|
10
|
+
amount: import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodNumber]>, string | number, string | number>;
|
|
11
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
13
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
14
|
+
idempotency_key: import("zod").ZodString;
|
|
15
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
16
|
+
payment_agreement_id: string;
|
|
17
|
+
amount: string | number;
|
|
18
|
+
enrich: boolean;
|
|
19
|
+
include_raw: boolean;
|
|
20
|
+
idempotency_key: string;
|
|
21
|
+
description?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
payment_agreement_id: string;
|
|
24
|
+
amount: string | number;
|
|
25
|
+
idempotency_key: string;
|
|
26
|
+
enrich?: boolean | undefined;
|
|
27
|
+
include_raw?: boolean | undefined;
|
|
28
|
+
description?: string | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
execute: (args: any) => Promise<StandardResponse<any> | {
|
|
31
|
+
raw?: import("../types/index.js").ApiResponse<any> | undefined;
|
|
32
|
+
success: boolean;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
data: any;
|
|
35
|
+
metadata: {
|
|
36
|
+
requestId: string;
|
|
37
|
+
processingTime: number;
|
|
38
|
+
environment: "sandbox" | "production";
|
|
39
|
+
};
|
|
40
|
+
insights: {
|
|
41
|
+
status: any;
|
|
42
|
+
canProceed: boolean;
|
|
43
|
+
nextActions: string[];
|
|
44
|
+
warnings: string[];
|
|
45
|
+
};
|
|
46
|
+
summary: string;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
get_payment_initiation: {
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
inputSchema: import("zod").ZodObject<{
|
|
53
|
+
payment_initiation_id: import("zod").ZodString;
|
|
54
|
+
enrich: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
55
|
+
include_raw: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
56
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
57
|
+
payment_initiation_id: string;
|
|
58
|
+
enrich: boolean;
|
|
59
|
+
include_raw: boolean;
|
|
60
|
+
}, {
|
|
61
|
+
payment_initiation_id: string;
|
|
62
|
+
enrich?: boolean | undefined;
|
|
63
|
+
include_raw?: boolean | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
execute: (args: any) => Promise<StandardResponse<any> | {
|
|
66
|
+
raw?: import("../types/index.js").ApiResponse<any> | undefined;
|
|
67
|
+
success: boolean;
|
|
68
|
+
timestamp: string;
|
|
69
|
+
data: any;
|
|
70
|
+
metadata: {
|
|
71
|
+
requestId: string;
|
|
72
|
+
processingTime: number;
|
|
73
|
+
environment: "sandbox" | "production";
|
|
74
|
+
};
|
|
75
|
+
insights: {
|
|
76
|
+
status: any;
|
|
77
|
+
canProceed: boolean;
|
|
78
|
+
nextActions: string[];
|
|
79
|
+
warnings: string[];
|
|
80
|
+
};
|
|
81
|
+
summary: string;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaymentInitiationTools = createPaymentInitiationTools;
|
|
4
|
+
const index_js_1 = require("../types/index.js");
|
|
5
|
+
const validator_js_1 = require("../security/validator.js");
|
|
6
|
+
const response_helpers_js_1 = require("./response-helpers.js");
|
|
7
|
+
function createPaymentInitiationTools(apiClient, config) {
|
|
8
|
+
return {
|
|
9
|
+
initiate_payment: {
|
|
10
|
+
name: 'initiate_payment',
|
|
11
|
+
description: 'Initiate a payment against an existing payment agreement.',
|
|
12
|
+
inputSchema: index_js_1.InitiatePaymentInputSchema,
|
|
13
|
+
execute: async (args) => {
|
|
14
|
+
const validation = (0, validator_js_1.validateInput)(index_js_1.InitiatePaymentInputSchema, args);
|
|
15
|
+
if (!validation.success) {
|
|
16
|
+
return (0, response_helpers_js_1.validationErrorResponse)(validation.errors ?? [], config.environment);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const start = Date.now();
|
|
20
|
+
const { enrich = true, include_raw = false, ...payload } = validation.data;
|
|
21
|
+
const response = await apiClient.initiatePayment(payload);
|
|
22
|
+
if (!enrich) {
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
data: response.data,
|
|
27
|
+
metadata: {
|
|
28
|
+
requestId: `req_${Date.now()}`,
|
|
29
|
+
processingTime: Date.now() - start,
|
|
30
|
+
environment: config.environment,
|
|
31
|
+
},
|
|
32
|
+
insights: {
|
|
33
|
+
status: response.data?.status || 'submitted',
|
|
34
|
+
canProceed: true,
|
|
35
|
+
nextActions: ['get_payment_initiation'],
|
|
36
|
+
warnings: ['Enrichment disabled'],
|
|
37
|
+
},
|
|
38
|
+
summary: 'Payment initiation request submitted successfully.',
|
|
39
|
+
...(include_raw ? { raw: response } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return enrichPaymentInitiation(response.data, include_raw ? response : undefined, Date.now() - start, config.environment, 'initiate');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return (0, response_helpers_js_1.toolErrorResponse)('Failed to initiate payment', config.environment);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
get_payment_initiation: {
|
|
50
|
+
name: 'get_payment_initiation',
|
|
51
|
+
description: 'Retrieve a payment initiation by ID.',
|
|
52
|
+
inputSchema: index_js_1.GetPaymentInitiationInputSchema,
|
|
53
|
+
execute: async (args) => {
|
|
54
|
+
const validation = (0, validator_js_1.validateInput)(index_js_1.GetPaymentInitiationInputSchema, args);
|
|
55
|
+
if (!validation.success) {
|
|
56
|
+
return (0, response_helpers_js_1.validationErrorResponse)(validation.errors ?? [], config.environment);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const start = Date.now();
|
|
60
|
+
const { payment_initiation_id, enrich = true, include_raw = false } = validation.data;
|
|
61
|
+
const response = await apiClient.getPaymentInitiation(payment_initiation_id);
|
|
62
|
+
// Best effort validation for structured output
|
|
63
|
+
let parsed = response.data;
|
|
64
|
+
const maybe = index_js_1.PaymentInitiationSchema.safeParse(response.data);
|
|
65
|
+
if (maybe.success)
|
|
66
|
+
parsed = maybe.data;
|
|
67
|
+
if (!enrich) {
|
|
68
|
+
return {
|
|
69
|
+
success: true,
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
data: parsed,
|
|
72
|
+
metadata: {
|
|
73
|
+
requestId: `req_${Date.now()}`,
|
|
74
|
+
processingTime: Date.now() - start,
|
|
75
|
+
environment: config.environment,
|
|
76
|
+
},
|
|
77
|
+
insights: {
|
|
78
|
+
status: parsed?.status || 'unknown',
|
|
79
|
+
canProceed: true,
|
|
80
|
+
nextActions: ['get_payment_initiation'],
|
|
81
|
+
warnings: ['Enrichment disabled'],
|
|
82
|
+
},
|
|
83
|
+
summary: `Payment initiation ${payment_initiation_id} retrieved successfully.`,
|
|
84
|
+
...(include_raw ? { raw: response } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return enrichPaymentInitiation(parsed, include_raw ? response : undefined, Date.now() - start, config.environment, 'retrieve');
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return (0, response_helpers_js_1.toolErrorResponse)(error?.response?.data?.message || error.message || 'Failed to get payment initiation', config.environment, error?.response?.data);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function enrichPaymentInitiation(data, raw, processingTime, environment, mode) {
|
|
97
|
+
const status = data?.status || 'submitted';
|
|
98
|
+
const lower = (status || '').toString().toLowerCase();
|
|
99
|
+
const canProceed = ['acsc', 'submitted', 'pending'].includes(lower);
|
|
100
|
+
const nextActions = lower === 'acsc'
|
|
101
|
+
? ['get_payment_initiation']
|
|
102
|
+
: ['get_payment_initiation'];
|
|
103
|
+
const warnings = [];
|
|
104
|
+
if (mode === 'initiate') {
|
|
105
|
+
warnings.push('Verify payment initiation status before assuming funds have settled');
|
|
106
|
+
}
|
|
107
|
+
if (['failed', 'rejected'].includes(lower)) {
|
|
108
|
+
warnings.push('Payment initiation failed or was rejected. Review agreement limits and payer status.');
|
|
109
|
+
}
|
|
110
|
+
const reconciliationNotes = [
|
|
111
|
+
'Use the payment_agreement_id to correlate settlement events to the originating agreement.',
|
|
112
|
+
'PayTo payment initiations can be tracked via get_payment_initiation until settlement completes.',
|
|
113
|
+
];
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
timestamp: new Date().toISOString(),
|
|
117
|
+
data,
|
|
118
|
+
metadata: {
|
|
119
|
+
requestId: `req_${Date.now()}`,
|
|
120
|
+
processingTime,
|
|
121
|
+
environment,
|
|
122
|
+
},
|
|
123
|
+
insights: {
|
|
124
|
+
status,
|
|
125
|
+
canProceed,
|
|
126
|
+
nextActions,
|
|
127
|
+
warnings,
|
|
128
|
+
business: {
|
|
129
|
+
product: 'PayTo',
|
|
130
|
+
meaning: 'Payment initiation against a PayTo agreement',
|
|
131
|
+
readiness: {
|
|
132
|
+
canInitiatePayment: canProceed,
|
|
133
|
+
reason: canProceed
|
|
134
|
+
? 'Payment initiation accepted; track status until settled.'
|
|
135
|
+
: 'Payment initiation requires review.',
|
|
136
|
+
},
|
|
137
|
+
limits: {
|
|
138
|
+
currency: 'AUD',
|
|
139
|
+
},
|
|
140
|
+
cadence: {},
|
|
141
|
+
timing: {},
|
|
142
|
+
payerControls: [
|
|
143
|
+
'Payer can view and manage PayTo agreements in their banking app.',
|
|
144
|
+
'If the payer pauses/cancels the agreement, future initiations will fail.',
|
|
145
|
+
],
|
|
146
|
+
reconciliationNotes,
|
|
147
|
+
operationalChecks: [
|
|
148
|
+
'Check initiation status via get_payment_initiation until completion.',
|
|
149
|
+
'If initiation fails, confirm agreement status and limits before retrying.',
|
|
150
|
+
],
|
|
151
|
+
riskFlags: [],
|
|
152
|
+
references: [
|
|
153
|
+
{ title: 'PayTo overview', url: 'https://www.auspayplus.com.au/solutions/payto' },
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
summary: mode === 'initiate'
|
|
158
|
+
? 'Payment initiation submitted. Track status with get_payment_initiation.'
|
|
159
|
+
: `Payment initiation ${data?.payment_initiation_id || ''} retrieved.`,
|
|
160
|
+
...(raw ? { raw } : {}),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StandardResponse } from '../types/index.js';
|
|
2
|
+
import { Config } from '../config/index.js';
|
|
3
|
+
export declare function validationErrorResponse<T>(errors: string[], environment: Config['environment']): StandardResponse<T | null>;
|
|
4
|
+
export declare function toolErrorResponse<T>(message: string, environment: Config['environment'], raw?: any): StandardResponse<T | null>;
|