接入教程
1. 注册Adyen账户并获取API密钥。
2. 调用API端点生成托管页面链接。
3. 将链接嵌入您的平台中。
4. 测试链接确保功能正常。
5. 监控集成状态并进行优化。
使用Python生成托管页面链接
python
import requests
base_url = 'https://api.example.com'
headers = {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
# 准备请求数据
payload = {
'reference': 'your_unique_reference',
'returnUrl': 'https://your-return-url.com'
}
# 调用API端点生成链接
response = requests.post(
f'{base_url}/generateHostedLink',
headers=headers,
json=payload
)
if response.status_code == 200:
result = response.json()
hosted_link = result.get('url')
print(f'Hosted link generated: {hosted_link}')
else:
print(f'Error: {response.status_code}')
print(response.text)
使用PHP调用托管集成API
php
<?php
$baseUrl = 'https://api.example.com';
$apiKey = 'YOUR_API_KEY';
$data = [
'reference' => 'your_unique_reference',
'returnUrl' => 'https://your-return-url.com'
];
$ch = curl_init($baseUrl . '/generateHostedLink');
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);
if ($httpCode === 200) {
$result = json_decode($response, true);
$hostedLink = $result['url'] ?? '';
echo "Hosted link generated: " . $hostedLink;
} else {
echo "Error: " . $httpCode;
echo $response;
}
curl_close($ch);
?>
使用JavaScript集成托管页面API
javascript
const baseUrl = 'https://api.example.com';
const apiKey = 'YOUR_API_KEY';
async function generateHostedLink() {
const payload = {
reference: 'your_unique_reference',
returnUrl: 'https://your-return-url.com'
};
try {
const response = await fetch(`${baseUrl}/generateHostedLink`, {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (response.ok) {
const result = await response.json();
const hostedLink = result.url;
console.log(`Hosted link generated: ${hostedLink}`);
return hostedLink;
} else {
console.error(`Error: ${response.status}`);
const errorText = await response.text();
console.error(errorText);
}
} catch (error) {
console.error('Request failed:', error);
}
}
// 调用函数
generateHostedLink();
常见问题
什么是托管集成API?
托管集成API允许您通过调用API端点生成Adyen托管的页面链接,如网站或支付页面,简化集成流程。
如何获取API密钥?
API密钥需从您的Adyen账户控制台获取。请登录后,在API凭证部分生成或查看您的API密钥,并确保安全存储。
API调用失败怎么办?
请检查API密钥是否正确、网络连接是否正常,并确认请求参数符合文档要求。如问题持续,请参考Adyen官方文档或联系支持。
Aitishiku.com