/// <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(); } } }
/// <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); }
/// <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 }
/// <summary> /// 添加网关 /// </summary> /// <param name="gateway">网关</param> /// <returns></returns> public bool Add(GatewayBase gateway) { if (gateway != null) { _list.Add(gateway); return(true); } return(false); }
/// <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(); } }
/// <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); }
/// <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)); } }
/// <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); }
/// <summary> /// 初始化支付事件数据的基类 /// </summary> /// <param name="gateway">支付网关</param> public PaymentEventArgs(GatewayBase gateway) { this.gateway = gateway; notifyServerHostAddress = HttpUtil.LocalIpAddress.ToString(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="gateway">网关</param> /// <param name="order">订单</param> public PaymentSetting(GatewayBase gateway, IOrder order) : this(gateway) { this.gateway.Order = order; }
/// <summary> /// 构造函数 /// </summary> /// <param name="gateway">网关</param> public PaymentSetting(GatewayBase gateway) { this.gateway = gateway; }
/// <summary> /// 初始化支付事件数据的基类 /// </summary> /// <param name="gateway">支付网关</param> protected PaymentEventArgs(GatewayBase gateway) { _gateway = gateway; _notifyServerHostAddress = HttpUtil.RemoteIpAddress; }