Browse Source

Fix XmlDocument usage.

pull/49/head
gdlcf88 6 years ago
parent
commit
bcc627a2b7
  1. 2
      modules/EasyAbp.EShop.Baskets/common.props
  2. 2
      modules/EasyAbp.EShop.Orders/common.props
  3. 2
      modules/EasyAbp.EShop.Payments.WeChatPay/common.props
  4. 19
      modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/EShopWeChatPayHandler.cs
  5. 4
      modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/UnifiedOrderFailedException.cs
  6. 20
      modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/WeChatPayPaymentServiceProvider.cs
  7. 12
      modules/EasyAbp.EShop.Payments.WeChatPay/src/EasyAbp.EShop.Payments.WeChatPay.Domain/EasyAbp/EShop/Payments/WeChatPay/XmlDocumentMissingRequiredElementException.cs
  8. 2
      modules/EasyAbp.EShop.Payments/common.props
  9. 2
      modules/EasyAbp.EShop.Products/common.props
  10. 2
      modules/EasyAbp.EShop.Stores/common.props

2
modules/EasyAbp.EShop.Baskets/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

2
modules/EasyAbp.EShop.Orders/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

2
modules/EasyAbp.EShop.Payments.WeChatPay/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

19
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<IMultiTenant>();
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);

4
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}")
{

20
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);
}

12
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}")
{
}
}
}

2
modules/EasyAbp.EShop.Payments/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

2
modules/EasyAbp.EShop.Products/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

2
modules/EasyAbp.EShop.Stores/common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.7</Version>
<Version>0.1.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

Loading…
Cancel
Save