예제 #1
0
        /// <summary>
        /// 初始化辅助接口的参数
        /// </summary>
        /// <param name="gatewayAuxiliaryType">辅助类型</param>
        /// <param name="auxiliary">辅助参数</param>
        private void InitAuxiliaryParameter(GatewayAuxiliaryType gatewayAuxiliaryType, IAuxiliary auxiliary)
        {
            auxiliary.Validate(gatewayAuxiliaryType);
            switch (gatewayAuxiliaryType)
            {
            case GatewayAuxiliaryType.Query:
                Merchant.Method = Constant.QUERY;
                break;

            case GatewayAuxiliaryType.Close:
                Merchant.Method = Constant.CLOSE;
                break;

            case GatewayAuxiliaryType.Cancel:
                Merchant.Method = Constant.CANCEL;
                break;

            case GatewayAuxiliaryType.Refund:
                Merchant.Method = Constant.REFUND;
                break;

            case GatewayAuxiliaryType.RefundQuery:
                Merchant.Method = Constant.REFUNDQUERY;
                break;

            default:
                break;
            }
            Merchant.BizContent = Util.SerializeObject((Auxiliary)auxiliary);
            GatewayData.Add(Merchant);
            BuildSign();
        }
예제 #2
0
 /// <summary>
 /// 初始化辅助参数
 /// </summary>
 /// <param name="gatewayAuxiliaryType">辅助类型</param>
 /// <param name="auxiliary">辅助参数</param>
 private void InitAuxiliaryParameter(GatewayAuxiliaryType gatewayAuxiliaryType, IAuxiliary auxiliary)
 {
     auxiliary.Validate(gatewayAuxiliaryType);
     Merchant.NonceStr = Util.GenerateNonceStr();
     GatewayData.Add(Merchant);
     GatewayData.Add(auxiliary);
     Merchant.Sign = BuildSign();
     GatewayData.Add(Constant.SIGN, Merchant.Sign);
 }
예제 #3
0
        /// <summary>
        /// 退款查询
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify RefundQuery(IAuxiliary auxiliary)
        {
            _gatewayAuxiliaryType = GatewayAuxiliaryType.RefundQuery;
            ValidateAuxiliary(auxiliary);

            if (this is IRefundQuery refundQuery)
            {
                return(refundQuery.BuildRefundQuery(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IRefundQuery 接口");
        }
예제 #4
0
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Close(IAuxiliary auxiliary)
        {
            _gatewayAuxiliaryType = GatewayAuxiliaryType.Close;
            ValidateAuxiliary(auxiliary);

            if (this is IClose close)
            {
                return(close.BuildClose(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IClose 接口");
        }
예제 #5
0
        /// <summary>
        /// 撤销
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Cancel(IAuxiliary auxiliary)
        {
            _gatewayAuxiliaryType = GatewayAuxiliaryType.Cancel;
            ValidateAuxiliary(auxiliary);

            if (this is ICancel cancel)
            {
                return(cancel.BuildCancel(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 ICancel 接口");
        }
예제 #6
0
        public bool Validate(GatewayAuxiliaryType gatewayAuxiliaryType)
        {
            if (gatewayAuxiliaryType != GatewayAuxiliaryType.BillDownload)
            {
                if (string.IsNullOrEmpty(OutTradeNo) && string.IsNullOrEmpty(TradeNo))
                {
                    throw new ArgumentNullException("商户订单号和支付宝订单号不可同时为空");
                }
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// 账单下载
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public void BillDownload(IAuxiliary auxiliary)
        {
            _gatewayAuxiliaryType = GatewayAuxiliaryType.BillDownload;
            ValidateAuxiliary(auxiliary);

            if (this is IBillDownload billDownload)
            {
                HttpUtil.Write(billDownload.BuildBillDownload(auxiliary));
                return;
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IBillDownload 接口");
        }
예제 #8
0
        /// <summary>
        /// 退款查询
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify RefundQuery(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(auxiliary));
            }

            if (this is IRefundQuery refundQuery)
            {
                _gatewayAuxiliaryType = GatewayAuxiliaryType.RefundQuery;
                return(refundQuery.BuildRefundQuery(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IRefundQuery 接口");
        }
예제 #9
0
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Close(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(auxiliary));
            }

            if (this is IClose close)
            {
                _gatewayAuxiliaryType = GatewayAuxiliaryType.Close;
                return(close.BuildClose(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IClose 接口");
        }
예제 #10
0
        /// <summary>
        /// 撤销
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Cancel(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(auxiliary));
            }

            if (this is ICancel cancel)
            {
                _gatewayAuxiliaryType = GatewayAuxiliaryType.Cancel;
                return(cancel.BuildCancel(auxiliary));
            }

            throw new NotSupportedException($"{GetType()} 没有实现 ICancel 接口");
        }
예제 #11
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Refund(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(IAuxiliary));
            }

            if (this is IRefund refund)
            {
                gatewayAuxiliaryType = GatewayAuxiliaryType.Refund;
                return(refund.BuildRefund(auxiliary));
            }

            throw new NotSupportedException($"{GatewayType} 没有实现 IRefund 接口");
        }
예제 #12
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public INotify Query(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(IAuxiliary));
            }

            if (this is IQuery query)
            {
                gatewayAuxiliaryType = GatewayAuxiliaryType.Query;
                return(query.BuildQuery(auxiliary));
            }

            throw new NotSupportedException($"{GatewayType} 没有实现 IQuery 接口");
        }
예제 #13
0
        /// <summary>
        /// 账单下载
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        public void BillDownload(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(auxiliary));
            }

            if (this is IBillDownload billDownload)
            {
                _gatewayAuxiliaryType = GatewayAuxiliaryType.BillDownload;
                HttpUtil.Write(billDownload.BuildBillDownload(auxiliary));
                return;
            }

            throw new NotSupportedException($"{GetType()} 没有实现 IBillDownload 接口");
        }
예제 #14
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gatewayAuxiliaryType">网关辅助类型</param>
 public NecessaryAttribute(GatewayAuxiliaryType gatewayAuxiliaryType)
 {
     this.gatewayAuxiliaryType = new GatewayAuxiliaryType[] { gatewayAuxiliaryType };
 }