忽略dll文件git
This commit is contained in:
@@ -1,177 +1,177 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部通知
|
||||
/// </summary>
|
||||
public class InternalNotifySerivce : ServiceBase<PaymentNotify>, IFindService
|
||||
{
|
||||
private IHttpClientFactory m_httpClientFactory;
|
||||
ServiceHttpClient m_ServiceHttpClient;
|
||||
public InternalNotifySerivce(PaymentContext dbContext
|
||||
, ServiceHttpClient _ServiceHttpClient
|
||||
, IHttpContextAccessor httpContextAccessor
|
||||
, IHttpClientFactory _httpClientFactory) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_httpClientFactory = _httpClientFactory;
|
||||
m_ServiceHttpClient = _ServiceHttpClient;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发起内部通知,没有支付记录
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="postData"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Notify(string url, object postData)
|
||||
{
|
||||
bool success;
|
||||
string responseData = "";
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch st = new Stopwatch();
|
||||
st.Start();
|
||||
|
||||
responseData = await m_httpClientFactory
|
||||
.CreateClient(TimeSpan.FromMinutes(5))
|
||||
.PostAsJsonGetString(url, postData);
|
||||
|
||||
st.Stop();
|
||||
|
||||
LogHelper.Trace("支付内部通知请求:",
|
||||
$"{url}\n\n{postData.ToJson(true)}\n\n响应:\n{responseData}\n\n用时:{st.ElapsedMilliseconds}毫秒");
|
||||
|
||||
if (responseData.ToLower() != "success")
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error($"支付内部通知异常,{e.Message}", e);
|
||||
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
await this.Add(new PaymentNotify()
|
||||
{
|
||||
PaymentRecordId = 0,
|
||||
Url = url,
|
||||
ResponseData = responseData,
|
||||
PostData = postData.ToJson(),
|
||||
RetryCount = 0,
|
||||
NotifyType= NotifyType.Faild
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发起内部通知,有支付记录
|
||||
/// </summary>
|
||||
/// <param name="paymentRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Notify(PaymentRecord paymentRecord)
|
||||
{
|
||||
if (paymentRecord.CallbackStatus == CallbackStatus.Finished)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool success;
|
||||
|
||||
string responseData = "";
|
||||
|
||||
string callBackUrl = paymentRecord.CallbackUrl;
|
||||
|
||||
if (!callBackUrl.Has())
|
||||
{
|
||||
//LogHelper.Warn("该支付记录没有回调地址", paymentRecord.ToJson(true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!callBackUrl.StartsWith("http"))
|
||||
{
|
||||
LogHelper.Warn("该支付记录回调地址异常", paymentRecord.ToJson(true));
|
||||
return;
|
||||
}
|
||||
|
||||
callBackUrl = UrlHelper.SetUrlParam(callBackUrl, new {PaymentType = (int) paymentRecord.PaymentType});
|
||||
|
||||
var postData = new
|
||||
{
|
||||
Data = new
|
||||
{
|
||||
Attach = paymentRecord.Attach,
|
||||
OrderId = paymentRecord.OrderId
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch st = new Stopwatch();
|
||||
st.Start();
|
||||
|
||||
var client= m_ServiceHttpClient.CreateInternalClient();
|
||||
responseData = await client.PostAsJsonGetString(callBackUrl, postData);
|
||||
|
||||
st.Stop();
|
||||
|
||||
LogHelper.Trace("支付内部通知请求:",
|
||||
$"{callBackUrl}\n\n{postData.ToJson(true)}\n\n响应:\n{responseData}\n\n用时:{st.ElapsedMilliseconds}毫秒");
|
||||
|
||||
if (responseData.ToLower() != "success")
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
paymentRecord.CallbackStatus = CallbackStatus.Finished;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error($"支付内部通知异常,{e.Message}", e);
|
||||
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
var any = await this.Query(true).AnyAsync(t => t.Id == paymentRecord.Id);
|
||||
|
||||
if (!any)
|
||||
{
|
||||
await this.Add(new PaymentNotify()
|
||||
{
|
||||
PaymentRecordId = paymentRecord.Id,
|
||||
Url = callBackUrl,
|
||||
ResponseData = responseData,
|
||||
PostData = postData.ToJson(),
|
||||
RetryCount = 0,
|
||||
NotifyType=NotifyType.Faild
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部通知
|
||||
/// </summary>
|
||||
public class InternalNotifySerivce : ServiceBase<PaymentNotify>, IFindService
|
||||
{
|
||||
private IHttpClientFactory m_httpClientFactory;
|
||||
ServiceHttpClient m_ServiceHttpClient;
|
||||
public InternalNotifySerivce(PaymentContext dbContext
|
||||
, ServiceHttpClient _ServiceHttpClient
|
||||
, IHttpContextAccessor httpContextAccessor
|
||||
, IHttpClientFactory _httpClientFactory) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_httpClientFactory = _httpClientFactory;
|
||||
m_ServiceHttpClient = _ServiceHttpClient;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发起内部通知,没有支付记录
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="postData"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Notify(string url, object postData)
|
||||
{
|
||||
bool success;
|
||||
string responseData = "";
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch st = new Stopwatch();
|
||||
st.Start();
|
||||
|
||||
responseData = await m_httpClientFactory
|
||||
.CreateClient(TimeSpan.FromMinutes(5))
|
||||
.PostAsJsonGetString(url, postData);
|
||||
|
||||
st.Stop();
|
||||
|
||||
LogHelper.Trace("支付内部通知请求:",
|
||||
$"{url}\n\n{postData.ToJson(true)}\n\n响应:\n{responseData}\n\n用时:{st.ElapsedMilliseconds}毫秒");
|
||||
|
||||
if (responseData.ToLower() != "success")
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error($"支付内部通知异常,{e.Message}", e);
|
||||
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
await this.Add(new PaymentNotify()
|
||||
{
|
||||
PaymentRecordId = 0,
|
||||
Url = url,
|
||||
ResponseData = responseData,
|
||||
PostData = postData.ToJson(),
|
||||
RetryCount = 0,
|
||||
NotifyType= NotifyType.Faild
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发起内部通知,有支付记录
|
||||
/// </summary>
|
||||
/// <param name="paymentRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Notify(PaymentRecord paymentRecord)
|
||||
{
|
||||
if (paymentRecord.CallbackStatus == CallbackStatus.Finished)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool success;
|
||||
|
||||
string responseData = "";
|
||||
|
||||
string callBackUrl = paymentRecord.CallbackUrl;
|
||||
|
||||
if (!callBackUrl.Has())
|
||||
{
|
||||
//LogHelper.Warn("该支付记录没有回调地址", paymentRecord.ToJson(true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!callBackUrl.StartsWith("http"))
|
||||
{
|
||||
LogHelper.Warn("该支付记录回调地址异常", paymentRecord.ToJson(true));
|
||||
return;
|
||||
}
|
||||
|
||||
callBackUrl = UrlHelper.SetUrlParam(callBackUrl, new {PaymentType = (int) paymentRecord.PaymentType});
|
||||
|
||||
var postData = new
|
||||
{
|
||||
Data = new
|
||||
{
|
||||
Attach = paymentRecord.Attach,
|
||||
OrderId = paymentRecord.OrderId
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch st = new Stopwatch();
|
||||
st.Start();
|
||||
|
||||
var client= m_ServiceHttpClient.CreateInternalClient();
|
||||
responseData = await client.PostAsJsonGetString(callBackUrl, postData);
|
||||
|
||||
st.Stop();
|
||||
|
||||
LogHelper.Trace("支付内部通知请求:",
|
||||
$"{callBackUrl}\n\n{postData.ToJson(true)}\n\n响应:\n{responseData}\n\n用时:{st.ElapsedMilliseconds}毫秒");
|
||||
|
||||
if (responseData.ToLower() != "success")
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
paymentRecord.CallbackStatus = CallbackStatus.Finished;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error($"支付内部通知异常,{e.Message}", e);
|
||||
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
var any = await this.Query(true).AnyAsync(t => t.Id == paymentRecord.Id);
|
||||
|
||||
if (!any)
|
||||
{
|
||||
await this.Add(new PaymentNotify()
|
||||
{
|
||||
PaymentRecordId = paymentRecord.Id,
|
||||
Url = callBackUrl,
|
||||
ResponseData = responseData,
|
||||
PostData = postData.ToJson(),
|
||||
RetryCount = 0,
|
||||
NotifyType=NotifyType.Faild
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,74 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Data;
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Hncore.Payment.Request;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class PaymentRecordService : ServiceBase<PaymentRecord>, IFindService
|
||||
{
|
||||
public PaymentRecordService(PaymentContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> CreatePaymentRecord(PaymentRecord record)
|
||||
{
|
||||
bool anySuccessed = await this.Query(false)
|
||||
.AnyAsync(t => t.OrderId == record.OrderId && t.PaymentStatus == PaymentStatus.OkPay);
|
||||
|
||||
if (anySuccessed)
|
||||
{
|
||||
BusinessException.Throw(ResultCode.RepeatPay, "该订单已支付完成,不能再次支付");
|
||||
}
|
||||
|
||||
await this.Add(record);
|
||||
return record;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PaymentRecord> CreatePaymentRecord(CreateOrderRequestBase request)
|
||||
{
|
||||
//todo
|
||||
// var property = await _propertyQuery.GetOneAsync(t => t.Id == request.OwnerId);
|
||||
|
||||
// CheckHelper.NotNull(property, "物业不存在");
|
||||
|
||||
PaymentRecord paymentRecord = request.MapTo<PaymentRecord>();
|
||||
|
||||
paymentRecord.PaymentChannel = PaymentChannel.QuanFuTong;
|
||||
|
||||
if (!paymentRecord.OrderId.Has())
|
||||
{
|
||||
paymentRecord.OrderId = Guid.NewGuid().ToString().Replace("-", "");
|
||||
}
|
||||
|
||||
|
||||
await CreatePaymentRecord(paymentRecord);
|
||||
|
||||
return paymentRecord;
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> GetOne(int Id)
|
||||
{
|
||||
return await this.GetById(Id);
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> GetOneByOrderId(string orderId)
|
||||
{
|
||||
return await this.Query(false).FirstOrDefaultAsync(x => x.OrderId == orderId);
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Data;
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Hncore.Payment.Request;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class PaymentRecordService : ServiceBase<PaymentRecord>, IFindService
|
||||
{
|
||||
public PaymentRecordService(PaymentContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> CreatePaymentRecord(PaymentRecord record)
|
||||
{
|
||||
bool anySuccessed = await this.Query(false)
|
||||
.AnyAsync(t => t.OrderId == record.OrderId && t.PaymentStatus == PaymentStatus.OkPay);
|
||||
|
||||
if (anySuccessed)
|
||||
{
|
||||
BusinessException.Throw(ResultCode.RepeatPay, "该订单已支付完成,不能再次支付");
|
||||
}
|
||||
|
||||
await this.Add(record);
|
||||
return record;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PaymentRecord> CreatePaymentRecord(CreateOrderRequestBase request)
|
||||
{
|
||||
//todo
|
||||
// var property = await _propertyQuery.GetOneAsync(t => t.Id == request.OwnerId);
|
||||
|
||||
// CheckHelper.NotNull(property, "物业不存在");
|
||||
|
||||
PaymentRecord paymentRecord = request.MapTo<PaymentRecord>();
|
||||
|
||||
paymentRecord.PaymentChannel = PaymentChannel.QuanFuTong;
|
||||
|
||||
if (!paymentRecord.OrderId.Has())
|
||||
{
|
||||
paymentRecord.OrderId = Guid.NewGuid().ToString().Replace("-", "");
|
||||
}
|
||||
|
||||
|
||||
await CreatePaymentRecord(paymentRecord);
|
||||
|
||||
return paymentRecord;
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> GetOne(int Id)
|
||||
{
|
||||
return await this.GetById(Id);
|
||||
}
|
||||
|
||||
public async Task<PaymentRecord> GetOneByOrderId(string orderId)
|
||||
{
|
||||
return await this.Query(false).FirstOrDefaultAsync(x => x.OrderId == orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class TenantService : ServiceBase<TenantEntity>, IFindService
|
||||
{
|
||||
PaymentContext m_DbContext;
|
||||
public TenantService(PaymentContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class TenantService : ServiceBase<TenantEntity>, IFindService
|
||||
{
|
||||
PaymentContext m_DbContext;
|
||||
public TenantService(PaymentContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Hncore.Pass.PaymentCenter.Domain.Refund;
|
||||
using Hncore.Pass.PaymentCenter.Model;
|
||||
using Hncore.Pass.PaymentCenter.Response;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.ClientExtension;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.QueryOrder;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.Refund;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class WeiFuTongService:IFindService
|
||||
{
|
||||
private WeiFuTongClient _weiFuTongClient;
|
||||
|
||||
public WeiFuTongService(WeiFuTongClient weiFuTongClient)
|
||||
{
|
||||
_weiFuTongClient = weiFuTongClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单查询
|
||||
/// </summary>
|
||||
/// <param name="orderNo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<QueryOrderResponse> QueryOrderAsync(PaymentRecord paymentRecord
|
||||
, MchInfo mchInfo)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
var res = await _weiFuTongClient.QueryOrderAsync(new WeiFuTongQueryOrderRequest()
|
||||
{
|
||||
MchInfo = mchInfo,
|
||||
OutTradeNo = paymentRecord.Id.ToString(),
|
||||
TransactionId = paymentRecord.TransactionId,
|
||||
PaymentChannel = paymentRecord.PaymentChannel
|
||||
});
|
||||
|
||||
if (res.IsPaySuccess())
|
||||
{
|
||||
message = "支付成功";
|
||||
}
|
||||
else if (res.IsPayFailed())
|
||||
{
|
||||
message = "支付失败";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "支付中";
|
||||
}
|
||||
|
||||
if (res.IsPaySuccess() && (paymentRecord.PaymentStatus != PaymentStatus.OkPay ||
|
||||
paymentRecord.PaySuccessTime == null))
|
||||
{
|
||||
paymentRecord.SetPaySuccessed(res.TransactionId, res.GetPaySuccessTime());
|
||||
}
|
||||
|
||||
if (res.IsPayFailed() && paymentRecord.PaymentStatus != PaymentStatus.Fail)
|
||||
{
|
||||
paymentRecord.SetPayFailed();
|
||||
}
|
||||
|
||||
if ((paymentRecord.PaymentType == PaymentType.None || paymentRecord.PaymentMethod == PaymentMethod.None)
|
||||
&& res.IsPaySuccess())
|
||||
{
|
||||
paymentRecord.SetPaymentTypeFromTradeType(res.TradeType);
|
||||
}
|
||||
|
||||
return new QueryOrderResponse()
|
||||
{
|
||||
PaymentStatus = paymentRecord.PaymentStatus,
|
||||
PaymentMessage = message,
|
||||
PayType = paymentRecord.PaymentType
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退款查询
|
||||
/// </summary>
|
||||
/// <param name="refundRecord"></param>
|
||||
/// <param name="mchInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<QueryRefundResponse> QueryRefundAsync(RefundRecord refundRecord, MchInfo mchInfo)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
var res = await _weiFuTongClient.QueryRefundAsync(new WeiFuTongRefundQueryRequest()
|
||||
{
|
||||
MchInfo = mchInfo,
|
||||
OutTradeNo = refundRecord.PaymentRecordId.ToString(), //商户订单号
|
||||
TransactionId = refundRecord.TransactionId, //平台订单号
|
||||
RefundId = refundRecord.TransactionRefundId, //平台退款单号
|
||||
OutRefundNo = refundRecord.RefundId, //商户退款单号
|
||||
PaymentChannel = refundRecord.PaymentChannel
|
||||
});
|
||||
|
||||
if (res.IsRefundSuccess())
|
||||
{
|
||||
message = "退款成功";
|
||||
}
|
||||
else if (res.IsRefundFail() || res.IsNotExists())
|
||||
{
|
||||
message = "退款失败";
|
||||
}
|
||||
else if (res.IsCancel())
|
||||
{
|
||||
message = "已撤销";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "退款中";
|
||||
}
|
||||
|
||||
if (res.IsRefundSuccess() && (refundRecord.RefundStatus != RefundStatus.Success
|
||||
|| refundRecord.RefundSuccessTime == null))
|
||||
{
|
||||
refundRecord.SetRefundSuccessed(res.RefundQueryItems.First().RefundId, DateTime.Now);
|
||||
}
|
||||
|
||||
if (res.IsRefundSuccess() && refundRecord.CancelStatus == CancelStatus.Canceling)
|
||||
{
|
||||
refundRecord.SetCancelFailed();
|
||||
}
|
||||
|
||||
if ((res.IsRefundFail() || res.IsNotExists()) && refundRecord.RefundStatus != RefundStatus.Fail)
|
||||
{
|
||||
refundRecord.SetRefundFailed();
|
||||
}
|
||||
|
||||
if (res.IsCancel())
|
||||
{
|
||||
if (refundRecord.CancelStatus == CancelStatus.Canceling)
|
||||
{
|
||||
refundRecord.SetCancelSuccessed();
|
||||
}
|
||||
else
|
||||
{
|
||||
refundRecord.SetRefundFailed();
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryRefundResponse()
|
||||
{
|
||||
CancelStatus = refundRecord.CancelStatus,
|
||||
PayType = refundRecord.PaymentType,
|
||||
RefundMessage = message,
|
||||
RefundStatus = refundRecord.RefundStatus,
|
||||
RefundId = refundRecord.RefundId,
|
||||
OperatorName = refundRecord.OperatorName,
|
||||
RefundReason = refundRecord.RefundReason
|
||||
};
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.PaymentCenter.Domain;
|
||||
using Hncore.Pass.PaymentCenter.Domain.Refund;
|
||||
using Hncore.Pass.PaymentCenter.Model;
|
||||
using Hncore.Pass.PaymentCenter.Response;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.ClientExtension;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.QueryOrder;
|
||||
using Hncore.Pass.PaymentCenter.WeiFuTong.Refund;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.PaymentCenter.Service
|
||||
{
|
||||
public class WeiFuTongService:IFindService
|
||||
{
|
||||
private WeiFuTongClient _weiFuTongClient;
|
||||
|
||||
public WeiFuTongService(WeiFuTongClient weiFuTongClient)
|
||||
{
|
||||
_weiFuTongClient = weiFuTongClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单查询
|
||||
/// </summary>
|
||||
/// <param name="orderNo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<QueryOrderResponse> QueryOrderAsync(PaymentRecord paymentRecord
|
||||
, MchInfo mchInfo)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
var res = await _weiFuTongClient.QueryOrderAsync(new WeiFuTongQueryOrderRequest()
|
||||
{
|
||||
MchInfo = mchInfo,
|
||||
OutTradeNo = paymentRecord.Id.ToString(),
|
||||
TransactionId = paymentRecord.TransactionId,
|
||||
PaymentChannel = paymentRecord.PaymentChannel
|
||||
});
|
||||
|
||||
if (res.IsPaySuccess())
|
||||
{
|
||||
message = "支付成功";
|
||||
}
|
||||
else if (res.IsPayFailed())
|
||||
{
|
||||
message = "支付失败";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "支付中";
|
||||
}
|
||||
|
||||
if (res.IsPaySuccess() && (paymentRecord.PaymentStatus != PaymentStatus.OkPay ||
|
||||
paymentRecord.PaySuccessTime == null))
|
||||
{
|
||||
paymentRecord.SetPaySuccessed(res.TransactionId, res.GetPaySuccessTime());
|
||||
}
|
||||
|
||||
if (res.IsPayFailed() && paymentRecord.PaymentStatus != PaymentStatus.Fail)
|
||||
{
|
||||
paymentRecord.SetPayFailed();
|
||||
}
|
||||
|
||||
if ((paymentRecord.PaymentType == PaymentType.None || paymentRecord.PaymentMethod == PaymentMethod.None)
|
||||
&& res.IsPaySuccess())
|
||||
{
|
||||
paymentRecord.SetPaymentTypeFromTradeType(res.TradeType);
|
||||
}
|
||||
|
||||
return new QueryOrderResponse()
|
||||
{
|
||||
PaymentStatus = paymentRecord.PaymentStatus,
|
||||
PaymentMessage = message,
|
||||
PayType = paymentRecord.PaymentType
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退款查询
|
||||
/// </summary>
|
||||
/// <param name="refundRecord"></param>
|
||||
/// <param name="mchInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<QueryRefundResponse> QueryRefundAsync(RefundRecord refundRecord, MchInfo mchInfo)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
var res = await _weiFuTongClient.QueryRefundAsync(new WeiFuTongRefundQueryRequest()
|
||||
{
|
||||
MchInfo = mchInfo,
|
||||
OutTradeNo = refundRecord.PaymentRecordId.ToString(), //商户订单号
|
||||
TransactionId = refundRecord.TransactionId, //平台订单号
|
||||
RefundId = refundRecord.TransactionRefundId, //平台退款单号
|
||||
OutRefundNo = refundRecord.RefundId, //商户退款单号
|
||||
PaymentChannel = refundRecord.PaymentChannel
|
||||
});
|
||||
|
||||
if (res.IsRefundSuccess())
|
||||
{
|
||||
message = "退款成功";
|
||||
}
|
||||
else if (res.IsRefundFail() || res.IsNotExists())
|
||||
{
|
||||
message = "退款失败";
|
||||
}
|
||||
else if (res.IsCancel())
|
||||
{
|
||||
message = "已撤销";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "退款中";
|
||||
}
|
||||
|
||||
if (res.IsRefundSuccess() && (refundRecord.RefundStatus != RefundStatus.Success
|
||||
|| refundRecord.RefundSuccessTime == null))
|
||||
{
|
||||
refundRecord.SetRefundSuccessed(res.RefundQueryItems.First().RefundId, DateTime.Now);
|
||||
}
|
||||
|
||||
if (res.IsRefundSuccess() && refundRecord.CancelStatus == CancelStatus.Canceling)
|
||||
{
|
||||
refundRecord.SetCancelFailed();
|
||||
}
|
||||
|
||||
if ((res.IsRefundFail() || res.IsNotExists()) && refundRecord.RefundStatus != RefundStatus.Fail)
|
||||
{
|
||||
refundRecord.SetRefundFailed();
|
||||
}
|
||||
|
||||
if (res.IsCancel())
|
||||
{
|
||||
if (refundRecord.CancelStatus == CancelStatus.Canceling)
|
||||
{
|
||||
refundRecord.SetCancelSuccessed();
|
||||
}
|
||||
else
|
||||
{
|
||||
refundRecord.SetRefundFailed();
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryRefundResponse()
|
||||
{
|
||||
CancelStatus = refundRecord.CancelStatus,
|
||||
PayType = refundRecord.PaymentType,
|
||||
RefundMessage = message,
|
||||
RefundStatus = refundRecord.RefundStatus,
|
||||
RefundId = refundRecord.RefundId,
|
||||
OperatorName = refundRecord.OperatorName,
|
||||
RefundReason = refundRecord.RefundReason
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user