- To import the module: instant
- To launch and show the Component: InstantPaymentComponent
Requirements
Preparation
- Create a developer account on the WeChat Open Platform.
- Register your mobile app with WeChat.
Start a payment with WeChat Pay
To start a payment with WeChat Pay, you need to:-
Specify in your /paymentMethods request:
- countryCode: Any supported country/region. For example, CN.
- amount.currency: Any supported currency. For example, CNY.
-
Deserialize the response from the /paymentMethods call and get the object with
type: wechatpaySDK. -
Add the WeChat Pay module:
a. Import the WeChat Pay module to your
build.gradlefile.Check the latest version on GitHub. b. Check if WeChat is available on the shopper’s device.c. If WeChat is available and the shopper chooses to pay with WeChat Pay, make a /payments request from your server.
Make a payment
-
From your server, make a /payments request:
curl
Java
PHP
C#
NodeJS (JavaScript)
Go
Python
Ruby
NodeJS (TypeScript)
The /payments response includes anactionobject that contains information about the app switch. -
Pass the
actionobject to your client app. /payments response
Handle the app switch
-
To switch the shopper to the WeChat app, initialize the WeChat Pay Action Component, and pass the
actionobject.After the shopper has completed the payment, the WeChat app redirects them back to your app, and provides anIntentobject containing the result of the payment. -
Get the result of the WeChat Pay SDK from the
Activity. Pass theintentback to the WeChat Pay Action Component. Depending on your activity’s launchMode, you can get this intent in eitheronCreateoronNewIntent.The Component notifies theobserverwith theactionComponentData. -
Pass the
actionComponentDatato your server.
Check the payment result
When the shopper returns to your app, the Component provides theactionComponentData.
- Pass the
actionComponentDatato your server. - From your server, make a
/payments/detailsrequest containing theactionComponentData.
Present the payment result
Use theresultCode that you received in the /payments/details response to present the payment result to your shopper.
The resultCode values you can receive for WeChat Pay are:
Test and go live
WeChat Pay currently has no test platform. If you have a personal WeChat account you can test your integration by either:- Canceling the transaction when you are asked to verify the payment (recommended).
- Making live WeChat Pay payments with a low value.