Beispiel #1
0
        /// <summary>
        /// 更新支付结果记录并关联支付请求记录
        /// </summary>
        /// <param name="resultInfo">支付结果记录</param>
        /// <returns></returns>
        public virtual PayRequestInfo RelateRequestInfo(PayResultInfo resultInfo)
        {
            //判断是否存在有效的支付结果记录,如果存在,则当前支付结果记录不执行
            bool exist = PayResultDAL.ExistValidPayResult(resultInfo.OrderId, resultInfo.TradeNo, (AppEnum.PayType)resultInfo.PayType);

            if (exist)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                resultInfo.ResultDesc    = "已存在有效的支付结果记录";
            }

            PayRequestInfo requestInfo = null;

            if (resultInfo.ExecuteResult == (int)ResultStatus.Success)
            {
                requestInfo = PayRequestDAL.GetValidPayRequest(resultInfo.OrderId, (AppEnum.PayType)resultInfo.PayType);
                if (requestInfo != null && requestInfo.SysNo > 0)
                {
                    resultInfo.RequestSysNo = requestInfo.SysNo;
                }
            }

            //更新支付结果记录信息
            PayResultDAL.Update(resultInfo);

            return(requestInfo);
        }
Beispiel #2
0
        /// <summary>
        /// 校验支付参数
        /// </summary>
        /// <param name="data">业务数据报文</param>
        /// <param name="payType">支付方式</param>
        /// <returns></returns>
        private ExecuteResult <PayOrderInfo> CheckParamaters(string data, AppEnum.PayType payType)
        {
            //校验结果
            var result = new ExecuteResult <PayOrderInfo>();
            //参数名称
            string paramName = null;
            //金额匹配表达式(最多保留2位小数正实数)
            string amtReg = @"^\d+(\.[0-9]{1,2}0*)?$";

            #region 校验支付报文结构
            var info = JsonHelper.Deserialize <PayOrderInfo>(data);
            if (info == null)
            {
                result.Status  = ResultStatus.Failure;
                result.Message = "参数data格式不正确";
                return(result);
            }
            #endregion

            #region 校验参数类型和取值范围

            #region 校验订单编号
            paramName = "orderId";
            if (string.IsNullOrWhiteSpace(info.OrderId))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}不能为空", paramName);
                return(result);
            }
            #endregion

            #region 校验支付金额
            paramName = "paymentAmt";
            if (string.IsNullOrWhiteSpace(info.PaymentAmt))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}不能为空", paramName);
                return(result);
            }
            decimal paymentAmt = 0;
            if (!Regex.IsMatch(info.PaymentAmt, amtReg) || !decimal.TryParse(info.PaymentAmt, out paymentAmt))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}类型错误", paramName);
                return(result);
            }
            if (paymentAmt <= 0)
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}必须大于0", paramName);
                return(result);
            }
            #endregion

            #region 校验支付条形码
            paramName = "barcode";
            if (string.IsNullOrWhiteSpace(info.Barcode))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}不能为空", paramName);
                return(result);
            }
            #endregion

            #region 校验支付完成的通知地址
            paramName = "notifyUrl";
            if (string.IsNullOrWhiteSpace(info.NotifyUrl))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}不能为空", paramName);
                return(result);
            }
            if (!info.NotifyUrl.IsUrl())
            {
                result.Status  = ResultStatus.Failure;
                result.Message = string.Format("参数{0}格式错误", paramName);
                return(result);
            }
            #endregion

            #endregion

            #region 校验是否已支付
            if (PayResultDAL.ExistValidPayResult(info.OrderId, payType))
            {
                result.Status  = ResultStatus.Failure;
                result.Message = "该订单已成功支付,不能重复支付";
                return(result);
            }
            #endregion

            result.Status = ResultStatus.Success;
            result.Data   = info;
            return(result);
        }