示例#1
0
        /// <summary>
        /// 根据商户信息获得门店支付权限,若只传商户ID,则返回全部门店的状态信息,若传门店ID则只返回指定门店的支付权限信息
        /// </summary>
        /// <param name="cid">商户号</param>
        /// <param name="storeId">门店号(可选)</param>
        /// <returns></returns>
        public QctPayReturn GetMerchStorePayInfos(int cid, string storeId = "")
        {
            var merchObj = PaySvc.GetMerchByCID(cid);

            if (merchObj == null)
            {
                return(QctPayReturn.Fail("请先申请开通商户,若您已经申请,请等待审核"));
            }

            var query = TStoreRepost.GetQuery().Where(o => o.CID == cid);

            if (string.IsNullOrWhiteSpace(storeId))
            {
                query = query.Where(o => o.State == (short)TraderStoreState.Enabled);
            }
            else
            {
                query = query.Where(o => o.StoreNum == storeId);
            }
            var queryStore = (from s in query
                              select new MerchStorePayItem
            {
                StoreId = s.StoreNum,
                State = s.State == (short)TraderStoreState.Enabled ? DataItemState.Enabled : DataItemState.Disabled
            }).ToList();
            var data = new MerchStorePayModel()
            {
                CID   = cid,
                Items = queryStore
            };

            return(QctPayReturn.Success(data: data));
        }
示例#2
0
        /// <summary>
        /// 验证商户访问权限(1、支付许可权限;2、商家支付通道权限;3、商家接口通道权限;)
        /// </summary>
        /// <returns></returns>
        public QctPayReturn VerifyMerchAccess()
        {
            var result = PaySvc.CheckMerchAccess(ReqModel.Mch_Id, ReqModel.Method, ReqModel.Version.ToType <decimal>());

            WithMerchModel(result.Data);
            return(result);
        }
示例#3
0
        /// <summary>
        /// 获取商户门店信息
        /// </summary>
        /// <returns></returns>
        public MerchantStoreChannelModel GetMerchStore()
        {
            var storeObj = PaySvc.GetMerchStore(MerchModel, ReqModel.Store_Id);

            WithMerchStoreModel(storeObj);
            return(storeObj);
        }
        /// <summary>
        /// 创建生成支付通知
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override SxfPayReturn Build(SxfPayNotifyRequest reqModel)
        {
            TradeOrder tradeOrder  = null;
            var        tradeResult = new TradeResult(reqModel);
            //保存通知结果并更改TradeOrder状态
            var isSucc = PaySvc.SaveMchTradeResult(tradeResult, out tradeOrder);

            if (!isSucc)
            {
                return(SxfPayReturn.Fail(msg: "数据接收失败"));
            }
            else
            {
                try
                {
                    var payNotify    = new NotifyPayRequest(tradeOrder, tradeResult);
                    var payNotifyDic = PaySignHelper.ToASCIIDictionary(payNotify);
                    return(SendPost(PayConst.QCTTRADE_NOTIFY_PAY, payNotifyDic, tradeOrder.CID, tradeOrder.PayNotifyUrl));
                }
                catch (Exception ex)
                {
                    LogEngine.WriteError(string.Format("发起支付后台通知请求异常:商户ID:{0},门店ID:{1},返回参数:{2}", reqModel.MerchantId, reqModel.ShopId, reqModel.ToJson()), null, LogModule.支付交易);
                    return(SxfPayReturn.Fail(msg: "数据接收失败"));
                }
            }
        }
示例#5
0
        /// <summary>
        /// 创建生产退款订单
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override QctPayReturn Build(RefundApplyRequest reqModel)
        {
            WithReqModel(reqModel);
            WithOutTradeNo(reqModel.Out_Refund_No);
            var canObj = CanBuilder();

            if (!canObj.Successed)
            {
                return(canObj);
            }
            else
            {
                ReqModel.ResetRfdNotifyUrl(MerchModel.RfdNotifyUrl);
                var tradeOrder = new TradeOrder(ReqModel, MerchStoreModel)
                {
                    TradeNo       = OrderHelper.GetMaxTradeNo(),
                    OutTradeNo    = ReqModel.Out_Refund_No,
                    OldOutTradeNo = ReqModel.Out_Trade_No,
                    TotalAmount   = ReqModel.Refund_Amount,
                    SourceType    = MerchModel.SourceType,
                    ApiNo         = MerchModel.ApiNo,
                    State         = (short)RefundState.RefundIng,
                    RfdNotifyUrl  = ReqModel.Refund_Notify_Url,
                    OrderType3    = ((short)SxfOrderType.CommonOrder),
                    TradeType     = (short)QctTradeType.Expense,
                    FeeType       = (short)PayFeeType.RMB,
                    BuyerMobile   = ""
                };
                var result = PaySvc.SaveTradeOrder(tradeOrder);
                if (result)
                {
                    //构建Sxf请求参数,签名,发起请求
                    var sxfReqModel = new SxfRefundApplyRequest(tradeOrder, PayConfig.SxfRefundNotifyUrl);
                    var rstObj      = SendPost <SxfRefundApplyRequest, SxfRefundApplyResponse>(MerchStoreModel.ApiUrl, sxfReqModel);
                    if (rstObj.Successed)
                    {
                        //处理返回成功结果,保存退款结果,后进行Qct签名并返回结果回发给商户,fishtodo:暂忽略验证Sxf返回的响应结果签名
                        var sxfRspModel = (SxfRefundApplyResponse)rstObj.Data;
                        //保存退款结果
                        var rfdApplyRsp = new RefundApplyResponse(tradeOrder, sxfRspModel)
                        {
                            Out_Trade_No = sxfReqModel.OldOutTradeNo
                        };
                        return(QctPayReturn.Success(data: PaySignHelper.ToDicAndSign(rfdApplyRsp, MerchModel.SecretKey, "sign")));
                    }
                    else
                    {
                        return(rstObj);
                    }
                }
                else
                {
                    return(ResultFail(msg: "订单提交失败", logMsg: string.Format("退款请求失败:{0},异常信息:{1}", reqModel.ToJson(), tradeOrder.ToJson())));
                }
            }
        }
示例#6
0
        /// <summary>
        /// 判断订单号是否重复
        /// </summary>
        /// <returns></returns>
        public QctPayReturn CanCreateOrder()
        {
            var can = PaySvc.CanCreateOrder(ReqModel.Mch_Id, OutTradeNo);

            if (can)
            {
                return(QctPayReturn.Success());
            }
            else
            {
                return(QctPayReturn.Fail(msg: "订单号已存在,不能重复提交"));
            }
        }
        /// <summary>
        /// 创建生成退款通知
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override SxfPayReturn Build(SxfRefundNotifyRequest reqModel)
        {
            TradeOrder tradeOrder     = null;
            var        rfdTradeResult = new TradeResult(reqModel);
            //保存通知结果并更改TradeOrder状态
            var success = PaySvc.SaveMchTradeResult(rfdTradeResult, out tradeOrder);

            if (!success)
            {
                return(SxfPayReturn.Fail(msg: "数据接收失败"));
            }
            else
            {
                var rfdNotify    = new NotifyRefundRequest(tradeOrder, rfdTradeResult);
                var rfdNotifyDic = PaySignHelper.ToASCIIDictionary(rfdNotify);
                return(SendPost(PayConst.QCTTRADE_NOTIFY_REFUND, rfdNotifyDic, tradeOrder.CID, tradeOrder.RfdNotifyUrl));
            }
        }
示例#8
0
 /// <summary>
 /// 创建生成支付订单,购买者付款扫码,(对应融合支付:主扫支付动态二维码)
 /// </summary>
 /// <param name="reqModel"></param>
 /// <returns></returns>
 public override QctPayReturn Build(PayBuyerScanDynaRequest reqModel)
 {
     try
     {
         WithReqModel(reqModel);
         WithOutTradeNo(reqModel.Out_Trade_No);
         var canObj = CanBuilder();
         if (!canObj.Successed)
         {
             return(canObj);
         }
         else
         {
             var tradeOrder = new TradeOrder(ReqModel, MerchStoreModel, OrderHelper.GetMaxTradeNo());
             var result     = PaySvc.SaveTradeOrder(tradeOrder);
             if (result)
             {
                 //构建Sxf请求参数,签名,发起请求
                 var sxfBuildReq = new SxfBuildPayTokenRequest(tradeOrder, PayConfig.SxfPayNotifyUrl);
                 sxfBuildReq.OrderType = "1";
                 var rstObj = SendPost <SxfBuildPayTokenRequest, SxfBuildPayTokenResponse>(MerchStoreModel.ApiUrl, sxfBuildReq);
                 if (rstObj.Successed)
                 {
                     //处理返回成功结果,将返回结果进行Qct签名并返回给商户,fishtodo:暂忽略验证Sxf返回的响应结果签名
                     var resultObj = new PayBuyerScanDynaResponse(tradeOrder, (SxfBuildPayTokenResponse)rstObj.Data);
                     WithRspModel(resultObj);
                     return(QctPayReturn.Success(data: PaySignHelper.ToDicAndSign(resultObj, MerchModel.SecretKey, "sign")));
                 }
                 return(rstObj);
             }
             else
             {
                 return(ResultFail(msg: "订单提交失败", logMsg: string.Format("购买者付款扫码请求失败:{0},异常信息:{1}", ReqModel.ToJson(), tradeOrder.ToJson())));
             }
         }
     }
     catch (Exception ex)
     {
         return(ResultFail(msg: "订单提交失败", logMsg: string.Format("购买者付款扫码请求异常:{0},异常信息:{1}", ex.Message, ReqModel.ToJson())));
     }
 }
        /// <summary>
        /// 创建生成支付订单,商家收款扫码,(对应融合支付:被扫支付)
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override QctPayReturn Build(PayMerchScanRequest reqModel)
        {
            WithReqModel(reqModel);
            WithOutTradeNo(reqModel.Out_Trade_No);
            var canObj = CanBuilder();

            if (!canObj.Successed)
            {
                return(canObj);
            }
            else
            {
                var tradeOrder = new TradeOrder(ReqModel, MerchStoreModel, OrderHelper.GetMaxTradeNo());
                tradeOrder.BuyerPayToken = ReqModel.Buyer_Pay_Token;
                var result = PaySvc.SaveTradeOrder(tradeOrder);
                if (result)
                {
                    //构建Sxf请求参数,签名,发起请求
                    var sxfReqModel = new SxfScanPayRequest(tradeOrder, PayConfig.SxfPayNotifyUrl);
                    var rstObj      = SendPost <SxfScanPayRequest, SxfScanPayResponse>(MerchStoreModel.ApiUrl, sxfReqModel);
                    if (rstObj.Successed)
                    {
                        //处理返回成功结果,保存商家收款扫码结果,后进行Qct签名并返回结果回发给商户,fishtodo:暂忽略验证Sxf返回的响应结果签名
                        var sxfRspModel = (SxfScanPayResponse)rstObj.Data;
                        PaySvc.SaveMerchScanResult(sxfRspModel, out tradeOrder);
                        var merchScanRsp = new PayMerchScanResponse(tradeOrder, sxfRspModel);
                        return(QctPayReturn.Success(data: PaySignHelper.ToDicAndSign(merchScanRsp, MerchModel.SecretKey, "sign")));
                    }
                    else
                    {
                        return(rstObj);
                    }
                }
                else
                {
                    return(ResultFail(msg: "订单提交失败", logMsg: string.Format("商家收款扫码请求失败:{0},异常信息:{1}", reqModel.ToJson(), tradeOrder.ToJson())));
                }
            }
        }
示例#10
0
        /// <summary>
        /// 根据CID获取商户的支付类型列表
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public QctPayReturn GetMerchPayModes(int cid)
        {
            var payLicenseObj = PaySvc.GetPayLicense(cid, (short)TraderPayLicenseState.Audited);

            if (payLicenseObj == null)
            {
                return(QctPayReturn.Fail("请先申请支付许可"));
            }
            var merchObj = PaySvc.GetMerchByCID(cid);

            if (merchObj == null)
            {
                return(QctPayReturn.Fail("请先申请开通商户,若您已经申请,请等待审核"));
            }

            var query = (from p in PayApiRepost.GetQuery()
                         join jtpsk in TPaySecretKeyRepost.GetQuery() on p.ChannelNo equals jtpsk.ChannelNo into itpsk
                         from tpsk in itpsk.DefaultIfEmpty()
                         where tpsk.CID == cid &&
                         p.State == (short)PayApiState.HasReleased && p.OptType == (short)PayOperateType.Receipt
                         select new MerchPayModeItem()
            {
                Title = p.Title,
                ChannelNo = p.ChannelNo,
                PayMode = p.TradeMode,
                State = DataItemState.Enabled
            });
            var objs = query.ToList();
            var data = new MerchPayMode()
            {
                CID   = cid,
                Items = objs
            };

            return(QctPayReturn.Success(data: objs));
        }