erio
79192cf65b
feat(payment): harden wxpay config validation with structured errors
...
Motivation: platform-certificate mode is being phased out by WeChat (2024-10+,
newly-provisioned merchants already cannot download platform certificates at
all), and wxpay config errors currently surface only when an order is being
created — admins have no feedback at save time. Also, errors were returned as
natural-language strings, leaving the frontend no way to localize them.
Changes:
- backend/internal/payment/provider/wxpay.go
- Replace fmt.Errorf with structured infraerrors.BadRequest errors:
- WXPAY_CONFIG_MISSING_KEY (metadata: key)
- WXPAY_CONFIG_INVALID_KEY_LENGTH (metadata: key, expected, actual)
- WXPAY_CONFIG_INVALID_KEY (metadata: key) for malformed PEMs
- Parse privateKey and publicKey PEMs in NewWxpay so malformed keys fail
at save time instead of at order creation.
- Keep the pubkey verifier (NewSHA256WithRSAPubkeyVerifier) as the single
supported verifier; no more loadKeyPair helper.
- backend/internal/service/payment_order.go invokeProvider
- If CreateProvider or CreatePayment returns a structured ApplicationError,
pass it through (optionally enriching metadata with provider/instance_id)
instead of wrapping it as generic PAYMENT_GATEWAY_ERROR — so clients see
the actual reason code (e.g. WXPAY_CONFIG_MISSING_KEY) and can localize.
- Simplify a few messages (TOO_MANY_PENDING, DAILY_LIMIT_EXCEEDED,
PAYMENT_GATEWAY_ERROR, NO_AVAILABLE_INSTANCE) to keyword form with
metadata for template variables.
- backend/internal/service/payment_config_providers.go
- New helper validateProviderConfig calls provider.CreateProvider at save
time. Enabled instances are validated on both Create and Update so admins
see config errors immediately in the dialog, not later at order creation.
- Disabled instances are not validated (half-filled drafts are allowed).
- backend/internal/payment/provider/wxpay_test.go
- Add generateTestKeyPair helper that produces valid RSA-2048 PKCS8/PKIX
PEMs per test, used by the valid-config baseline (prior fake strings no
longer pass the eager PEM check).
- Cover each structured-error branch (missing/invalid-length/malformed PEM).
2026-04-20 19:49:45 +08:00
..
2026-03-05 11:50:58 +08:00
2026-03-07 13:39:47 +08:00
2026-02-21 14:16:18 +08:00
2026-02-08 13:06:25 +08:00
2026-03-23 03:49:28 +08:00
2026-02-24 16:48:16 +08:00
2026-03-06 05:07:52 +08:00
2026-03-05 11:50:58 +08:00
2026-03-08 14:12:17 +08:00
2026-03-14 17:37:34 +08:00
2026-04-19 18:45:04 +08:00
2026-03-31 13:24:22 +08:00
2026-03-23 10:16:52 +08:00
2026-04-05 17:11:01 +08:00
2026-04-14 16:26:46 +08:00
2026-04-14 16:26:46 +08:00
2026-04-05 17:11:01 +08:00
2026-04-15 15:29:52 +08:00
2026-04-15 15:29:52 +08:00
2026-04-15 15:29:52 +08:00
2026-04-15 15:29:52 +08:00
2026-04-14 09:32:11 +08:00
2026-04-01 02:19:42 +08:00
2026-04-19 18:45:04 +08:00
2026-04-14 20:34:53 +08:00
2026-03-01 14:39:07 +08:00
2026-04-14 09:15:49 +08:00
2026-03-02 03:59:31 +08:00
2026-03-19 22:27:55 +08:00
2026-03-12 23:37:36 +08:00
2026-04-17 22:06:32 +08:00
2026-04-09 18:14:28 +08:00
2026-03-16 16:22:31 +08:00
2026-04-05 17:11:01 +08:00
2026-04-09 18:14:28 +08:00
2026-04-17 22:06:32 +08:00
2026-03-07 15:06:13 +08:00
2026-02-02 22:13:50 +08:00
2026-03-07 15:06:13 +08:00
2026-02-09 07:02:12 +08:00
2026-02-09 07:02:12 +08:00
2026-04-04 14:32:26 +08:00
2026-04-04 14:32:26 +08:00
2026-03-27 14:33:05 +08:00
2026-04-04 14:32:26 +08:00
2026-03-27 20:11:24 +08:00
2026-03-27 20:18:07 +08:00
2026-04-01 02:19:42 +08:00
2026-02-11 13:41:55 +08:00
2026-04-01 12:24:52 +08:00
2026-03-25 19:03:12 +08:00
2026-03-25 17:38:41 +08:00
2026-03-16 04:58:23 +08:00
2026-03-16 04:58:23 +08:00
2026-03-16 04:58:58 +08:00
2026-03-27 14:33:05 +08:00
2026-03-17 01:47:08 +08:00
2026-04-05 17:21:36 +08:00
2026-03-25 19:03:12 +08:00
2026-02-07 12:31:10 +08:00
2026-02-07 14:39:25 +08:00
2026-03-23 03:49:28 +08:00
2026-03-16 01:31:54 +08:00
2026-04-14 17:35:27 +08:00
2026-04-14 09:26:32 +08:00
2026-03-15 14:04:13 +08:00
2026-04-10 17:55:37 +08:00
2026-03-19 22:27:55 +08:00
2026-03-19 22:27:55 +08:00
2026-02-23 12:45:37 +08:00
2026-03-19 22:27:55 +08:00
2026-03-15 14:04:13 +08:00
2026-03-09 13:13:39 +08:00
2026-04-14 11:27:32 +08:00
2026-03-09 13:13:39 +08:00
2026-04-09 02:20:51 +00:00
2026-03-16 20:22:10 +08:00
2026-03-16 20:22:10 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:31:45 +08:00
2026-04-14 09:35:20 +08:00
2026-03-13 17:00:16 +08:00
2026-03-13 17:00:16 +08:00
2026-03-13 17:00:16 +08:00
2026-03-13 17:00:16 +08:00
2026-03-13 19:15:27 +08:00
2026-03-13 19:15:27 +08:00
2026-03-03 16:11:05 +08:00
2026-03-03 15:01:10 +08:00
2026-03-07 10:13:51 +08:00
2026-04-17 22:06:32 +08:00
2026-04-17 22:06:32 +08:00
2026-04-17 22:06:32 +08:00
2026-04-17 22:06:32 +08:00
2026-04-17 22:06:32 +08:00
2026-04-05 22:32:49 +08:00
2026-04-14 17:35:27 +08:00
2026-04-04 11:25:01 +08:00
2026-04-14 09:20:39 +08:00
2026-04-14 12:11:08 +08:00
2026-02-08 12:05:39 +08:00
2026-03-01 16:39:21 +08:00
2026-03-18 11:08:58 +08:00
2026-03-16 01:31:54 +08:00
2026-03-09 19:55:18 +08:00
2026-04-14 17:35:27 +08:00
2026-02-09 10:39:09 +08:00
2026-03-23 03:49:28 +08:00
2026-03-12 16:53:18 +08:00
2026-03-12 16:53:18 +08:00
2026-03-12 16:53:18 +08:00
2026-03-18 14:16:50 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:05:54 +08:00
2026-02-09 07:02:12 +08:00
2026-02-09 07:02:12 +08:00
2026-04-14 10:18:39 +08:00
2026-02-12 19:01:09 +08:00
2026-04-14 10:18:39 +08:00
2026-02-13 19:27:07 +08:00
2026-02-10 11:42:39 +08:00
2026-02-10 21:40:31 +08:00
2026-02-12 23:43:47 +08:00
2026-03-27 14:33:05 +08:00
2026-03-14 02:21:22 +08:00
2026-02-07 12:31:10 +08:00
2026-02-09 21:35:41 +08:00
2026-02-21 14:16:18 +08:00
2026-04-08 14:06:06 +08:00
2026-03-10 11:20:10 +08:00
2026-04-08 16:11:19 +08:00
2026-04-08 16:23:02 +08:00
2026-03-19 16:56:18 +08:00
2026-02-06 09:54:29 +08:00
2026-04-04 11:25:01 +08:00
2026-04-04 11:25:01 +08:00
2026-03-26 11:17:25 +08:00
2026-03-24 09:32:34 +08:00
2026-03-27 14:33:05 +08:00
2026-03-24 09:32:34 +08:00
2026-03-27 14:33:05 +08:00
2026-03-03 13:20:58 +08:00
2026-04-04 12:38:50 +08:00
2026-04-04 12:38:50 +08:00
2026-01-29 01:49:51 +08:00
2026-04-08 14:06:06 +08:00
2026-04-14 09:23:02 +08:00
2026-04-19 18:05:25 +08:00
2026-04-19 18:05:25 +08:00
2026-02-06 16:09:58 +08:00
2026-02-07 14:32:08 +08:00
2026-03-13 17:00:16 +08:00
2026-03-13 17:00:16 +08:00
2026-02-09 06:47:22 +08:00
2026-04-05 17:11:01 +08:00
2026-02-07 20:05:29 +08:00
2026-04-17 22:06:32 +08:00
2026-04-19 18:45:04 +08:00
2026-03-12 16:53:18 +08:00
2026-02-28 15:01:20 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 17:35:27 +08:00
2026-03-04 20:25:15 +08:00
2026-04-01 00:45:56 +08:00
2026-04-16 01:53:22 +08:00
2026-03-23 10:16:52 +08:00
2026-03-12 11:04:14 +08:00
2026-02-03 21:34:55 +08:00
2026-02-26 10:53:04 +08:00
2026-03-02 16:04:20 +08:00
2026-02-09 07:02:12 +08:00
2026-03-24 09:32:01 +08:00
2026-03-24 09:32:01 +08:00
2026-03-23 03:49:28 +08:00
2026-03-16 01:31:54 +08:00
2026-03-24 09:31:32 +08:00
2026-03-18 10:06:35 +08:00
2026-03-18 10:06:35 +08:00
2026-04-17 22:06:32 +08:00
2026-03-30 11:43:07 +08:00
2026-03-27 14:33:05 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-03-19 16:56:18 +08:00
2026-03-26 11:17:25 +08:00
2026-03-27 20:11:24 +08:00
2026-03-18 11:08:58 +08:00
2026-03-18 11:08:58 +08:00
2026-04-04 11:17:49 +08:00
2026-04-04 15:15:33 +08:00
2026-02-24 23:24:48 +08:00
2026-02-28 15:01:20 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 09:35:20 +08:00
2026-03-30 16:23:38 +08:00
2026-03-30 16:44:15 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-23 03:50:03 +08:00
2026-04-16 02:01:50 +00:00
2026-03-31 13:04:55 +08:00
2026-04-04 11:25:01 +08:00
2026-02-21 12:06:24 +08:00
2026-02-21 12:06:24 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-04-09 12:29:49 +08:00
2026-04-11 22:48:45 +08:00
2026-04-11 22:48:45 +08:00
2026-04-09 12:29:49 +08:00
2026-03-29 20:52:29 +08:00
2026-03-24 19:20:15 +08:00
2026-04-04 14:07:19 +08:00
2026-04-02 00:11:17 +08:00
2026-04-02 01:03:22 +08:00
2026-04-11 22:48:45 +08:00
2026-04-11 22:48:45 +08:00
2026-04-15 23:56:56 +08:00
2026-04-17 22:06:32 +08:00
2026-03-10 03:00:58 +08:00
2026-02-22 21:04:52 +08:00
2026-04-01 00:46:38 +08:00
2026-03-16 10:28:51 +08:00
2026-04-08 14:17:49 +08:00
2026-04-16 01:53:22 +08:00
2026-02-28 15:01:20 +08:00
2026-04-09 12:29:28 +08:00
2026-04-09 12:29:28 +08:00
2026-04-07 11:27:57 +03:00
2026-04-04 14:07:19 +08:00
2026-03-30 22:29:26 +08:00
2026-04-05 17:11:01 +08:00
2026-03-30 00:21:51 +08:00
2026-02-28 15:01:20 +08:00
2026-04-05 17:21:36 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-23 00:10:22 +08:00
2026-04-02 20:44:28 +08:00
2026-02-28 15:01:20 +08:00
2026-03-09 15:08:37 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-23 03:50:03 +08:00
2026-02-28 15:01:20 +08:00
2026-03-05 11:50:58 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-04-14 20:13:59 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-16 10:50:02 +08:00
2026-04-07 11:40:41 +03:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-06 20:49:47 +08:00
2026-04-14 09:23:02 +08:00
2026-03-05 11:50:58 +08:00
2026-03-05 11:50:58 +08:00
2026-04-15 15:29:52 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-09 09:51:26 +08:00
2026-02-09 08:19:01 +08:00
2026-03-14 18:47:37 +08:00
2026-02-08 12:05:39 +08:00
2026-03-20 18:22:00 +08:00
2026-02-12 19:01:09 +08:00
2026-04-14 17:35:27 +08:00
2026-03-04 13:45:49 +08:00
2026-03-04 13:45:49 +08:00
2026-03-04 13:45:49 +08:00
2026-02-12 16:25:44 +08:00
2026-02-12 16:27:29 +08:00
2026-04-14 17:35:27 +08:00
2026-03-21 23:30:13 +08:00
2026-02-12 14:20:14 +08:00
2026-02-12 14:20:14 +08:00
2026-02-12 14:20:14 +08:00
2026-03-21 23:30:13 +08:00
2026-03-04 15:22:46 +08:00
2026-03-04 13:45:49 +08:00
2026-02-09 08:27:14 +08:00
2026-03-11 17:32:00 +08:00
2026-02-28 15:01:20 +08:00
2026-04-04 12:38:50 +08:00
2026-03-11 17:32:00 +08:00
2026-02-22 13:31:30 +08:00
2026-02-07 12:31:10 +08:00
2026-04-09 17:49:02 +08:00
2026-03-13 17:18:04 +08:00
2026-03-15 17:26:18 +08:00
2026-03-15 17:26:18 +08:00
2026-02-12 16:25:44 +08:00
2026-02-12 16:27:29 +08:00
2026-04-14 17:35:27 +08:00
2026-02-12 17:42:29 +08:00
2026-03-04 13:45:49 +08:00
2026-03-21 23:49:50 +08:00
2026-03-21 23:30:13 +08:00
2026-03-18 16:22:19 +08:00
2026-02-12 14:20:56 +08:00
2026-04-15 01:27:24 +08:00
2026-04-11 13:16:35 +08:00
2026-04-11 13:16:35 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 17:35:27 +08:00
2026-04-19 02:22:53 +08:00
2026-04-20 19:49:45 +08:00
2026-04-11 13:16:35 +08:00
2026-04-15 01:39:00 +08:00
2026-04-11 13:16:35 +08:00
2026-04-15 01:27:24 +08:00
2026-04-11 13:16:35 +08:00
2026-04-11 13:16:35 +08:00
2026-04-20 19:49:45 +08:00
2026-04-15 01:27:24 +08:00
2026-04-15 01:50:19 +08:00
2026-04-11 13:16:35 +08:00
2026-03-19 19:03:13 +08:00
2026-04-17 09:37:25 +08:00
2026-02-20 12:13:04 +08:00
2026-02-05 18:40:49 +08:00
2026-03-17 08:40:08 +08:00
2026-03-17 08:40:08 +08:00
2026-03-14 02:21:22 +08:00
2026-04-14 20:13:59 +08:00
2026-02-14 00:21:56 +08:00
2026-03-08 06:59:53 +08:00
2026-03-07 21:24:06 +08:00
2026-04-17 10:17:50 +08:00
2026-03-23 10:16:52 +08:00
2026-04-03 01:50:26 +08:00
2026-03-16 01:31:54 +08:00
2026-02-05 12:42:54 +08:00
2026-03-04 13:54:18 +08:00
2026-03-04 13:54:18 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 20:34:22 +08:00
2026-03-08 06:59:53 +08:00
2026-03-08 06:59:53 +08:00
2026-03-05 16:37:07 +08:00
2026-02-07 12:31:10 +08:00
2026-02-09 21:35:41 +08:00
2026-04-08 10:39:15 -07:00
2026-04-16 20:41:40 +08:00
2026-02-02 22:13:50 +08:00
2026-03-12 02:42:57 +03:00
2026-04-09 02:20:51 +00:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:30:51 +08:00
2026-04-14 10:18:39 +08:00
2026-02-06 22:55:12 +08:00
2026-02-07 21:18:03 +08:00
2026-04-19 18:45:04 +08:00
2026-03-18 11:32:35 +08:00
2026-03-06 01:07:28 +08:00
2026-02-02 22:13:50 +08:00
2026-02-10 17:52:10 +08:00
2026-02-10 17:51:49 +08:00
2026-03-13 10:39:35 +08:00
2026-03-18 09:23:19 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-02-07 12:31:10 +08:00
2026-04-04 11:13:58 +08:00
2026-02-10 17:52:10 +08:00
2026-02-12 19:01:09 +08:00
2026-03-27 14:33:05 +08:00
2026-02-02 22:13:50 +08:00
2026-04-05 17:11:01 +08:00
2026-03-30 00:21:51 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-02-02 22:13:50 +08:00
2026-02-12 19:01:09 +08:00
2026-04-16 01:53:22 +08:00
2026-04-17 22:07:15 +08:00
2026-04-14 09:36:26 +08:00
2026-03-12 16:53:18 +08:00
2026-02-28 15:01:20 +08:00
2026-02-28 15:01:20 +08:00
2026-03-12 18:38:09 +08:00
2026-04-04 11:09:01 +08:00
2026-02-28 15:01:20 +08:00
2026-04-14 09:22:12 +08:00
2026-02-22 12:56:57 +08:00
2026-02-22 12:56:57 +08:00
2026-03-03 20:59:12 +08:00
2026-03-06 16:47:51 +08:00
2026-03-06 16:47:51 +08:00
2026-03-12 23:37:36 +08:00
2026-03-03 01:05:11 +08:00
2026-04-14 11:27:32 +08:00
2026-04-14 09:36:26 +08:00
2026-03-18 09:23:19 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 17:35:27 +08:00
2026-04-14 09:26:08 +08:00