{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-payments/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["img","tabs","tab","partial"]},"type":"markdown"},"seo":{"title":"WeChat Pay","description":"Learn how to Integration with PayKKa APIs","siteUrl":"https://docs.paykka.com","image":"/assets/logo.df495cc5e94d9633069f202c90e3a52a9aaff809e494405ba215cb8339e0714e.db81178d.png","keywords":"paykka, docs, doc, documentation, apis, api, portal","lang":"en-US"},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"wechat-pay","__idx":0},"children":["WeChat Pay"]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/wechat-pay-component.961cfe066a4dc207cc5dc81b243d5a78f5470dcb229f23196a56f066012990a7.ee87f053.png","alt":"WeChat Pay component","framed":false,"withLightbox":true,"width":"350","style":{"borderRadius":"8px"}},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example","__idx":1},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"npm","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","data-title":"html","header":{"title":"html","controls":{"copy":{}}},"source":"<div id=\"checkoutWechatPayField\"></div>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","data-title":"javascript","header":{"title":"javascript","controls":{"copy":{}}},"source":"import { WechatPay } from '@paykka/card-checkout-ui'\n\nconst checkoutWechatPay = paykkaCheckout.create(WechatPay, {\n  onSubmit: formValidateError => {\n    console.log('WeChat Pay payment submitted:', formValidateError)\n  },\n  onSuccess: data => {\n    console.log('WeChat Pay payment successful:', data)\n  },\n  onError: error => {\n    console.log('WeChat Pay payment failed:', error)\n  }\n})\n\ncheckoutWechatPay.mount('#checkoutWechatPayField')\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"CDN","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","data-title":"html","header":{"title":"html","controls":{"copy":{}}},"source":"<div id=\"checkoutWechatPayField\"></div>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","data-title":"javascript","header":{"title":"javascript","controls":{"copy":{}}},"source":"const { WechatPay } = PayKKaCardCheckoutUI\n\nconst checkoutWechatPay = paykkaCheckout.create(WechatPay, {\n  onSubmit: formValidateError => {\n    console.log('WeChat Pay payment submitted:', formValidateError)\n  },\n  onSuccess: data => {\n    console.log('WeChat Pay payment successful:', data)\n  },\n  onError: error => {\n    console.log('WeChat Pay payment failed:', error)\n  }\n})\n\ncheckoutWechatPay.mount('#checkoutWechatPayField')\n","lang":"javascript"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"wechat-in-app-payment","__idx":2},"children":["WeChat in-app payment"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When the user pays inside WeChat, WeChat Pay requires a WeChat OpenID to identify the payer. The checkout component does not obtain the OpenID automatically. You need to implement the OpenID retrieval flow and return the OpenID through ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["onGetOpenId"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Recommended flow:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Guide the user to open the checkout page in WeChat."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Obtain the WeChat authorization code according to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.weixin.qq.com/doc/service/guide/h5/auth.html","target":"_blank","rel":"noopener noreferrer"},"children":["WeChat webpage authorization documentation"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Send the authorization code to your server."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Your server exchanges the code for the user's OpenID with WeChat."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Return the OpenID in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["onGetOpenId"]}," callback."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const checkoutWechatPay = paykkaCheckout.create(WechatPay, {\n  onGetOpenId: async () => {\n    const response = await fetch('/api/wechat/openid')\n    const data = await response.json()\n    return data.openId\n  }\n})\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"attributes","__idx":3},"children":["Attributes"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"wechatpayprops","__idx":4},"children":["WechatPayProps"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Passed when calling the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["create"]}," method to create WeChat Pay."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"160px","data-label":"Name"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Name"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"300px","data-label":"Description"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Description"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Type"]}]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"110px","data-label":"Default"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Default"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["showEmail"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Whether to display email.",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]}," and email is already passed when creating the checkout, it will be displayed as disabled."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}," and email is not passed when creating the checkout, it will be displayed normally."]}]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["boolean"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["showAddress"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Whether to display address.",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]}," and address is already passed when creating the checkout, it will be displayed normally."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}," and address is not passed when creating the checkout, it will be displayed normally."]}]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["boolean"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["hidePaymentButton"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Whether to hide the payment button. After hiding it, you can trigger payment manually through the component ref's ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["payment()"]}," method."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["boolean"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onSubmit"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Payment submission callback, triggered after clicking the payment button.",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["formValidateError"]}," is the error information when form validation fails."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Return ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}," to stop the payment submission."]}]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(formValidateError?: Record<string, FormValidateError[]>) => void | boolean | Promise<void | boolean>"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onSuccess"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Callback after successful payment.",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PaymentSuccessData"]}," contains the information returned after successful payment, please ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#paymentsuccessdata"},"children":["refer to"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["This callback is also triggered when risk control is pending."]}]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(data: PaymentSuccessData) => void"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onError"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Callback after payment failure, can resubmit for payment.",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error"]}," is a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PayKKaError"]}," instance, typically containing the following properties:",{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type"]},": Error type."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message"]},": Error message."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["code"]},": Error code, when an API error occurs, it will return a specific error code."]}]}]}]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["(error: PayKKaError) => void"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onTimeout"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Callback when payment times out, can resubmit for payment."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["() => void"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onExpired"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Callback when the checkout counter has expired during payment, cannot pay again."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["() => void"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["WechatPay also supports the following attribute:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"160px","data-label":"Name"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Name"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"300px","data-label":"Description"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Description"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Type"]}]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"110px","data-label":"Default"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Default"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["onGetOpenId"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Callback to get the WeChat OpenID. Required only when the user pays inside WeChat. The checkout component does not handle this internally; you need to implement it yourself."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["() => string | Promise<string>"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"wechatpayref","__idx":5},"children":["WechatPayRef"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Methods and properties exposed by WeChat Pay, can be called by the WeChat Pay instance created via the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["create"]}," method, e.g.: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["checkoutWechatPay.ref.payment()"]},"."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"160px","data-label":"Name"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Name"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Description"]}]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Type"]}]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["payment"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Make a payment, enabled when the payment button is ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["not visible"]},"."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["() => void"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is an explanation of some data types:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"paymentsuccessdata","__idx":6},"children":["PaymentSuccessData"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Payment success information."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"interface PaymentSuccessData {\n  /** URL that can be redirected to after successful payment */\n  returnUrl?: string\n}\n","lang":"typescript"},"children":[]}]},"headings":[{"value":"WeChat Pay","id":"wechat-pay","depth":1},{"value":"Example","id":"example","depth":2},{"value":"WeChat in-app payment","id":"wechat-in-app-payment","depth":2},{"value":"Attributes","id":"attributes","depth":2},{"value":"WechatPayProps","id":"wechatpayprops","depth":3},{"value":"WechatPayRef","id":"wechatpayref","depth":3},{"value":"PaymentSuccessData","id":"paymentsuccessdata","depth":3}],"frontmatter":{"seo":{"title":"WeChat Pay"}},"lastModified":"2026-07-13T07:32:02.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/payments/docs/developer-resources/wechat-pay-component","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}