这是一个用于与阿尔及利亚 SATIM 支付网关系统集成的模型上下文协议(MCP)服务器。该服务器提供了一个结构化的接口,通过 SATIM-ePAY 平台处理 CIB/Edhahabia 卡支付。此包使像 Cursor、Claude 和 Copilot 这样的AI助手能够通过标准化接口直接访问您的账户数据。
<a href="https://glama.ai/mcp/servers/@zakblacki/Satim-Payment-Gateway-Integration"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=2649691705,1156117642&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Satim 支付网关集成 MCP 服务器" /> </a>更多详情: https://code2tutorial.com/tutorial/6b3a062c-3a34-4716-830e-8793a5378bcc/index.md
# 克隆仓库
git clone https://github.com/zakblacki/Satim-Payment-Gateway-Integration.git
cd satim-payment-gateway-integration
# 安装依赖
npm install
# 运行服务器
npx tsx satim-mcp-server.ts
或
npm run dev
# 演示
启动 index.html
git clone https://github.com/zakblacki/Satim-Payment-Gateway-Integration.git
cd satim-payment-gateway-integration
npm init -y
npm pkg set type=module
# 核心依赖
npm install @modelcontextprotocol/sdk axios
# 开发依赖
npm install --save-dev typescript @types/node tsx
npx tsx satim-mcp-server.ts
# 编译 TypeScript
npm run build
# 运行编译后的 JavaScript
npm start
npm run dev
要使用此服务器与 MCP 客户端(如 Claude Desktop),请在配置中添加以下内容:
{
"mcpServers": {
"satim-payment": {
"command": "npx",
"args": ["@devqxi/satim-payment-gateway-mcp"],
"env": {
"SATIM_USERNAME": "your_test_username",
"SATIM_PASSWORD": "your_test_password",
"NODE_ENV": "development"
}
}
}
}
在使用任何支付工具之前,请配置您的 SATIM 凭证:
// 配置凭证
await mcp.callTool("configure_credentials", {
userName: "your_merchant_username",
password: "your_merchant_password"
});
对于生产环境,请考虑使用环境变量:
SATIM_USERNAME=your_merchant_username
SATIM_PASSWORD=your_merchant_password
SATIM_TERMINAL_ID=your_terminal_id
SATIM_BASE_URL=https://test.satim.dz/payment/rest # 或 https://satim.dz/payment/rest 用于生产
完整的支付过程遵循以下步骤:
const registrationResult = await mcp.callTool("register_order", {
orderNumber: "ORDER_001_2024",
amountInDA: 1500.50, // 金额以阿尔及利亚第纳尔计
returnUrl: "https://yoursite.com/payment/success",
failUrl: "https://yoursite.com/payment/failure",
force_terminal_id: "E005005097",
udf1: "merchant_ref_123",
language: "FR"
});
// 响应包括 orderId 和 formUrl
// 将客户重定向到 formUrl 进行支付
const confirmResult = await mcp.callTool("confirm_order", {
orderId: "received_order_id",
language: "FR"
});
// 验证响应
const validation = await mcp.callTool("validate_payment_response", {
response: confirmResult
});
根据验证结果,向客户显示适当的提示信息。
配置 SATIM 网关凭证。
参数:
userName (字符串,必需):商户登录名password (字符串,必需):商户密码注册新的支付订单。
参数:
orderNumber (字符串,必需):唯一订单标识符amountInDA (数字,必需):金额以阿尔及利亚第纳尔计(最小值:50 DA)returnUrl (字符串,必需):成功重定向 URLfailUrl (字符串,可选):失败重定向 URLforce_terminal_id (字符串,必需):银行分配的终端 IDudf1 (字符串,必需):SATIM 特定参数currency (字符串,可选):货币代码(默认:"012" 对应 DZD)language (字符串,可选):界面语言 ("AR", "FR", "EN")description (字符串,可选):订单描述udf2-udf5 (字符串,可选):附加参数响应:
{
"orderId": "123456789AZERTYUIOPL",
"formUrl": "https://test.satim.dz/payment/merchants/merchant1/payment_fr.html?mdOrder=123456789AZERTYUIOPL"
}
支付尝试后确认订单状态。
参数:
orderId (字符串,必需):来自注册的订单 IDlanguage (字符串,可选):响应语言响应:
{
"orderNumber": "ORDER_001_2024",
"actionCode": 0,
"actionCodeDescription": "您的支付已被接受",
"amount": 150050,
"errorCode": "0",
"orderStatus": 2,
"approvalCode": "303004",
"params": {
"respCode": "00",
"respCode_desc": "您的支付已被接受"
}
}
处理已完成订单的退款。
参数:
orderId (字符串,必需):需要退款的订单 IDamountInDA (数字,必需):退款金额以 DA 计currency (字符串,可选):货币代码language (字符串,可选):响应语言响应:
{
"errorCode": 0
}
验证并解释支付响应。
参数:
response (对象,必需):订单确认响应响应:
{
"status": "ACCEPTED",
"displayMessage": "您的支付已被接受",
"shouldShowContactInfo": false,
"contactNumber": "3020 3020"
}
创建一个简单的测试文件 test-simple.js:
import { spawn } from 'child_process';
// 启动 MCP 服务器
const server = spawn('npx', ['tsx', 'satim-mcp-server.ts'], {
stdio: ['pipe', 'pipe', 'inherit']
});
console.log('SATIM MCP 服务器已启动用于测试');
// 让它运行几秒钟然后退出
setTimeout(() => {
server.kill();
console.log('测试完成');
}, 5000);
运行:
node test-simple.js
创建 test-client.ts,按照文档中的示例进行操作,然后运行:
npm run test
使用文档中提供的 HTTP 包装器示例,创建 REST API 端点,以便使用 Postman 或 curl 等工具进行更轻松的测试。
“无法在模块外部使用 import 语句”
# 确保 package.json 中有 "type": "module"
npm pkg set type=module
“模块未找到” 错误
# 重新安装依赖
rm -rf node_modules package-lock.json
npm install
TypeScript 编译错误
# 检查 tsconfig.json 配置
# 确保所有依赖都已安装
npm install --save-dev @types/node
服务器连接问题
# 检查服务器是否正在运行
ps aux | grep tsx
# 检查端口冲突
lsof -i :3000 # 如果使用 HTTP 包装器
启用调试日志:
DEBUG=true npx tsx satim-mcp-server.ts
对于接受的支付,显示:
respCode_desc)orderId)orderNumber)approvalCode)发送给 SATIM 的金额需乘以 100:
MCP 服务器会自动处理此转换。
| 错误代码 | 描述 |
|---|---|
| 0 | 成功确认 |
| 1 | 空订单 ID |
| 2 | 已经确认 |
| 3 | 访问被拒 |
| 5 | 访问被拒 |
| 6 | 未知订单 |
| 7 | 系统错误 |
| 错误代码 | 描述 |
|---|---|
| 0 | 无系统错误 |
| 5 | 需要更改密码 / 空订单 ID |
| 6 | 错误的订单编号 |
| 7 | 支付状态错误 / 金额错误 / 系统错误 |
// 1. 配置凭证
await mcp.callTool("configure_credentials", {
userName: "test_merchant",
password: "test_password"
});
// 2. 注册订单
const order = await mcp.callTool("register_order", {
orderNumber: `ORDER_${Date.now()}`,
amountInDA: 250.75,
returnUrl: "https://mystore.dz/payment/success",
failUrl: "https://mystore.dz/payment/failure",
force_terminal_id: "E005005097",
udf1: "customer_ref_456",
language: "FR",
description: "购买电子产品"
});
// 3. 将客户重定向到 order.formUrl
// 客户完成支付并返回
// 4. 确认支付
const confirmation = await mcp.callTool("confirm_order", {
orderId: order.orderId,
language: "FR"
});
// 5. 验证响应
const validation = await mcp.callTool("validate_payment_response", {
response: confirmation
});
// 6. 处理结果
if (validation.status === "ACCEPTED") {
// 处理成功的支付
console.log("支付成功:", validation.displayMessage);
} else if (validation.status === "REJECTED") {
// 处理拒绝
console.log("支付被拒绝");
} else {
// 处理错误
console.log("支付错误:", validation.displayMessage);
}
// 全额退款
const refund = await mcp.callTool("refund_order", {
orderId: "123456789AZERTYUIOPL",
amountInDA: 250.75, // 原始全额
language: "FR"
});
// 部分退款
const partialRefund = await mcp.callTool("refund_order", {
orderId: "123456789AZERTYUIOPL",
amountInDA: 100.00, // 部分金额
language: "FR"
});
# 生产端点
SATIM_BASE_URL=https://satim.dz/payment/rest
# 开发/测试端点
SATIM_BASE_URL=https://test.satim.dz/payment/rest
实现健康检查端点以监控网关连接:
// 添加到您的服务器
app.get('/health/satim', async (req, res) => {
try {
// 测试连接到 SATIM
const response = await axios.get(`${SATIM_BASE_URL}/health`);
res.json({ status: 'healthy', satim: 'connected' });
} catch (error) {
res.status(503).json({ status: 'unhealthy', error: error.message });
}
});
此 MCP 服务器实现遵循 SATIM 的官方 API 规范,并包含了阿尔及利亚电子商务平台所需的所有集成点。