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

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

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

                    if (!gateway.IsSuccessPay)
                    {
                        OnPayFailed(new PayFailedEventArgs(gateway));
                        gateway.WriteFailureFlag();
                        return;
                    }

                    bool result = OnPaySucceed(new PaySucceedEventArgs(gateway));
                    if (result)
                    {
                        gateway.WriteSuccessFlag();
                    }
                    else
                    {
                        gateway.WriteFailureFlag();
                    }
                }
                else
                {
                    OnPayFailed(new PayFailedEventArgs(gateway));
                    gateway.WriteFailureFlag();
                }
            }
            catch (GatewayException ex)
            {
                OnPayFailed(new PayFailedEventArgs(gateway)
                {
                    Message = ex.Message
                });
                gateway.WriteFailureFlag();
            }
        }
Beispiel #2
0
        public async Task <SendEventResult> ReceivedAsync(bool writeFlag)
        {
            var gateway = await NotifyProcess.GetGatewayAsync(_gateways);

            var sendEventResult = await SendNotifyEventAsync(gateway);

            if (writeFlag)
            {
                sendEventResult.WriteFlagXml();
            }

            return(sendEventResult);
        }
Beispiel #3
0
        /// <summary>
        /// 接收并验证网关的支付通知
        /// </summary>
        public async Task ReceivedAsync()
        {
            var gateway = NotifyProcess.GetGateway(_gateways);

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

            try
            {
                if (!await gateway.ValidateNotifyAsync())
                {
                    OnUnknownNotify(new UnKnownNotifyEventArgs(gateway)
                    {
                        Message = "签名验证失败"
                    });
                    gateway.WriteFailureFlag();
                    return;
                }

                if (HttpUtil.RequestType == "GET")
                {
                    OnPaySucceed(new PaySucceedEventArgs(gateway));
                    return;
                }

                var result = false;
                if (gateway.IsPaySuccess)
                {
                    result = OnPaySucceed(new PaySucceedEventArgs(gateway));
                }
                else if (gateway.IsRefundSuccess)
                {
                    result = OnRefundSucceed(new RefundSucceedEventArgs(gateway));
                }
                else if (gateway.IsCancelSuccess)
                {
                    result = OnCancelSucceed(new CancelSucceedEventArgs(gateway));
                }
                else
                {
                    result = OnUnknownNotify(new UnKnownNotifyEventArgs(gateway));
                }

                if (result)
                {
                    gateway.WriteSuccessFlag();
                }
                else
                {
                    gateway.WriteFailureFlag();
                }
            }
            catch (GatewayException ex)
            {
                OnUnknownNotify(new UnKnownNotifyEventArgs(gateway)
                {
                    Message = ex.Message
                });
                gateway.WriteFailureFlag();
            }
        }