Ejemplo n.º 1
0
 public void InitBillDownload(IAuxiliary auxiliary)
 {
     Merchant.Method     = Constant.BILLDOWNLOAD;
     Merchant.BizContent = Util.SerializeObject((Auxiliary)auxiliary);
     GatewayData.Add(Merchant);
     BuildSign();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询订单
        /// </summary>
        public INotify BuildQuery(IAuxiliary auxiliary)
        {
            InitQuery(auxiliary);

            Commit(Constant.ALIPAY_TRADE_QUERY_RESPONSE);

            return(Notify);
        }
Ejemplo n.º 3
0
        public INotify BuildRefund(IAuxiliary auxiliary)
        {
            InitRefund(auxiliary);

            Commit(true);

            return(Notify);
        }
Ejemplo n.º 4
0
        public INotify BuildClose(IAuxiliary auxiliary)
        {
            InitClose(auxiliary);

            Commit();

            return(Notify);
        }
Ejemplo n.º 5
0
        public INotify BuildRefundQuery(IAuxiliary auxiliary)
        {
            InitRefundQuery(auxiliary);

            Commit(Constant.ALIPAY_TRADE_FASTPAY_REFUND_QUERY_RESPONSE);

            return(Notify);
        }
Ejemplo n.º 6
0
        public INotify BuildRefund(IAuxiliary auxiliary)
        {
            InitRefund(auxiliary);

            Commit(Constant.ALIPAY_TRADE_REFUND_RESPONSE);

            return(Notify);
        }
Ejemplo n.º 7
0
        public INotify BuildClose(IAuxiliary auxiliary)
        {
            InitClose(auxiliary);

            Commit(Constant.ALIPAY_TRADE_CLOSE_RESPONSE);

            return(Notify);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 撤销订单
        /// </summary>
        public INotify BuildCancel(IAuxiliary auxiliary)
        {
            InitCancel(auxiliary);

            Commit(Constant.ALIPAY_TRADE_CANCEL_RESPONSE);

            return(Notify);
        }
Ejemplo n.º 9
0
        public INotify BuildRefundQuery(IAuxiliary auxiliary)
        {
            InitRefundQuery(auxiliary);

            Commit();

            return(Notify);
        }
Ejemplo n.º 10
0
        public INotify BuildCancel(IAuxiliary auxiliary)
        {
            InitCancel(auxiliary);

            Commit(true);

            return(Notify);
        }
Ejemplo n.º 11
0
        public FileStream BuildBillDownload(IAuxiliary auxiliary)
        {
            InitBillDownload(auxiliary);

            Commit();

            string result = GatewayData.GetDefaultResult();

            return(CreateCsv(result));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 验证辅助
        /// </summary>
        /// <param name="auxiliary">辅助参数</param>
        private void ValidateAuxiliary(IAuxiliary auxiliary)
        {
            if (auxiliary is null)
            {
                throw new ArgumentNullException(nameof(auxiliary));
            }

            ValidateParameter(auxiliary);
            ValidateParameter(Merchant);
        }
Ejemplo n.º 13
0
        public FileStream BuildBillDownload(IAuxiliary auxiliary)
        {
            InitBillDownload(auxiliary);

            Commit(Constant.ALIPAY_DATA_DATASERVICE_BILL_DOWNLOADURL_QUERY_RESPONSE);

            GatewayData.FromUrl(Notify.BillDownloadUrl);

            return(HttpUtil.Download(Notify.BillDownloadUrl, $"{DateTime.Now.ToString(TIMEFORMAT)}.{GatewayData.GetStringValue(Constant.FILETYPE)}"));
        }
Ejemplo n.º 14
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 接口");
        }
Ejemplo n.º 15
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 接口");
        }
Ejemplo n.º 16
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 接口");
        }
Ejemplo n.º 17
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 接口");
        }
Ejemplo n.º 18
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 接口");
        }
Ejemplo n.º 19
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 接口");
        }
Ejemplo n.º 20
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 接口");
        }
Ejemplo n.º 21
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 接口");
        }
Ejemplo n.º 22
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 接口");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 每隔5秒轮询判断用户是否支付,总共轮询5次
        /// </summary>
        private void PollQueryTradeState(IAuxiliary auxiliary)
        {
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(5000);
                BuildQuery(auxiliary);
                if (IsSuccessPay)
                {
                    OnPaymentSucceed(new PaymentSucceedEventArgs(this));
                    return;
                }
            }

            BuildCancel(auxiliary);
            OnPaymentFailed(new PaymentFailedEventArgs(this));
        }
Ejemplo n.º 24
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 接口");
        }
Ejemplo n.º 25
0
 public void InitRefund(IAuxiliary auxiliary)
 {
     GatewayUrl = REFUNDGATEWAYURL;
     InitAuxiliaryParameter(GatewayAuxiliaryType.Refund, auxiliary);
 }
Ejemplo n.º 26
0
 public void InitCancel(IAuxiliary auxiliary)
 {
     GatewayUrl = CANCELGATEWAYURL;
     InitAuxiliaryParameter(GatewayAuxiliaryType.Cancel, auxiliary);
 }
Ejemplo n.º 27
0
 public void InitClose(IAuxiliary auxiliary)
 {
     GatewayUrl = CLOSEORDERGATEWAYURL;
     InitAuxiliaryParameter(GatewayAuxiliaryType.Close, auxiliary);
 }
Ejemplo n.º 28
0
 public void InitRefundQuery(IAuxiliary auxiliary)
 {
     GatewayUrl = REFUNDQUERYGATEWAYURL;
     InitAuxiliaryParameter(GatewayAuxiliaryType.RefundQuery, auxiliary);
 }
Ejemplo n.º 29
0
 public void InitBillDownload(IAuxiliary auxiliary)
 {
     GatewayUrl = DOWNLOADBILLGATEWAYURL;
     InitAuxiliaryParameter(GatewayAuxiliaryType.BillDownload, auxiliary);
 }
Ejemplo n.º 30
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);
 }