通过 Stripe 使用卡支付
通过 Stripe 的安全支付处理平台接受信用卡和借记卡支付。此集成支持所有主要卡网络,具有高级欺诈保护和 3D Secure 身份验证。
设置
请按照通用的 Stripe 说明 来设置 Stripe。
集成
API 请求
curl --request POST \
--url https://api.efundpay.com/v4/transactions \
--header 'Authorization: Bearer <token>' \
--header 'x-merchant-account-id: <x-merchant-account-id>' \
--header 'Content-Type: application/json' \
--data '{
"amount": 2500,
"currency": "USD",
"payment_method": {
"method": "stripe",
"payment_method_data": {
"type": "card",
"card": {
"number": "4242424242424242",
"exp_month": 12,
"exp_year": 2024,
"cvc": "123"
}
}
},
"external_identifier": "order-12345"
}'
支付流程
- 初始化支付 - 通过 EFundPay 创建支付请求
- 客户端集成 - 使用 Stripe.js 进行安全的卡数据收集
- 支付处理 - Stripe 处理支付
- 3D Secure - 处理所需的 3D Secure 身份验证
- Webhook 通知 - 通过 webhook 接收支付状态
- 最终结果 - 处理成功/失败响应
配置
必需参数
amount- 最小货币单位的支付金额(美元以分为单位)currency- 三字母 ISO 货币代码payment_method_data.type- 卡支付设置为 "card"card.number- 卡号card.exp_month- 到期月份(1-12)card.exp_year- 到期年份(4 位数字)card.cvc- 安全代码(CVV)
可选参数
billing_address- 客户账单地址shipping_address- 客户配送地址description- 支付描述metadata- 附加元数据
客户端集成
Stripe.js 集成
// 加载 Stripe.js
const stripe = Stripe('pk_test_your_publishable_key');
// 创建支付方式
const {paymentMethod, error} = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: {
name: 'John Doe',
email: 'john@example.com',
},
});
if (error) {
console.error('错误:', error);
} else {
// 将支付方式 ID 发送到您的服务器
makePayment(paymentMethod.id);
}
支付确认
async function makePayment(paymentMethodId) {
try {
const response = await fetch('/api/payments', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
payment_method_id: paymentMethodId,
amount: 2500,
currency: 'usd',
}),
});
const result = await response.json();
handlePaymentResult(result);
} catch (error) {
console.error('支付失败:', error);
}
}
响应处理
成功响应
{
"type": "transaction",
"id": "txn_123456789",
"status": "processing",
"stripe_payment_intent_id": "pi_1234567890",
"external_identifier": "order-12345"
}
Webhook 通知
{
"ll_transaction_id": "2022012601122644",
"merchant_transaction_id": "order-12345",
"payment_data": {
"payment_status": "SUCCEEDED",
"payment_amount": "25.00",
"payment_currency_code": "USD",
"payment_time": "20220126141430",
"stripe_payment_intent_id": "pi_1234567890",
"status": "succeeded"
}
}
测试
测试卡
Stripe 提供各种测试卡号:
- 成功: 4242424242424242
- 拒绝: 4000000000000002
- 3D Secure: 4000002500003155
- 余额不足: 4000000000009995
测试环境
- 开发时使用测试 API 密钥
- 使用 Stripe 的测试商户账户
- 在测试模式下验证 webhook 通知
- 测试 3D Secure 流程
安全考虑
PCI 合规
- Stripe 处理卡数据的 PCI 合规
- 使用 Stripe.js 进行安全的卡数据收集
- 切勿存储原始卡数据
- 实施适当的 webhook 签名验证
欺诈预防
- 启用 Stripe 的风险管理工具
- 实施 3D Secure 身份验证
- 监控可疑活动
- 使用 Stripe 的欺诈检测功能
常见问题
支付失败
- 卡被拒绝 - 检查卡详情和资金
- 需要 3D Secure - 实施 3D Secure 流程
- 无效金额 - 确保金额格式正确
- 货币不匹配 - 验证货币设置
集成问题
- 未收到 Webhook - 检查 webhook 端点和签名
- 支付方式错误 - 验证支付方式创建
- 无效 API 密钥 - 检查 API 密钥配置
最佳实践
用户体验
- 实施适当的加载状态
- 显示清晰的错误消息
- 提供多种支付选项
- 针对移动设备进行优化
技术实施
- 使用 webhook 进行实时更新
- 实施适当的错误处理
- 存储支付参考
- 优雅地处理网络故障
安全
- 始终使用 HTTPS
- 验证 webhook 签名
- 实施适当的会话管理
- 定期安全审计
支持
如需通过 Stripe 集成卡支付的技术支持:
- EFundPay 支持 - 联系我们的技术团队
- Stripe 支持 - 使用 Stripe 的支持资源
- Stripe 文档 - 全面的 API 文档