using System.Threading.Tasks; using PaySharp.Core.Request; using PaySharp.Core.Response; using PaySharp.Core.Utils; namespace PaySharp.Core { /// /// 网关的抽象基类 /// public abstract class BaseGateway : IGateway { #region 构造函数 /// /// 构造函数 /// protected BaseGateway() { } /// /// 构造函数 /// /// 商户数据 protected BaseGateway(IMerchant merchant) { Merchant = merchant; } #endregion #region 属性 /// /// 商户数据 /// public IMerchant Merchant { get; set; } /// /// 通知数据 /// public IResponse NotifyResponse { get; set; } /// /// 网关的地址 /// public abstract string GatewayUrl { get; set; } /// /// 网关数据 /// protected internal GatewayData GatewayData { get; set; } /// /// 是否支付成功 /// protected internal abstract bool IsPaySuccess { get; } /// /// 是否退款成功 /// protected internal abstract bool IsRefundSuccess { get; } /// /// 是否撤销成功 /// protected internal abstract bool IsCancelSuccess { get; } /// /// 需要验证的参数名称数组,用于识别不同的网关类型。 /// 商户号(AppId)必须放第一位 /// protected internal abstract string[] NotifyVerifyParameter { get; } #endregion #region 方法 /// /// 检验网关返回的通知,确认订单是否支付成功 /// protected internal abstract Task ValidateNotifyAsync(); /// /// 当接收到支付网关通知并验证无误时按照支付网关要求格式输出表示成功接收到网关通知的字符串 /// protected internal virtual void WriteSuccessFlag() { HttpUtil.Write("success"); } /// /// 当接收到支付网关通知并验证有误时按照支付网关要求格式输出表示失败接收到网关通知的字符串 /// protected internal virtual void WriteFailureFlag() { HttpUtil.Write("failure"); } /// /// 执行请求 /// /// 数据模型 /// 返回模型 /// 请求 /// public abstract TResponse Execute(Request request) where TResponse : IResponse; #endregion } }