{"record":{"id":"e0eddf2abaeb0b07","repo":"JeffreySu/WeiXinMPSDK","slug":"out-trade-no-transaction-id","errorCode":null,"errorMessage":"out_trade_no 和 transaction_id 至少填写一个。","messagePattern":"out_trade_no 和 transaction_id 至少填写一个。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs","lineNumber":239,"sourceCode":"\n        /// <summary>微信支付订单号，与 out_trade_no 至少填写一个。</summary>\n        public string transaction_id { get; set; }\n\n        /// <summary>商户子订单号。</summary>\n        public string sub_order_no { get; set; }\n\n        /// <summary>微信子订单号。</summary>\n        public string sub_order_id { get; set; }\n\n        /// <inheritdoc />\n        protected override void Validate(string key)\n        {\n            base.Validate(key);\n            Require(mch_customs_no, \"mch_customs_no\");\n            if (string.IsNullOrWhiteSpace(out_trade_no) &&\n                string.IsNullOrWhiteSpace(transaction_id))\n            {\n                throw new ArgumentException(\n                    \"out_trade_no 和 transaction_id 至少填写一个。\");\n            }\n        }\n\n        /// <inheritdoc />\n        protected override void SetParameters(RequestHandler handler)\n        {\n            base.SetParameters(handler);\n            handler.SetParameterWhenNotNull(\"sign_type\", sign_type);\n            handler.SetParameter(\"mch_customs_no\", mch_customs_no);\n            handler.SetParameterWhenNotNull(\"out_trade_no\", out_trade_no);\n            handler.SetParameterWhenNotNull(\"transaction_id\", transaction_id);\n            handler.SetParameterWhenNotNull(\"sub_order_no\", sub_order_no);\n            handler.SetParameterWhenNotNull(\"sub_order_id\", sub_order_id);\n        }\n    }\n}\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs#L221-L257","documentation":"This Validate overload (for a customs request type that also requires mch_customs_no) enforces that either out_trade_no or transaction_id is provided — sub-order identifiers alone are not accepted for this API. Additionally Require(mch_customs_no, ...) must pass. Otherwise ArgumentException is thrown.","triggerScenarios":"Calling the corresponding customs API (e.g. declare/order query variant) with only sub_order_no or sub_order_id set, or with both out_trade_no and transaction_id left empty.","commonSituations":"Developers confuse this endpoint's stricter requirement (only out_trade_no/transaction_id) with the looser variant that also accepts sub_order_no/sub_order_id, and pass split-order identifiers only.","solutions":["Set out_trade_no to your merchant order number before calling the API.","Or set transaction_id to the WeChat transaction id returned by the payment.","Also confirm mch_customs_no is set, since this Validate requires it first."],"exampleFix":"// before\nvar data = new ...RequestData(key, appid, mch_id, mch_customs_no, null, null, subOrderNo, null);\n// after\nvar data = new ...RequestData(key, appid, mch_id, mch_customs_no, outTradeNo, null, subOrderNo, null);","handlingStrategy":"validation","validationCode":"// C#\nif (string.IsNullOrWhiteSpace(outTradeNo) && string.IsNullOrWhiteSpace(transactionId))\n    throw new InvalidOperationException(\"This customs API requires out_trade_no or transaction_id (sub-order ids are not accepted)\");","typeGuard":null,"tryCatchPattern":"try { await api.CallAsync(data); }\ncatch (ArgumentException ex) { log.LogWarning(\"{Msg}\", ex.Message); }","preventionTips":["Check which Validate rules apply to the specific customs endpoint you call","Keep out_trade_no/transaction_id from the original payment available in the customs flow","Don't reuse request classes across endpoints with different required fields"],"tags":["argument-validation","weixin-tenpay","customs"],"backgroundTag":"missing-required-argument","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}