接入教程
1. 注册Adyen账户并获取API密钥
2. 在您的网站或应用中集成Checkout SDK
3. 配置支付方式(信用卡、钱包等)
4. 调用API发起支付请求
5. 处理支付回调并更新订单状态
6. 在Adyen后台查看交易记录
使用Python发起支付
python
import requests
url = 'https://api.example.com/payments'
headers = {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'amount': {
'currency': 'USD',
'value': 1000
},
'reference': 'order-123',
'returnUrl': 'https://your-website.com/return'
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
使用PHP处理支付结果
php
<?php
$url = 'https://api.example.com/payments/result';
$apiKey = 'YOUR_API_KEY';
$data = [
'paymentData' => $_POST['paymentData'] ?? null,
'details' => [
'redirectResult' => $_POST['redirectResult'] ?? null
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
使用JavaScript创建支付会话
javascript
const fetch = require('node-fetch');
const url = 'https://api.example.com/sessions';
const apiKey = 'YOUR_API_KEY';
const payload = {
amount: {
currency: 'EUR',
value: 5000
},
reference: 'checkout-session-456',
returnUrl: 'https://your-store.com/thank-you'
};
async function createSession() {
const response = await fetch(url, {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data);
}
createSession();
常见问题
如何获取API密钥?
API密钥需要在Adyen商户后台生成。登录您的Adyen账户,进入API和Webhooks部分,创建新的API密钥并妥善保管。
支付请求失败常见原因有哪些?
常见原因包括:API密钥无效或过期、请求格式不符合API规范、金额或货币代码错误、网络连接问题或Adyen服务临时不可用。
支持哪些支付方式?
Adyen Checkout API支持信用卡/借记卡(包括3D Secure)、Apple Pay、Google Pay、支付宝、微信支付以及iDEAL、Sofort等多种本地支付方式。
Aitishiku.com