Example #1
0
        /// <summary>
        ///     执行支付通知
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public virtual async Task <string> ExecPayNotifyAsync(PayNotifyInput input)
        {
            var action = PaymentRegisters.FirstOrDefault(p =>
                                                         input.Provider.Equals(p.Key, StringComparison.OrdinalIgnoreCase));

            if (action == null)
            {
                throw new UserFriendlyException($"Provider:{input.Provider} 不存在,请确认是否已注册相关逻辑!");
            }

            var result = await action.ExecPayNotifyAsync(input);

            if (result == null)
            {
                throw new UserFriendlyException("ExecPayNotifyAsync必须处理并返回支付参数!");
            }
            if (string.IsNullOrWhiteSpace(result.BusinessParams))
            {
                throw new UserFriendlyException("请配置自定义参数!");
            }
            //目前仅用支付参数的业务字段存储key,自定义数据在交易日志的CustomData中
            var key = result.BusinessParams.Contains("{") ? result.BusinessParams.FromJsonString <JObject>()["key"]?.ToString() : result.BusinessParams;

            await ExecuteCallback(key, result.OutTradeNo, result.TradeNo, result.TotalFee);

            return(result.SuccessResult?.ToString());
        }
Example #2
0
        public override async Task <ExecPayNotifyOutputDto> ExecPayNotifyAsync(PayNotifyInput input)
        {
            using (var obj = IocManager.ResolveAsDisposable <WeChatPayApi>())
            {
                var api    = obj.Object;
                var outDto = new ExecPayNotifyOutputDto();
                var result = await api.PayNotifyHandler(input.Request.Body, async (output, error) =>
                {
                    //获取微信支付自定义数据
                    if (string.IsNullOrWhiteSpace(output.Attach))
                    {
                        throw new UserFriendlyException("自定义参数不允许为空!");
                    }
                    var outTradeNo        = output.OutTradeNo;
                    var totalFee          = decimal.Parse(output.TotalFee) / 100;
                    outDto.TradeNo        = output.TransactionId;
                    outDto.BusinessParams = output.Attach;
                    outDto.TotalFee       = totalFee;
                    outDto.OutTradeNo     = outTradeNo;
                });

                outDto.SuccessResult = result;
                return(outDto);
            }
        }
        public override async Task <ExecPayNotifyOutputDto> ExecPayNotifyAsync(PayNotifyInput input)
        {
            using (var obj = IocManager.ResolveAsDisposable <IAllinpayAppService>())
            {
                var api        = obj.Object;
                var dictionary = input.Request.Form.ToDictionary(p => p.Key,
                                                                 p2 => p2.Value.FirstOrDefault()?.ToString());
                //签名校验
                if (!api.PayNotifyHandler(dictionary))
                {
                    throw new UserFriendlyException("通联支付签名错误!");
                }

                // ReSharper disable once StringLiteralTypo
                var outTradeNo = input.Request.Form["outtrxid"];
                var tradeNo    = input.Request.Form["trxid"];
                var totalFee   = (decimal.Parse(input.Request.Form["trxamt"]) / 100);
                // ReSharper disable once IdentifierTypo
                var trxreserved = input.Request.Form["trxreserved"];
                if (string.IsNullOrWhiteSpace(trxreserved))
                {
                    throw new UserFriendlyException("自定义参数不允许为空!");
                }

                return(await Task.FromResult(new ExecPayNotifyOutputDto()
                {
                    BusinessParams = trxreserved,
                    OutTradeNo = outTradeNo,
                    TradeNo = tradeNo,
                    TotalFee = totalFee,
                    SuccessResult = "success"
                }));
            }
        }
Example #4
0
        public override async Task <ExecPayNotifyOutputDto> ExecPayNotifyAsync(PayNotifyInput input)
        {
            using (var obj = IocManager.ResolveAsDisposable <IAlipayAppService>())
            {
                var api = obj.Object;

                var dictionary = input.Request.Form.ToDictionary(p => p.Key,
                                                                 p2 => p2.Value.FirstOrDefault()?.ToString());
                //签名校验
                if (!api.PayNotifyHandler(dictionary))
                {
                    throw new UserFriendlyException("支付宝支付签名错误!");
                }

                var outTradeNo     = input.Request.Form["out_trade_no"];
                var tradeNo        = input.Request.Form["trade_no"];
                var charset        = input.Request.Form["charset"];
                var totalFee       = decimal.Parse(input.Request.Form["total_fee"]);
                var businessParams = input.Request.Form["business_params"];
                if (string.IsNullOrWhiteSpace(businessParams))
                {
                    throw new UserFriendlyException("自定义参数不允许为空!");
                }

                return(await Task.FromResult(new ExecPayNotifyOutputDto()
                {
                    BusinessParams = businessParams,
                    OutTradeNo = outTradeNo,
                    TotalFee = totalFee,
                    TradeNo = tradeNo,
                    SuccessResult = "success"
                }));
            }
        }
Example #5
0
        public async Task <IActionResult> PayNotify(int?tenantId, string provider)
        {
            if (string.IsNullOrWhiteSpace(provider))
            {
                throw new ArgumentException("请传递提供程序!", nameof(provider));
            }

            LoggerAction("Debug", "正在处理支付信息");
            var input = new PayNotifyInput
            {
                TenantId = tenantId,
                Provider = provider,
                Request  = Request
            };
            var result = await Task.Run(() =>
            {
                try
                {
                    return(PayNotifyFunc(input));
                }
                catch (Exception ex)
                {
                    LoggerAction("Error", "调用回调处理逻辑时出错:" + ex);
                    throw new PayNotifyException("调用回调处理逻辑时出错!");
                }
            });

            LoggerAction("Debug", "回调处理结果:" + result);
            return(Content(result));
        }
Example #6
0
        public override async Task <ExecPayNotifyOutputDto> ExecPayNotifyAsync(PayNotifyInput input)
        {
            using (var obj = IocManager.ResolveAsDisposable <IGlobalAlipayAppService>())
            {
                var api = obj.Object;

                var dictionary = input.Request.Form.ToDictionary(p => p.Key, p2 => p2.Value.FirstOrDefault()?.ToString());
                //签名校验
                if (!api.PayNotifyHandler(dictionary))
                {
                    throw new UserFriendlyException("支付宝支付签名错误!");
                }
                var outTradeNo = input.Request.Form["out_trade_no"];
                var tradeNo    = input.Request.Form["trade_no"];
                var charset    = input.Request.Form["charset"];
                var totalFee   = Convert.ToDecimal(input.Request.Form["total_fee"]);
                //交易状态
                string tradeStatus = input.Request.Form["trade_status"];

                return(await Task.FromResult(new ExecPayNotifyOutputDto()
                {
                    //待处理
                    BusinessParams = null,
                    OutTradeNo = outTradeNo,
                    TradeNo = tradeNo,
                    TotalFee = totalFee,
                    SuccessResult = "success"
                }));
            }
        }
Example #7
0
 /// <summary>
 /// 支付状态异步通知
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public async Task <ResultDto> PayNotify(PayNotifyInput input)
 {
     if (input.trade_status == "TRADE_SUCCESS")
     {
     }
     if (input.trade_status == "TRADE_CLOSED")
     {
         //未付款交易超时关闭,或支付完成后全额退款
     }
     if (input.trade_status == "TRADE_FINISHED")
     {
         //交易结束,不可退款
     }
     return(new ResultDto {
         Code = 0, Message = "支付状态异步通知", Data = input
     });
 }
        /// <summary>
        /// 支付状态异步通知
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ResultDto> PayNotify(PayNotifyInput input)
        {
            //0ba47efc-ac09-4174-9678-330531eb7910
            var no = input.No.Substring(0, 8) + "-" + input.No.Substring(8, 4) + "-" + input.No.Substring(12, 4) + "-" +
                     input.No.Substring(16, 4) + "-" + input.No.Substring(20, 12);

            Logger.Debug("AppWeChatPayService-PayNotify-" + no);
            if (input.ResultCode == "SUCCESS")
            {
                Logger.Debug("AppWeChatPayService-PayNotify-SUCCESS");
            }
            if (input.ResultCode == "FAIL")
            {
                //未付款交易超时关闭,或支付完成后全额退款
                Logger.Debug("AppWeChatPayService-PayNotify-FAIL");
            }
            return(new ResultDto {
                Code = 0, Message = "支付状态异步通知", Data = input
            });
        }
 /// <summary>
 /// 支付回调
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public virtual Task <ExecPayNotifyOutputDto> ExecPayNotifyAsync(PayNotifyInput input)
 {
     throw new NotImplementedException();
 }