这是一个模型上下文协议(MCP)服务器,用于与阿尔及利亚的 SATIM 支付网关系统集成。该服务器通过 SATIM - ePAY 平台为处理 CIB/Edhahabia 卡支付提供了一个结构化接口。此软件包使 Cursor、Claude 和 Copilot 等 AI 助手能够通过标准化接口直接访问你的账户数据。
更多详情: 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": "Votre paiement a été accepté",
"amount": 150050,
"errorCode": "0",
"orderStatus": 2,
"approvalCode": "303004",
"params": {
"respCode": "00",
"respCode_desc": "Votre paiement a été accepté"
}
}
处理已完成订单的退款。
参数:
orderId
(字符串,必需):要退款的订单 IDamountInDA
(数字,必需):退款金额(单位:DA)currency
(字符串,可选):货币代码language
(字符串,可选):响应语言响应:
{
"errorCode": 0
}
验证并解释支付响应。
参数:
response
(对象,必需):订单确认响应响应:
{
"status": "ACCEPTED",
"displayMessage": "Votre paiement a été accepté",
"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 Server started for testing');
// 让它运行几秒钟后退出
setTimeout(() => {
server.kill();
console.log('Test completed');
}, 5000);
使用以下命令运行:
node test-simple.js
按照文档中的示例创建 test - client.ts
,然后运行:
npm run test
使用文档中提供的 HTTP 包装器示例创建 REST API 端点,以便使用 Postman 或 curl 等工具进行更轻松的测试。
“Cannot use import statement outside a module”
# 确保 package.json 中有 "type": "module"
npm pkg set type=module
“Module not found” 错误
# 重新安装依赖
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: "Achat produit électronique"
});
// 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("Payment successful:", validation.displayMessage);
} else if (validation.status === "REJECTED") {
// 处理拒绝
console.log("Payment rejected");
} else {
// 处理错误
console.log("Payment error:", 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 规范,包含了阿尔及利亚电子商务平台所需的所有集成点。