接入教程
1. 登录Adyen账户并生成API密钥
2. 在代码中引入Adyen管理API客户端库
3. 使用API密钥对请求进行签名认证
4. 调用API端点配置公司或商户账户
5. 管理商店和支付终端设置
6. 测试API功能并部署到生产环境
获取商户账户列表
import requests
url = 'https://api.example.com/merchantAccounts'
headers = {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(data)
else:
print(f'请求失败,状态码: {response.status_code}')
print(response.text)
创建新商店
<?php
$url = 'https://api.example.com/stores';
$apiKey = 'YOUR_API_KEY';
$data = [
'name' => 'Example Store',
'address' => '123 Main St',
'status' => 'active'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 201) {
echo '商店创建成功';
print_r(json_decode($response, true));
} else {
echo '请求失败,状态码: ' . $httpCode;
echo $response;
}
?>
更新终端状态
const fetch = require('node-fetch');
const url = 'https://api.example.com/terminals/terminal123';
const apiKey = 'YOUR_API_KEY';
const updateData = {
status: 'inactive',
reason: 'maintenance'
};
fetch(url, {
method: 'PATCH',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(updateData)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => console.log('更新成功:', data))
.catch(error => console.error('请求失败:', error));
常见问题
如何获取API密钥?
您需要在Adyen客户区域生成API密钥。请访问Adyen官方文档中的API凭证生成页面,按照指南创建新的API密钥。
API请求失败常见的状态码有哪些?
常见的状态码包括:401(未授权,API密钥无效)、403(禁止访问,权限不足)、404(资源未找到)、429(请求过多,超出频率限制)。请根据具体状态码检查API密钥和请求参数。
管理API支持哪些HTTP方法?
管理API支持标准的RESTful方法,包括GET(获取资源)、POST(创建资源)、PATCH(部分更新资源)、DELETE(删除资源)。具体端点支持的方法请参考API文档。
Aitishiku.com