## Confirm a WeChat Pay payment Use `stripe.confirmWechatPayPayment` in the WeChat Pay payment method creation flow when the customer submits your payment form. When called, it will confirm the [PaymentIntent](/api/payment_intents.md) with `data` you provide and handle the [NextAction](/api/payment_intents/object.md#payment_intent_object-next_action) for the customer to authorize the payment. When you confirm a `PaymentIntent`, it needs to have an attached [PaymentMethod](/api/payment_methods.md). In addition to confirming the `PaymentIntent`, this method can automatically create and attach a new `PaymentMethod` for you. If you have already attached a `PaymentMethod` you can call this method without needing to provide any additional data. These use cases are detailed in the sections that follow. > Note that `stripe.confirmWechatPayPayment` may take several seconds to complete and display the QR code. > During that time, you should disable your form from being resubmitted and show a waiting indicator like a spinner. > If you receive an error result, you should be sure to show that error to the customer, re-enable the form, and hide the waiting indicator. By default, `stripe.confirmWechatPayPayment` will display WeChat Pay QR code. If there is an error, or when handling next actions manually by using the `handleActions: false` option, it will return a `Promise` which resolves with a `result` object. This object has either: * `result.paymentIntent`: the successful [PaymentIntent](/api/payment_intents). * `result.error`: an error. Refer to the [API reference](/api/errors) for all possible errors. **Syntax:** `stripe.confirmWechatPayPayment(...)` - `clientSecret` (string) **required** The [client secret](/api/payment_intents/object.md#payment_intent_object-client_secret) of the `PaymentIntent`. - `data` (object) Data to be sent with the request. Refer to the [Payment Intents API](/api/payment_intents/confirm.md) for a full list of parameters. - `payment_method` (string | object) Either the `id` of an existing [PaymentMethod](/api/payment_methods.md), or an object containing data to create a `PaymentMethod` with. See the use case sections below for details. - `options` (object) An options object to control the behavior of this method. - `handleActions` (boolean) Set this to `false` if you would like to [handle displaying the WeChat Pay QR code yourself](/payments/wechat-pay/accept-a-payment?platform=web.md#submit-payment). ### Use case: Without an existing payment method If you have not already created a `PaymentMethod`, you can pass payment method parameters, and the newly created `PaymentMethod` will be used to confirm the `PaymentIntent`. ### Data argument properties - `payment_method` (object) **required** Pass payment method billing details. - `billing_details` (object) The [billing_details](/api/payment_methods/create.md#create_payment_method-billing_details) associated with the payment method. ### Confirm without existing payment method ```js stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', { payment_method: { billing_details: { name: '{NAME}', email: '{EMAIL}' }, wechat_pay: {}, }, } ).then(function({error, paymentIntent}) { if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } }); ``` ```es_next const {error, paymentIntent} = await stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', { payment_method: { billing_details: { name: '{NAME}', email: '{EMAIL}' }, wechat_pay: {}, }, } ); if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } ``` ### Use case: With an existing payment method If you have already created a `PaymentMethod`, you can pass its `id` to `payment_method` and it will be used to confirm the `PaymentIntent`. ### Data argument properties - `payment_method` (string) **required** The `id` of an existing `PaymentMethod`. ### Confirm with existing payment method ```js stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', { payment_method: '{PAYMENT_METHOD_ID}', } ).then(function({error, paymentIntent}) { if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } }); ``` ```es_next const {error} = await stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', { payment_method: '{PAYMENT_METHOD_ID}', } ); if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } ``` ### Use case: With an attached PaymentMethod If you have already attached a `PaymentMethod` to this `PaymentIntent`, then you can confirm without passing in any additional data. ### Confirm with an attached PaymentMethod ```js stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', {} ).then(function({error, paymentIntent}) { if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } }); ``` ```es_next const {error} = await stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', {} ); if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } ``` ### Confirm a WeChat Pay payment ```js stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', {} ).then(function({error, paymentIntent}) { if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } }); ``` ```es_next const {error} = await stripe.confirmWechatPayPayment( '{PAYMENT_INTENT_CLIENT_SECRET}', {} ); if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'succeeded') { // Inform the customer that the payment was successful } else if (paymentIntent.status === 'requires_action') { // Inform the customer that the payment did not go through } ```