public W1PaymentView()
        {
            PaymentService paymentService = new PaymentService();
            UrlGenerator urlGenerator;

            urlGenerator = new UrlGenerator();
            this.WMI_SUCCESS_URL = urlGenerator.GetSuccessPaymentUrl();
            this.WMI_FAIL_URL = urlGenerator.GetFailPaymentUrl();
        }
        public W1PaymentView(W1Payment w1Payment)
            : this()
        {
            PaymentService paymentService = new PaymentService();

            this.WMI_PAYMENT_NO = w1Payment.WMI_PAYMENT_NO;
            this.WMI_MERCHANT_ID = w1Payment.WMI_MERCHANT_ID;
            this.WMI_CURRENCY_ID = Convert.ToString(w1Payment.WMI_CURRENCY_ID);
            this.WMI_DESCRIPTION = w1Payment.WMI_DESCRIPTION;
            //Сейчас время в UTC+0, его не меняем
            this.WMI_EXPIRED_DATE = w1Payment.WMI_EXPIRED_DATE.ToString("s");
            this.WMI_PAYMENT_AMOUNT = string.Format(
                CultureInfo.InvariantCulture, "{0,2}",
                w1Payment.WMI_PAYMENT_AMOUNT);
            this.WMI_SIGNATURE =
                paymentService.GetSignatureAsString(this.dictionary);
        }
        public ActionResult SelectShop(Shop shop)
        {
            Basket basket;
            IList<Shop> shops;
            PaymentView paymentView;
            UrlGenerator urlGenerator;
            Payment payment, dbPayment;
            W1Payment w1Payment, dbW1Payment;
            W1PaymentView w1PaymentView;
            Individual individual;
            BasketService basketService;
            IndividualRepository individualRepository;
            PaymentRepository paymentRepository;
            PaymentService paymentService;

            //Необходимо вызвать UrlGenerator в любом Post-методе контроллера,
            //иначе Request и Url поля не будут доступны.
            //В будующем нужно исправить!
            urlGenerator = new UrlGenerator(this.Request, this.Url);

            basketService = new BasketService();
            paymentRepository = new PaymentRepository();
            paymentService = new PaymentService();
            individualRepository = new IndividualRepository();
            //----
            shop = (Shop)this._shopRepository.FindById(shop.Id); //для адреса

            basket = basketService.GetBasket(User.Identity.Name);

            //Вычитаем заказанныек книги из BookVariableInfo и
            //обвновляем Basket
            basketService.ShopProcessing(basket, shop);
            shop.Address = (Address)this._addressRepository.FindById(shop.Id);
            //--
            //Создание платежной формы W1Payment
            individual = (Individual)individualRepository
                .FindIndividualByUserProfileName(User.Identity.Name);

            w1Payment = new W1Payment();
            w1Payment.WMI_PAYMENT_AMOUNT = paymentService.DecimalCounting(
                basket.TotalAmount, shop.BookDeliveryCost);
            w1Payment.WMI_DESCRIPTION = paymentService.MakeDescription(basket.Id);
            dbW1Payment = paymentService.MakeW1Payment(w1Payment);
            //добавление payment и w1Payment
            payment = new Payment()
            {
                Id = dbW1Payment.WMI_PAYMENT_NO,
                ShopId = shop.Id,
                IndividualId = individual.Id
            };
            dbPayment = paymentService.AddPayment(payment, w1Payment);
            payment.Id = dbPayment.Id;

            //Перемещение заказов из корзины в платеж и очистка корзины
            basketService.BasketToPaymentMigration(basket, payment);

            //-Создали представление для отображения w1Payment и передачи его в POST
            w1PaymentView = new W1PaymentView(dbW1Payment);//payment, basket);

            return RedirectToAction("BasketPay", w1PaymentView);//shop); //payment);
        }
        //Метод, вызываемый при удачной оплате
        public W1ActionResult SuccessPayment()
        {
            PaymentService paymentService;
            string content;
            RequestWorking requestWorking;
            Dictionary<string, string> formFields;
            bool isAcceptedCheckSum = true;
            Payment payment;
            PaymentRepository paymentRepository;

            paymentService = new PaymentService();
            requestWorking = new RequestWorking();//this.Request);

            formFields = requestWorking.GetFormDictionary(this.Request.Form);

            //Поиск и обновление присланного платежа
            if (!formFields.ContainsKey("WMI_PAYMENT_NO"))
                return new W1ActionResult(paymentService.MakeResponseToW1("RETRY",
                    "Отсутствует параметр WMI_PAYMENT_NO"));
            if (!formFields.ContainsKey("WMI_PAYMENT_NO"))
                return new W1ActionResult(paymentService.MakeResponseToW1("RETRY",
                    "Отсутствует параметр WMI_PAYMENT_NO"));
            if (!formFields.ContainsKey("WMI_ORDER_STATE"))
                return new W1ActionResult(paymentService.MakeResponseToW1("RETRY",
                    "Отсутствует параметр WMI_ORDER_STATE"));
            if (formFields["WMI_ORDER_STATE"].ToUpper() != "ACCEPTED")
                return new W1ActionResult(paymentService.MakeResponseToW1("RETRY",
                        "Неверное состояние " + formFields["WMI_ORDER_STATE"]));

            //Наверное, сигнутура отключена в настройках
            if (formFields.ContainsKey("WMI_SIGNATURE"))
            {
                isAcceptedCheckSum = paymentService.CheckSignature(formFields);
                if (!isAcceptedCheckSum)
                    return new W1ActionResult(paymentService.MakeResponseToW1("RETRY",
                    "Неверная подпись " + formFields["WMI_SIGNATURE"]));
            }
            //OK, no comments
            //фиксируем
            paymentRepository = (PaymentRepository)this._paymentRepository;
            //связаны 1:1
            payment = (Payment)this._paymentRepository.FindById(
                Convert.ToInt32(formFields["WMI_PAYMENT_NO"]));
            payment.isPayed = true;
            paymentRepository.Edit(payment);

            return new W1ActionResult(paymentService.MakeResponseToW1("OK",
                    "Заказ #" + formFields["WMI_PAYMENT_NO"] + " оплачен!"));
        }
        //Метод, вызываемый при неудачной оплате
        public W1ActionResult FailPayment()
        {
            PaymentService paymentService;
            string content;

            paymentService = new PaymentService();
            //RETRY
            content = paymentService.MakeResponseToW1("RETRY",
                "Server is not availables temporary");
            return new W1ActionResult(content);
        }