Handling Error Codes
Handling Error Codes in WeChat Pay Integration
When integrating WeChat Pay, the component may return various error codes during different stages of the payment process. It is essential to handle these errors appropriately to ensure a smooth user experience and provide meaningful feedback to your customers.
The following table lists the possible error codes that can be returned by the component:
| Code | Message | Explanation |
|---|---|---|
| 400 | Bad request | Malformed request to the DNA Payments API. |
| 401 | Unauthorized | The request to the DNA Payments API was not authorized. Check your token. |
| 403 | Forbidden | You do not have permission to perform the requested action. |
| 404 | Not found | The requested resource was not found on the DNA Payments API. |
| 500 | Internal server error | An error occurred on the DNA Payments API server. |
| 1000 | Something went wrong | A general or unexpected error occurred. |
| 1001 | Failed to render button | The component could not be rendered in the specified containerElement. Ensure the container exists in the DOM at the time of initialization. |
| 1002 | Failed to process payment | An error occurred during the communication with the DNA Payments API while creating the transaction. This could be due to invalid order parameters or a transient server issue. |
| 1003 | Failed to process payment (timeout) | The request to create a payment order timed out. Check your internet connection and the status of the DNA Payments service. |
| 1004 | Payment data is missing | The paymentData object was not provided during initialization and was not returned by the onBeforeProcessPayment event handler. |
| 1005 | Token is missing | The authentication token was not provided during initialization and was not returned by the onBeforeProcessPayment event handler. |
| 1006 | Payment timeout | The transaction timed out because the customer did not complete the payment (e.g., scan the QR code) within the allotted time. |
| 1007 | Failed to execute onBeforeProcessPayment | The onBeforeProcessPayment asynchronous event handler threw an error (e.g., a failed network request). |
| 1008 | No result returned from onBeforeProcessPayment | The event handler was called but did not return a valid result object containing the necessary paymentData and token. |
| 1009 | paymentData field missing in result from onBeforeProcessPayment | The object returned by onBeforeProcessPayment is missing the required paymentData field. |
| 1010 | token field missing in result from onBeforeProcessPayment | The object returned by onBeforeProcessPayment is missing the required token field. |
Notes
User Experience: Provide clear instructions or next steps for the user when an error occurs, such as retrying the payment or contacting support.
By properly handling error codes, you can improve the reliability of your WeChat Pay integration and ensure a better user experience.