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-sideClient-side
First, you need a Stripe account. Register now.
Server-side
This integration requires endpoints on your server that talk to the Stripe API. Use the official libraries for access to the Stripe API from your server:
Client-side
The Stripe Android SDK is open source and fully documented.
To install the SDK, add stripe-android
to the dependencies
block of your app/build.gradle file:
Note
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
Configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API, such as in your Application
subclass:
Note
Stripe samples also use OkHttp and GSON to make HTTP requests to a server.
Integrate the Alipay SDKClient-side
For in-app payments using Alipay’s app-to-app redirect flow, you must integrate the Alipay SDK. If you don’t want to integrate the Alipay SDK, the Stripe SDK uses a WebView to redirect customers to Alipay. Integrating the Alipay SDK provides a more seamless experience for your customers, but increases the overall size of your app. See Use a WebView for more details.
After unzipping the archive, add alipaySdk-{version}.
to the libs
directory of your app. Add the libs
folder to your project’s dependency repository list:
allprojects { repositories { flatDir { dirs 'libs' } } }
Add the dependency to your app:
dependencies { // ... // Replace {version} with the version number of the Alipay SDK that you downloaded above implementation(name:"alipaySdk-{version}", ext:"aar") }
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.
Redirect to the Alipay WalletClient-side
Request a PaymentIntent from your server and store its client secret.
When the customer taps to pay with Alipay, confirm the PaymentIntent using Stripe confirmAlipayPayment
. You must supply an AlipayAuthenticator to pass data from the Stripe SDK to the Alipay SDK. The authenticator calls the Alipay payV2
method with the supplied data string. The Alipay SDK opens the Alipay app (if installed) or shows its own UI and communicates the result back to the Stripe SDK automatically.
Note
The Alipay Android SDK doesn’t support test payments. To fully test this integration, use live mode.
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.