Accept an Alipay payment
Learn how to accept Alipay payments, a digital wallet popular with customers from China.
Alipay is a single-use payment method where customers are required to authenticate their payment. Customers pay by redirecting from your website or app, authorize the payment through Alipay, then return to your website or app where you get immediate notification on whether the payment succeeded or failed.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
A PaymentIntent is an object that represents your intent to collect payment from your customer and tracks the lifecycle of the payment process. Create a PaymentIntent
on your server and specify the amount to collect and a supported currency. If you have an existing Payment Intents integration, add alipay
to the list of payment method types.
Retrieve the client secret
The PaymentIntent includes a client secret that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side.
Redirect to the Alipay WalletClient-side
When a customer clicks to pay with Alipay, use Stripe.js to submit the payment to Stripe. Stripe.js is the foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to extend your integration to other payment methods. Include the Stripe.js script on your checkout page by adding it to the head
of your HTML file.
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>
Create an instance of Stripe.js with the following JavaScript on your checkout page.
// 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'
Use the client secret of the PaymentIntent
and call stripe.
to handle the Alipay redirect. Add a return_
to determine where Stripe redirects the customer after they complete the payment.
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; } });
The return_
corresponds to a page on your website that displays the result of the payment. You can determine what to display by verifying the status of the PaymentIntent
. To verify the status, the Stripe redirect to the return_
includes the following URL query parameters. You can also append your own query parameters to the return_
. They persist throughout the redirect process.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent . |
payment_ | The client secret of the PaymentIntent object. |
Supported 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
.
Currency | Country |
---|---|
cny | Any country |
aud | Australia |
cad | Canada |
eur | Austria, Belgium, Bulgaria, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Ireland, Italy, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Norway, Portugal, Romania, Slovakia, Slovenia, Spain, Sweden, Switzerland |
gbp | United Kingdom |
hkd | Hong Kong |
jpy | Japan |
myr | Malaysia |
nzd | New Zealand |
sgd | Singapore |
usd | United States |
If you have a bank account in another currency and would like to create an Alipay payment in that currency, you can contact support. Support for additional currencies is provided on a case-by-case basis.