Exemple #1
0
        protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Pay")
            {
                string orderCode = e.CommandArgument.ToString();
                ColoPay.Model.Pay.Order orderInfo = orderBll.GetModel(orderCode);
                bool isSuccess = true;
                if (orderInfo.PaymentStatus < 2)
                {
                    isSuccess = orderBll.CompleteOrder(orderInfo);
                }
                if (isSuccess)//成功之后需要回调商家回调地址
                {
                    try
                    {
                        ColoPay.BLL.Pay.Enterprise.Notify(orderInfo);
                    }
                    catch (Exception ex)
                    {
                        ColoPay.BLL.SysManage.LogHelp.AddErrorLog(String.Format("订单【{0}】支付回调通知失败:{1}", orderInfo.OrderCode, ex.Message), ex.StackTrace);
                    }
                }
                MessageBox.ShowSuccessTip(this, "操作成功!");
            }

            if (e.CommandName == "Notify")
            {
                string orderCode = e.CommandArgument.ToString();
                ColoPay.Model.Pay.Order orderInfo = orderBll.GetModel(orderCode);
                bool   isSuccess   = true;
                string responseStr = "";
                if (orderInfo.PaymentStatus < 2)
                {
                    isSuccess = orderBll.CompleteOrder(orderInfo);
                }
                if (isSuccess)//成功之后需要回调商家回调地址
                {
                    try
                    {
                        responseStr = ColoPay.BLL.Pay.Enterprise.Notify(orderInfo);
                    }
                    catch (Exception ex)
                    {
                        responseStr = ex.Message;
                        ColoPay.BLL.SysManage.LogHelp.AddErrorLog(String.Format("订单【{0}】支付回调通知失败:{1}", orderInfo.OrderCode, ex.Message), ex.StackTrace);
                    }
                }
                if (responseStr == "success")
                {
                    MessageBox.ShowSuccessTip(this, "操作成功!");
                }
                else
                {
                    responseStr = "回调通知失败," + responseStr;
                    MessageBox.ShowFailTip(this, responseStr);
                }
            }
            gridView.OnBind();
        }
Exemple #2
0
        public ResponseResult SubmitOrder([FromBody] PayInfo payinfo)
        {
            //YSWL.Common.DEncrypt.DEncrypt.GetMD5FromStr
            //验证是否数据安全性
            if (payinfo.amount < 0)
            {
                return(FailResult(ResponseCode.ParamError, "amount is illegal"));
            }
            if (String.IsNullOrWhiteSpace(payinfo.order_no))
            {
                return(FailResult(ResponseCode.ParamError, "ordercode is illegal"));
            }


            ColoPay.Model.Pay.Enterprise CurrEnterprise = bll.GetEnterpriseInfo(payinfo.appid, payinfo.secrit);
            if (CurrEnterprise == null)
            {
                return(FailResult(ResponseCode.ParamError, "appid or secrit is illegal"));
            }
            //判断订单是否存在
            ColoPay.Model.Pay.Order orderInfo = orderBll.GetModelEx(payinfo.order_no, CurrEnterprise.EnterpriseID);

            if (orderInfo == null)
            {
                //创建订单
                orderInfo              = new Model.Pay.Order();
                orderInfo.Agentd       = CurrEnterprise.AgentId;
                orderInfo.Amount       = payinfo.amount;
                orderInfo.AppId        = CurrEnterprise.AppId;
                orderInfo.AppReturnUrl = String.IsNullOrWhiteSpace(payinfo.return_url) ? CurrEnterprise.AppReturnUrl : payinfo.return_url;
                orderInfo.AppSecrit    = CurrEnterprise.AppSecrit;
                orderInfo.AppUrl       = HttpContext.Current.Request.Url.ToString();
                orderInfo.CreatedTime  = DateTime.Now;
                orderInfo.EnterOrder   = payinfo.order_no;
                orderInfo.EnterpriseID = CurrEnterprise.EnterpriseID;
                orderInfo.OrderCode    = DateTime.Now.ToString("yyyyMMddHHmmssfff") + CurrEnterprise.EnterpriseID;
                //获取支付方式
                ColoPay.Model.Pay.PaymentTypes typeInfo = typeBll.GetPaymentInfo(payinfo.paytype);
                if (typeInfo == null)
                {
                    return(FailResult(ResponseCode.ParamError, "paytype is illegal"));
                }
                //获取支付费率

                ColoPay.Model.Pay.EnterprisePayFee feeInfo = feeBll.GetModel(CurrEnterprise.EnterpriseID, typeInfo.ModeId);
                if (feeInfo == null)
                {
                    return(FailResult(ResponseCode.ParamError, "paytype is illegal"));
                }
                orderInfo.FeeRate         = feeInfo.FeeRate;
                orderInfo.PaymentFee      = payinfo.amount * (feeInfo.FeeRate / 100);
                orderInfo.OrderAmount     = payinfo.amount - orderInfo.PaymentFee;
                orderInfo.PaymentGateway  = typeInfo.Gateway;
                orderInfo.PaymentStatus   = 0;
                orderInfo.AppNotifyUrl    = CurrEnterprise.AppReturnUrl;
                orderInfo.PaymentTypeName = typeInfo.Name;
                orderInfo.PayModeId       = typeInfo.ModeId;
                orderInfo.OrderInfo       = String.IsNullOrWhiteSpace(payinfo.remark) ? "" : payinfo.remark;
                orderInfo.OrderId         = orderBll.Add(orderInfo);
                if (orderInfo.OrderId == 0)//创建订单失败
                {
                    return(FailResult(ResponseCode.ServiceUnavailable, "payorder is error"));
                }
            }
            else //订单已经存在了
            {
                if (orderInfo.Amount != payinfo.amount)//金额不一样,说明订单不一样
                {
                    return(FailResult(ResponseCode.OrderExists, "order_no has exist"));
                }
                if (orderInfo.PaymentStatus == 2)
                {
                    return(FailResult(ResponseCode.HasPaid, "order has paid"));
                }
            }
            string resullt = "";

            //BZ 支付金额必须要为整数,有点扯淡
            //开始支付

            if (!payinfo.istest)
            {
                //tuzh BZ_Pay 支付接口已失效
                // resullt = ColoPay.WebApi.PayApi.BZ_Pay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.get_code, orderInfo.OrderInfo);
                // 如果是网银或者快捷支付,走丰核支付
                YSWL.Log.LogHelper.AddInfoLog("支付网关", "PaymentGateway--->" + orderInfo.PaymentGateway);
                switch (orderInfo.PaymentGateway)
                {
                case "wangyin":
                case "kuaijie":
                    resullt = ColoPay.WebApi.PayApi.FengHe.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, orderInfo.OrderInfo);
                    break;

                case "onlinekj":
                    resullt = ColoPay.WebApi.PayApi.YiYuan.PayRequest(orderInfo.OrderCode, payinfo.amount, payinfo.bankcard, payinfo.moblie, payinfo.idcard, payinfo.realname, payinfo.remark);
                    break;

                case "wx":
                case "ali":
                case "aliwap":
                    resullt = ColoPay.WebApi.PayApi.MidoPay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.bankcard, payinfo.title, payinfo.product, orderInfo.Remark);
                    break;

                default:
                    resullt = ColoPay.WebApi.PayApi.MidoPay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.bankcard, payinfo.title, payinfo.product, orderInfo.Remark);
                    break;
                }
            }
            else //测试支付
            {
                bool isSuccess = orderBll.CompleteOrder(orderInfo);
                if (isSuccess)//成功之后需要回调商家回调地址
                {
                    try
                    {
                        orderInfo.PaymentStatus = 2;
                        ColoPay.BLL.Pay.Enterprise.Notify(orderInfo);
                    }
                    catch (Exception ex)
                    {
                        ColoPay.BLL.SysManage.LogHelp.AddErrorLog(String.Format("订单【{0}】BZPay支付回调通知失败:{1}", orderInfo.OrderCode, ex.Message), ex.StackTrace);
                    }
                }
            }

            return(SuccessResult(resullt));
        }