Пример #1
0
        /// <summary>
        /// 接收并验证网关的支付通知
        /// </summary>
        public async Task ReceivedAsync()
        {
            GatewayBase gateway = NotifyProcess.GetGateway(_gateways);

            if (gateway is NullGateway)
            {
                OnUnknownGateway(new UnknownGatewayEventArgs(gateway));
            }
            else
            {
                try
                {
                    if (await gateway.ValidateNotifyAsync())
                    {
                        OnPaymentSucceed(new PaymentSucceedEventArgs(gateway));
                        gateway.WriteSuccessFlag();
                    }
                    else
                    {
                        OnPaymentFailed(new PaymentFailedEventArgs(gateway));
                        gateway.WriteFailureFlag();
                    }
                }
                catch (GatewayException ex)
                {
                    OnPaymentFailed(new PaymentFailedEventArgs(gateway)
                    {
                        Message = ex.Message
                    });
                    gateway.WriteFailureFlag();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 获取网关
        /// </summary>
        /// <param name="gateways">网关列表</param>
        /// <returns></returns>
        public static GatewayBase GetGateway(IGateways gateways)
        {
            var         gatewayData = ReadNotifyData();
            GatewayBase gateway     = null;

            foreach (var item in gateways.GetList())
            {
                if (ExistParameter(item.NotifyVerifyParameter, gatewayData))
                {
                    if (item.Merchant.AppId == gatewayData
                        .GetStringValue(item.NotifyVerifyParameter.FirstOrDefault()))
                    {
                        gateway = item;
                        break;
                    }
                }
            }

            if (gateway is null)
            {
                gateway = new NullGateway();
            }

            gateway.GatewayData = gatewayData;
            return(gateway);
        }
Пример #3
0
        /// <summary>
        /// 初始化支付事件数据的基类
        /// </summary>
        /// <param name="gateway">支付网关</param>
        protected PaymentEventArgs(GatewayBase gateway)
        {
            _gateway = gateway;
#if DEBUG
            _notifyServerHostAddress = "127.0.0.1";
#else
            _notifyServerHostAddress = HttpUtil.RemoteIpAddress.ToString();
#endif
        }
Пример #4
0
        /// <summary>
        /// 添加网关
        /// </summary>
        /// <param name="gateway">网关</param>
        /// <returns></returns>
        public bool Add(GatewayBase gateway)
        {
            if (gateway != null)
            {
                _list.Add(gateway);
                return(true);
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// 接收并验证网关的支付通知
        /// </summary>
        public async Task ReceivedAsync()
        {
            GatewayBase gateway = NotifyProcess.GetGateway(_gateways);

            if (gateway is NullGateway)
            {
                OnUnknownGateway(new UnknownGatewayEventArgs(gateway));
                return;
            }

            try
            {
                if (await gateway.ValidateNotifyAsync())
                {
                    if (HttpUtil.RequestType == "GET")
                    {
                        OnPaymentSucceed(new PaymentSucceedEventArgs(gateway));
                        return;
                    }

                    if (!gateway.IsSuccessPay)
                    {
                        OnPaymentFailed(new PaymentFailedEventArgs(gateway));
                        gateway.WriteFailureFlag();
                        return;
                    }

                    bool result = OnPaymentSucceed(new PaymentSucceedEventArgs(gateway));
                    if (result)
                    {
                        gateway.WriteSuccessFlag();
                    }
                    else
                    {
                        gateway.WriteFailureFlag();
                    }
                }
                else
                {
                    OnPaymentFailed(new PaymentFailedEventArgs(gateway));
                    gateway.WriteFailureFlag();
                }
            }
            catch (GatewayException ex)
            {
                OnPaymentFailed(new PaymentFailedEventArgs(gateway)
                {
                    Message = ex.Message
                });
                gateway.WriteFailureFlag();
            }
        }
Пример #6
0
        /// <summary>
        /// 添加网关
        /// </summary>
        /// <param name="gateway">网关</param>
        /// <returns></returns>
        public bool Add(GatewayBase gateway)
        {
            if (gateway != null)
            {
                if (!Exist(gateway.Merchant.AppId))
                {
                    _list.Add(gateway);

                    return(true);
                }
                else
                {
                    throw new GatewayException("该商户数据已存在");
                }
            }

            return(false);
        }
Пример #7
0
        /// <summary>
        /// 接收并验证网关的支付通知
        /// </summary>
        public async Task ReceivedAsync()
        {
            GatewayBase gateway = NotifyProcess.GetGateway(gatewayList);

            if (gateway.GatewayType != GatewayType.None)
            {
                if (await gateway.ValidateNotifyAsync())
                {
                    OnPaymentSucceed(new PaymentSucceedEventArgs(gateway));
                    gateway.WriteSuccessFlag();
                }
                else
                {
                    OnPaymentFailed(new PaymentFailedEventArgs(gateway));
                    gateway.WriteFailureFlag();
                }
            }
            else
            {
                OnUnknownGateway(new UnknownGatewayEventArgs(gateway));
            }
        }
Пример #8
0
        /// <summary>
        /// 获取网关
        /// </summary>
        /// <param name="gateways">网关列表</param>
        /// <returns></returns>
        public static GatewayBase GetGateway(IGateways gateways)
        {
            var         gatewayData = ReadNotifyData();
            GatewayBase gateway     = null;

            foreach (var item in gateways.GetList())
            {
                if (ExistParameter(item.NotifyVerifyParameter, gatewayData))
                {
                    gateway = item;
                    break;
                }
            }

            if (gateway is null)
            {
                gateway = new NullGateway();
            }

            gateway.GatewayData = gatewayData;
            return(gateway);
        }
Пример #9
0
 /// <summary>
 /// 初始化支付事件数据的基类
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public PaymentEventArgs(GatewayBase gateway)
 {
     this.gateway            = gateway;
     notifyServerHostAddress = HttpUtil.LocalIpAddress.ToString();
 }
Пример #10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gateway">网关</param>
 /// <param name="order">订单</param>
 public PaymentSetting(GatewayBase gateway, IOrder order)
     : this(gateway)
 {
     this.gateway.Order = order;
 }
Пример #11
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gateway">网关</param>
 public PaymentSetting(GatewayBase gateway)
 {
     this.gateway = gateway;
 }
Пример #12
0
 /// <summary>
 /// 初始化支付事件数据的基类
 /// </summary>
 /// <param name="gateway">支付网关</param>
 protected PaymentEventArgs(GatewayBase gateway)
 {
     _gateway = gateway;
     _notifyServerHostAddress = HttpUtil.RemoteIpAddress;
 }