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, authorise 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/basil/stripe.js"></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. |
OptionalHandle the redirect manuallyServer-side
The best way to handle redirects is to use Stripe.js with confirmAlipayPayment
. If you need to manually redirect your customers:
- Provide the URL to redirect your customers to after they complete their payment.
- Confirm the
PaymentIntent
has a status ofrequires_
. The type for theaction next_
will beaction alipay_
.handle_ redirect
"next_action": { "type": "alipay_handle_redirect", "alipay_handle_redirect": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }
- Redirect the customer to the URL provided in the
next_
property.action
When the customer finishes the payment process, they’re sent to the return_
destination. The payment_
and payment_
URL query parameters are included and you can pass through your own query parameters, as described above.
OptionalHandle post-payment events
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.
Receive events and run business actions
There are a few options for receiving and running business actions.
Manually
Use the Stripe Dashboard to view all your Stripe payments, send email receipts, handle payouts, or retry failed payments.
Custom code
Build a webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.
Prebuilt apps
Handle common business events, such as automation or marketing and sales, by integrating a partner application.
Supported currencies
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
.
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 want to create an Alipay payment in that currency, you can contact support. We provide support for additional currencies on a case-by-case basis.