コード例 #1
0
        public IActionResult GetRes()
        {
            try
            {
                SberClasses.Register_toSber   register_toSber   = Config.GetSessionValue <SberClasses.Register_toSber>(HttpContext, Config.ss_SberValues_register_toSber);
                SberClasses.Register_fromSber register_fromSber = Config.GetSessionValue <SberClasses.Register_fromSber>(HttpContext, Config.ss_SberValues_register_fromSber);

                var getOrderStatusExtended_toSber = new SberClasses.GetOrderStatusExtended_toSber()
                {
                    orderId     = register_fromSber.orderId,
                    orderNumber = register_toSber.orderNumber,
                    password    = register_toSber.password,
                    userName    = register_toSber.userName
                };

                var getOrderStatusExtended_fromSber = LNet.reqResp <SberClasses.GetOrderStatusExtended_fromSber>(HttpContext, _sb_context, getOrderStatusExtended_toSber, LNet.addr_getOrderStatusExtended, HttpMethod.Post);

                Config.SetSessionValue(HttpContext, Config.ss_SberValues_getOrderStatusExtended_toSber, getOrderStatusExtended_toSber);
                Config.SetSessionValue(HttpContext, Config.ss_SberValues_getOrderStatusExtended_fromSber, getOrderStatusExtended_fromSber);

                ViewData[Config.vd_ServerMessagePay] = $"Операция {getOrderStatusExtended_fromSber.orderNumber} на {(int)(getOrderStatusExtended_fromSber.amount/100)}руб. {(getOrderStatusExtended_fromSber.amount % 100)}коп. ушла";
                ViewData[Config.vd_TmpStatus + register_toSber.orderNumber] = getOrderStatusExtended_fromSber.errorCode;
                ViewData[Config.vd_TmpValue + register_toSber.orderNumber]  = getOrderStatusExtended_fromSber.orderNumber;
                return(View("PayResult"));
            }
            catch (Exception e)
            {
                Log.Write(e);
                return(RedirectToAction("Error"));
            }
        }
コード例 #2
0
        public IActionResult Index(string card, string sum)
        {
            try
            {
                var register_toSber = new SberClasses.Register_toSber();



                if (string.IsNullOrEmpty(card) || !int.TryParse(card, out int account))
                {
                    ViewData[Config.vd_ServerMessagePay] = "Неверный номер";
                    return(View());
                }
                else
                {
                    if (sum == null || !decimal.TryParse(sum, out decimal decamount))
                    {
                        ViewData[Config.vd_ServerMessagePay] = "Неверная сумма";
                        return(View());
                    }
                    else
                    {
                        var    amount = (int)(decamount * 100);
                        object sia_v  = new Rc.Validate()
                        {
                            account = account,
                            amount  = decamount
                        };

                        var isOk = _rc_context.SpExec(Config.DbPrefixRc + "Validate", ref sia_v) && ((Rc.Validate)sia_v).error_code == 0;

                        if (!isOk)
                        {
                            ViewData[Config.vd_ServerMessagePay] = "Номер карты не зарегистрирован";
                            return(View());
                        }

                        if (((Rc.Validate)sia_v).tariff_price > 0)
                        {
                            register_toSber.amount = (int)(((Rc.Validate)sia_v).tariff_price * 100);
                        }
                        else
                        {
                            register_toSber.amount = amount;
                        }

                        register_toSber.userName    = LNet.apiLogin;
                        register_toSber.password    = LNet.apiPass;
                        register_toSber.orderNumber = Guid.NewGuid().ToString();
                        register_toSber.returnUrl   = Config.ReturnUrl + "result";

                        Config.SetSessionValue(HttpContext, Config.ss_OrderInfo, new Sb.OrderInfo()
                        {
                            amount      = decamount,
                            emiss       = account,
                            orderNumber = register_toSber.orderNumber
                        });

                        var register_fromSber = LNet.reqResp <SberClasses.Register_fromSber>(HttpContext, _sb_context, register_toSber, LNet.addr_register, HttpMethod.Post);

                        if ((register_fromSber.errorCode ?? 0) != 0)
                        {
                            ViewData[Config.vd_ServerMessagePay] = register_fromSber.errorMessage;// "Проблема соединения с сервером, попробуйте еще раз";
                            return(View());
                        }


                        Config.SetSessionValue(HttpContext, Config.ss_SberValues_register_toSber, register_toSber);
                        Config.SetSessionValue(HttpContext, Config.ss_SberValues_register_fromSber, register_fromSber);

                        ViewData[Config.vd_Redirect] = register_fromSber.formUrl;
                    }
                }


                return(View());
            }
            catch (Exception e)
            {
                Log.Write(e);
                try
                {
                    HttpContext.Session.Clear();
                }
                catch { }
                return(Index());
                //return RedirectToAction("Error");
            }
        }