예제 #1
0
        public virtual void ProcessRequest(HttpContext context)
        {
            //支付ID
            int paymentModeId = Globals.SafeInt(context.Request.QueryString["modeId"], 0);
            //充值金额
            decimal balance = Globals.SafeDecimal(context.Request.QueryString["blance"], 0M);

            //参数 NULL ERROR返回首页
            if ((paymentModeId == 0) || (balance == 0M))
            {
                //Add ErrorLog..
                return;
            }

            T user = GetCurrentUser(context);
            PayConfiguration config      = PayConfiguration.GetConfig();
            PaymentModeInfo  paymentMode = PaymentModeManage.GetPaymentModeById(paymentModeId);
            GatewayProvider  provider    = config.Providers[paymentMode.Gateway.ToLower()] as GatewayProvider;

            //计算支付手续费
            decimal payCharge = paymentMode.CalcPayCharge(balance);

#warning 未支持多币种支付手续费
            //根据多币种货币换算, 计算手续费
            //decimal payCharge = Sales.ScaleMoney(paymentMode.CalcPayCharge(balance));

            if (provider != null)
            {
                RechargeRequestInfo info2 = null;
                info2 = new RechargeRequestInfo
                {
                    TradeDate      = DateTime.Now,
                    RechargeBlance = balance,
                    UserId         = user.UserId,
                    PaymentGateway = paymentMode.Gateway
                };
                info2.RechargeId = PaymentModeManage.AddRechargeBalance(info2);
                if (info2.RechargeId > 0L)
                {
                    PaymentRequest.Instance(
                        provider.RequestType,
                        this.GetPayee(paymentMode),
                        this.GetGateway(paymentMode.Gateway.ToLower()),
                        this.GetTrade(info2, payCharge, user)
                        ).SendRequest();
                }
            }
        }
예제 #2
0
        public virtual void ProcessRequest(HttpContext context)
        {
            //Safe
            if (!VerifySendPayment(context))
            {
                return;
            }

            //订单ID字符串
            string orderIdStr = string.Empty;

            //获取全部订单ID
            string[] orderIds = OrderProcessor.GetQueryString4OrderIds(context.Request, out orderIdStr);

            //订单ID NULL ERROR返回首页
            if (orderIds == null || orderIds.Length < 1)
            {
                //Add ErrorLog..
                HttpContext.Current.Response.Redirect("~/");
                return;
            }

            //合并支付 订单支付信息以第一份订单为主
            T orderInfo = Option.GetOrderInfo(orderIds[0]);

            if (orderInfo == null)
            {
                return;
            }

            //计算订单支付金额
            decimal totalMoney = this.GetOrderTotalMoney(orderIds, orderInfo);

            if (totalMoney < 0)
            {
                return;
            }

            if (orderInfo.PaymentStatus != PaymentStatus.NotYet)
            {
                //订单已支付
                context.Response.Write(
                    HttpContext.GetGlobalResourceObject("Resources", "IDS_ErrorMessage_SentPayment").ToString());
                return;
            }

            PaymentModeInfo paymentMode = GetPaymentMode(orderInfo);

            if (paymentMode == null || string.IsNullOrWhiteSpace(paymentMode.Gateway))
            {
                //订单历史的支付方式不存在
                context.Response.Write(
                    HttpContext.GetGlobalResourceObject("Resources", "IDS_ErrorMessage_NoPayment").ToString());
                return;
            }

            string getwayName = paymentMode.Gateway.ToLower();

            //获取支付网关
            GatewayProvider provider =
                PayConfiguration.GetConfig().Providers[getwayName] as GatewayProvider;

            if (provider == null)
            {
                return;
            }

            //支付网关
            GatewayInfo gatewayInfo = this.GetGateway(getwayName);

            //交易信息
            TradeInfo tradeInfo = this.GetTrade(orderIdStr, totalMoney, orderInfo);

            #region 测试模式
            //DONE: 测试模式埋点
            if (Globals.IsPaymentTestMode && !Globals.ExcludeGateway.Contains(getwayName.ToLower()))
            {
                System.Text.StringBuilder url = new System.Text.StringBuilder(gatewayInfo.ReturnUrl);
                url.AppendFormat("&out_trade_no={0}", tradeInfo.OrderId);
                url.AppendFormat("&total_fee={0}", tradeInfo.TotalMoney);
                url.AppendFormat("&sign={0}", Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString()));
                HttpContext.Current.Response.Redirect(
                    gatewayInfo.ReturnUrl.Contains("?")
                        ? url.ToString()
                        : url.ToString().Replace("&out_trade_no", "?out_trade_no"), true);
                return;
            }
            #endregion

            #region 发送支付请求
            //发送支付请求
            PaymentRequest paymentRequest = PaymentRequest.Instance(
                provider.RequestType,
                this.GetPayee(paymentMode),
                gatewayInfo,
                tradeInfo
                );
            if (paymentRequest == null)
            {
                return;
            }
            paymentRequest.SendRequest();
            #endregion
        }