diff --git a/modules/EasyAbp.EShop.Baskets/common.props b/modules/EasyAbp.EShop.Baskets/common.props index 62057c0b..81f31d0a 100644 --- a/modules/EasyAbp.EShop.Baskets/common.props +++ b/modules/EasyAbp.EShop.Baskets/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Orders/common.props b/modules/EasyAbp.EShop.Orders/common.props index 62057c0b..81f31d0a 100644 --- a/modules/EasyAbp.EShop.Orders/common.props +++ b/modules/EasyAbp.EShop.Orders/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Payments.WeChatPay/common.props b/modules/EasyAbp.EShop.Payments.WeChatPay/common.props index df02c817..80da1d4e 100644 --- a/modules/EasyAbp.EShop.Payments.WeChatPay/common.props +++ b/modules/EasyAbp.EShop.Payments.WeChatPay/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/EShopWeChatPayHandler.cs b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/EShopWeChatPayHandler.cs index b5479583..55b8c744 100644 --- a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/EShopWeChatPayHandler.cs +++ b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/EShopWeChatPayHandler.cs @@ -30,19 +30,26 @@ namespace EasyAbp.EShop.Payments.WeChatPay { using var disabledDataFilter = _dataFilter.Disable(); - if (xmlDocument.Attributes == null || xmlDocument.Attributes["return_code"].Value != "SUCCESS") + var xml = xmlDocument.SelectSingleNode("xml") ?? + throw new XmlDocumentMissingRequiredElementException("xml"); + + if (xml.SelectSingleNode("return_code")?.Value != "SUCCESS") { return; } + + // Todo: sign check - if (xmlDocument.Attributes["result_code"].Value == "SUCCESS") + if (xml.SelectSingleNode("result_code")?.Value == "SUCCESS") { - var orderId = Guid.Parse(xmlDocument.Attributes["out_trade_no"].Value); + var orderId = Guid.Parse(xml.SelectSingleNode("out_trade_no")?.Value ?? + throw new XmlDocumentMissingRequiredElementException("out_trade_no")); var payment = await _paymentRepository.GetAsync(orderId); - - payment.SetExternalTradingCode(xmlDocument.Attributes["transaction_id"].Value); - + + payment.SetExternalTradingCode(xml.SelectSingleNode("transaction_id")?.Value ?? + throw new XmlDocumentMissingRequiredElementException("transaction_id")); + payment.CompletePayment(_clock.Now); await _paymentRepository.UpdateAsync(payment, true); diff --git a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/UnifiedOrderFailedException.cs b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/UnifiedOrderFailedException.cs index 5e9001a9..20dc191f 100644 --- a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/UnifiedOrderFailedException.cs +++ b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/UnifiedOrderFailedException.cs @@ -4,6 +4,10 @@ namespace EasyAbp.EShop.Payments.WeChatPay { public class UnifiedOrderFailedException : BusinessException { + public UnifiedOrderFailedException() : base(message: $"Unified order failed") + { + } + public UnifiedOrderFailedException(string returnCode, string returnMsg) : base( message: $"Unified order failed, return_code: {returnCode}, return_msg: {returnMsg}") { diff --git a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/WeChatPayPaymentServiceProvider.cs b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/WeChatPayPaymentServiceProvider.cs index 07082690..52f8da66 100644 --- a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/WeChatPayPaymentServiceProvider.cs +++ b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/WeChatPayPaymentServiceProvider.cs @@ -79,21 +79,23 @@ namespace EasyAbp.EShop.Payments.WeChatPay receipt: payeeConfigurations.GetOrDefault("receipt") as string ?? "N", sceneInfo: null); - if (result.SelectSingleNode("return_code")?.Value != "SUCCESS") + var xml = result.SelectSingleNode("xml") ?? throw new UnifiedOrderFailedException(); + + if (xml.SelectSingleNode("return_code")?.Value != "SUCCESS") { - throw new UnifiedOrderFailedException(result.SelectSingleNode("return_code")?.Value, result.SelectSingleNode("return_msg")?.Value); + throw new UnifiedOrderFailedException(xml.SelectSingleNode("return_code")?.Value, xml.SelectSingleNode("return_msg")?.Value); } - if (result.SelectSingleNode("result_code")?.Value != "SUCCESS") + if (xml.SelectSingleNode("result_code")?.Value != "SUCCESS") { - throw new UnifiedOrderFailedException(result.SelectSingleNode("return_code")?.Value, - result.SelectSingleNode("return_msg")?.Value, result.SelectSingleNode("err_code_des")?.Value, - result.SelectSingleNode("err_code")?.Value); + throw new UnifiedOrderFailedException(xml.SelectSingleNode("return_code")?.Value, + xml.SelectSingleNode("return_msg")?.Value, xml.SelectSingleNode("err_code_des")?.Value, + xml.SelectSingleNode("err_code")?.Value); } - payment.SetProperty("trade_type", result.SelectSingleNode("trade_type")); - payment.SetProperty("prepay_id", result.SelectSingleNode("prepay_id")); - payment.SetProperty("code_url", result.SelectSingleNode("code_url")); + payment.SetProperty("trade_type", xml.SelectSingleNode("trade_type")); + payment.SetProperty("prepay_id", xml.SelectSingleNode("prepay_id")); + payment.SetProperty("code_url", xml.SelectSingleNode("code_url")); return await _paymentRepository.UpdateAsync(payment, true); } diff --git a/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/XmlDocumentMissingRequiredElementException.cs b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/XmlDocumentMissingRequiredElementException.cs new file mode 100644 index 00000000..ff582772 --- /dev/null +++ b/modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/XmlDocumentMissingRequiredElementException.cs @@ -0,0 +1,12 @@ +using Volo.Abp; + +namespace EasyAbp.EShop.Payments.WeChatPay +{ + public class XmlDocumentMissingRequiredElementException : BusinessException + { + public XmlDocumentMissingRequiredElementException(string elementTag) : base( + message: $"XmlDocument missing required element: {elementTag}") + { + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/common.props b/modules/EasyAbp.EShop.Payments/common.props index 62057c0b..81f31d0a 100644 --- a/modules/EasyAbp.EShop.Payments/common.props +++ b/modules/EasyAbp.EShop.Payments/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Products/common.props b/modules/EasyAbp.EShop.Products/common.props index 62057c0b..81f31d0a 100644 --- a/modules/EasyAbp.EShop.Products/common.props +++ b/modules/EasyAbp.EShop.Products/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Stores/common.props b/modules/EasyAbp.EShop.Stores/common.props index 62057c0b..81f31d0a 100644 --- a/modules/EasyAbp.EShop.Stores/common.props +++ b/modules/EasyAbp.EShop.Stores/common.props @@ -1,7 +1,7 @@ latest - 0.1.7 + 0.1.9 $(NoWarn);CS1591 true EasyAbp Team