This module provides support for PaymentIntent
with wechat_pay
as its payment method.
-
This module will provide a
PaymentAuthenticator
implementation to authenticate a PaymentIntent with next_action.wechat_pay_redirect_to_android_app by invoking the WeChat Pay SDK and passing the required parameters from that hash. -
No extra code is needed when using this module, however you will need to declare dependency on the actual WeChat Pay SDK, as this module uses reflection to invoke it.
-
In app/build.gradle, add these dependencies:
dependencies { // Stripe dependencies, make sure they have the same $stripe_sdk_version implementation 'com.stripe:stripe-android:$stripe_sdk_version' // Main Stripe SDK implementation 'com.stripe:stripe-wechatpay:$stripe_sdk_version' // WeChat Pay module // WeChat Pay SDK, make sure 6.7.0 is used implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.7.0' }
-
Then in your app, just confirm and capture the result of the
PaymentIntent
with WeChat Pay like others (see a complete example here), the WeChat app on the phone will be opened to confirm the payment.class CheckoutActivity : AppCompatActivity() { private fun startCheckout() { // create paymentMethod with WeChat Pay type val weChatPaymentMethodCreateParams = PaymentMethodCreateParams.createWeChatPay() // confirm the intent with the param val confirmParams = ConfirmPaymentIntentParams .createWithPaymentMethodCreateParams(weChatPaymentMethodCreateParams, clientSecret) stripe.confirmPayment(this, confirmParams) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (stripe.isPaymentResult(requestCode, data)) { lifecycleScope.launch { runCatching { stripe.getPaymentIntentResult(requestCode, data!!).intent }.fold( /* retrieve success/failure result */ ) } } } }
- Make sure your Android app is registered in WeChat Open Platform and its package name (应用包名) from
AndroidManifest.xml
and signature (应用签名) correctly uploaded.Note: Use the GenSignature tool provided by WeChat here to generate a signature, note the signature will differ from debug build to release build.
- Make sure the WeChat app installed on your test phone is logged in with an account with WeChat Pay enabled.
- Make sure to create a Stripe
PaymentIntent
with a Stripe live key - thePaymentIntent
created by a test key will have dummy WeChat Pay parameters that won't be recognized by WeChat. - Apart from adding the dependencies, you don't need to write any additional code with WeChat Pay SDK (e.g the
WXPayEntryActivity
or any callbacks from the WeChat Pay doc), the module will do those for you.