接受支付宝付款
用 Stripe API 和 Checkout 接受支付宝付款,这是中国人广泛使用的一种数字钱包
Alipay 是一种单次使用的支付方式,客户需要验证他们的付款。客户在您的网站或应用程序中被跳转到 Alipay 页面,授权付款,然后返回您的网站或应用,然后在这里收到付款成功或失败的即时通知。
创建 PaymentIntent服务器端
PaymentIntent 是一个用来表示您从客户收款意图的对象,并可用于跟踪付款流程的生命周期。在您的服务器上创建一个 PaymentIntent
,并指定要收取的金额和支持的币种。如果您有现成的 Payment Intents 集成,则将 alipay
添加到 payment method types 列表。
检索客户端私钥
PaymentIntent 中包含的是一个客户端私钥,用于在客户端安全地完成支付流程。有不同的方法可以将客户端私钥传递到客户端。
重定向到支付宝钱包客户端
客户通过 Alipay 点击支付时,用 Stripe.js 向 Stripe 提交付款。Stripe.js 是构建支付流程的基础 JavaScript 库。它会自动处理一些复杂操作,例如下面的重定向,使您能够将集成扩展到其他支付方式。在您的结账页面包含 Stripe.js 脚本,方法是将它添加到您的 HTML 文件的 head
部分。
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></script> </head>
用下面的 JavaScript 在您的结账页面创建一个 Stripe.js 实例。
// Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
使用 PaymentIntent
的客户端私钥并调用 stripe.
来处理 支付宝重定向。添加一个 return_
,确定在客户完成付款后让 Stripe 将他们重定向到哪里。
const form = document.getElementById('payment-form'); form.addEventListener('submit', async function(event) { event.preventDefault(); // Set the clientSecret of the PaymentIntent const { error } = await stripe.confirmAlipayPayment(clientSecret, { // Return URL where the customer should be redirected after the authorization return_url: `${window.location.href}`, }); if (error) { // Inform the customer that there was an error. const errorElement = document.getElementById('error-message'); errorElement.textContent = error.message; } });
return_
对应于您网站上显示付款结果的一个页面。通过对 PaymentIntent
进行状态验证,您可以确定要显示的内容。要验证状态,Stripe 到 return_
的重定向会包含以下 URL 查询参数。您还可以将自己的查询参数附加到 return_
。它们会贯穿整个重定向过程。
参数 | 描述 |
---|---|
payment_ | PaymentIntent 的唯一标识符。 |
payment_ | PaymentIntent 对象的客户端私钥。 |
支持的货币
Your account must have a bank account for one of the following currencies. You can create Alipay payments in the currencies that map to your country. The default local currency for Alipay is cny
and customers also see their purchase amount in cny
.
货币 | 国家/地区 |
---|---|
cny | 任何国家 |
aud | 澳大利亚 |
cad | 加拿大 |
eur | 奥地利、比利时、保加利亚、塞浦路斯、捷克共和国、丹麦、爱沙尼亚、芬兰、法国、德国、希腊、爱尔兰、意大利、拉脱维亚、立陶宛、卢森堡、马耳他、荷兰、挪威、葡萄牙、罗马尼亚、斯洛伐克、斯洛文尼亚、西班牙、瑞典、瑞士 |
gbp | 英国 |
hkd | 香港 |
jpy | 日本 |
myr | 马来西亚 |
nzd | 新西兰 |
sgd | 新加坡 |
usd | 美国 |
如果您拥有以另一种货币开设的银行账户,并希望以该货币创建支付宝支付,可以联系支持服务。我们会根据具体情况为其他货币提供支持服务。