Exemplo n.º 1
0
        public async Task <IActionResult> VerifyData(string billcode, string merchant_code, string order_id, string check_sum)
        {
            var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            logger.Info("Investment with ViettelPay | Verify Data: billcode: " + billcode + ", merchant_code: " + merchant_code + ", order_id: " + order_id + ", check_sum: " + check_sum);

            var orderVerify = new OrderVerifyModel()
            {
                billcode      = billcode,
                check_sum     = check_sum?.Replace(" ", "+").Replace("=", "%3D").Replace("+", "%2B"),
                order_id      = order_id,
                merchant_code = merchant_code
            };

            try
            {
                var orderId = 0;
                var config  = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

                if (string.IsNullOrWhiteSpace(billcode) || string.IsNullOrWhiteSpace(merchant_code) || !Int32.TryParse(order_id, out orderId) || string.IsNullOrWhiteSpace(check_sum) || config.Contains("true"))
                {
                    orderVerify.error_code = "01";
                    logger.Info("Investment with ViettelPay | Verify Data: error_code: 01");

                    return(Json(orderVerify));
                }

                var order = await _orderService.GetOrder(orderId);

                if (order != null && !order.IsSuccess && !order.IsVerify)
                {
                    var checkSum = Helpers.CreateCheckSum(_configuration.GetValue <string>("PaymentSecurity:AccessCode"), _configuration.GetValue <string>("PaymentSecurity:SecretKey"),
                                                          order.Id.ToString(), order.MerchantCode, order.Id.ToString(), order.TransAmount.ToString());
                    if (orderVerify.check_sum == checkSum)
                    {
                        orderVerify.error_code   = "00";
                        orderVerify.trans_amount = order.TransAmount;

                        logger.Info("Investment with ViettelPay | Verify Data: error_code: 00");

                        order.IsVerify = true;
                        await _orderService.UpdateOrder(order);

                        return(Json(orderVerify));
                    }
                }

                orderVerify.error_code = "02";
                logger.Info("Investment with ViettelPay | Verify Data: error_code: 02");
                return(Json(orderVerify));
            }
            catch (Exception)
            {
                orderVerify.error_code = "03";
                logger.Info("Investment with ViettelPay | Verify Data: error_code: 03");
                return(Json(orderVerify));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Invest()
        {
            if (!_userService.IsSignedIn(User))
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

            if (config.Contains("true"))
            {
                return(View("~/Views/Lock.cshtml"));
            }

            var currentUser = await _userService.GetCurrentUser();

            if (currentUser.KVRR == null)
            {
                return(RedirectToAction(nameof(AccountController.MyPortfolio), "Account"));
            }

            return(View());
        }
        public async Task <IActionResult> New()
        {
            if (!_userService.IsSignedIn(User))
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

            if (config.Contains("true"))
            {
                return(View("~/Views/Lock.cshtml"));
            }

            var currentUser = await _userService.GetCurrentUser();

            var model = new InvestmentTargetModel()
            {
                Duration = Common.Duration.TwelfthMonth, Frequency = Common.Frequency.OneWeek, User = currentUser
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task CheckOrderRequestPendingTask()
        {
            try
            {
                var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

                if (config.Contains("true"))
                {
                    return;
                }
                var listorder = await _orderRequestService.GetAllOrderRequestByStatus(OrderRequestStatus.Pending);

                if (listorder != null && listorder.Count > 0)
                {
                    var viettelPayApi   = _configuration.GetValue <bool>("RequestPaymentLink:IsLive") ? _configuration.GetValue <string>("RequestPaymentLink:Live") : _configuration.GetValue <string>("RequestPaymentLink:Test");
                    var cmd             = _configuration.GetValue <string>("RequestPaymentParam:cmdCheckOrderRequest");
                    var rsaPublicKey    = _configuration.GetValue <string>("RSAKey:public");
                    var rsaPrivateKey   = _configuration.GetValue <string>("RSAKey:private");
                    var rsaPublicKeyVTP = _configuration.GetValue <string>("RSAKey:VTPpublic");

                    var rsa             = new RSAHelper(RSAType.RSA, Encoding.UTF8, "", rsaPublicKeyVTP);
                    var passwordEncrypt = rsa.Encrypt(_configuration.GetValue <string>("RequestPaymentParam:password"));
                    var logger          = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
                    logger.Info("Check Order Request Job : Start ");
                    foreach (var orderRequest in listorder)
                    {
                        if (orderRequest.Amount > 0)
                        {
                            logger.Info("Check Order Request Job : orderRequestId = " + orderRequest.Id);

                            SoapDataCheckOrderRequest request = new SoapDataCheckOrderRequest()
                            {
                                username    = _configuration.GetValue <string>("RequestPaymentParam:username"),
                                password    = passwordEncrypt,
                                serviceCode = _configuration.GetValue <string>("RequestPaymentParam:serviceCode"),
                                orderId     = orderRequest.Id.ToString()
                            };
                            var response = await _viettelPay.CheckOrderRequest(viettelPayApi, cmd, rsaPublicKey, rsaPrivateKey, rsaPublicKeyVTP, request);

                            if (response != null)
                            {
                                logger.Info("Check Order Request Job : orderRequestId = " + orderRequest.Id + " batchErrorCode : " + response);
                                if (response == "DISB_SUCCESS")
                                {
                                    orderRequest.Status = OrderRequestStatus.Success;
                                    await _orderRequestService.UpdateOrder(orderRequest);
                                }
                                else if (response == "DISB_FAILED" || response == "DISB_TIMEOUT" || response == "CANCEL_DISB")
                                {
                                    orderRequest.Status = OrderRequestStatus.Failure;
                                    await _orderRequestService.UpdateOrder(orderRequest);

                                    await _fundTransactionHistoryService.WithdrawRollback(orderRequest.Amount, orderRequest.PhoneNumber);
                                }
                            }
                            else
                            {
                                logger.Info("Check Order Request Job : orderRequestId = " + orderRequest.Id + " ErrorCode != 0 ");
                                orderRequest.Status = OrderRequestStatus.Failure;
                                await _orderRequestService.UpdateOrder(orderRequest);

                                await _fundTransactionHistoryService.WithdrawRollback(orderRequest.Amount, orderRequest.PhoneNumber);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException("Check Order Request Error: " + e.Message);
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> KVRRRecommendation(int questionGroup, int totalScore)
        {
            if (!_userService.IsSignedIn(User))
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

            if (config.Contains("true"))
            {
                return(View("~/Views/Lock.cshtml"));
            }

            var currentUser = await _userService.GetCurrentUser();

            UserModel model = new UserModel();

            model = await _userService.GetUserRelateData();

            var kvrrs = await _kvrrService.GetAllKVRR();

            var kvrrModel = new KVRRModel()
            {
                Id = 0
            };

            if (currentUser.KVRR != null)
            {
                model.KVRR = new KVRRModel()
                {
                    Id = 0
                };
            }
            else
            {
                if (questionGroup == 1)
                {
                    if (totalScore <= 9)
                    {
                        kvrrModel = kvrrs?.Where(i => i.Name == "An toàn")?.FirstOrDefault();
                    }
                    else
                    {
                        kvrrModel = kvrrs?.Where(i => i.Name == "Cẩn trọng")?.FirstOrDefault();
                    }
                }
                else
                {
                    if (totalScore <= 8)
                    {
                        kvrrModel = kvrrs?.Where(i => i.Name == "Cân bằng")?.FirstOrDefault();
                    }
                    else if (totalScore > 11)
                    {
                        kvrrModel = kvrrs?.Where(i => i.Name == "Đầu cơ")?.FirstOrDefault();
                    }
                    else
                    {
                        kvrrModel = kvrrs?.Where(i => i.Name == "Mạo hiểm")?.FirstOrDefault();
                    }
                }

                model.KVRR = kvrrModel;
            }

            if (currentUser.KVRR != null)
            {
                model.KVRROthers = kvrrs?.Where(x => model.KVRR != null && x.Id != model.KVRR.Id && x.Id != currentUser.KVRR.Id)?.ToList() ?? throw new NotFoundException();
            }
            else
            {
                model.KVRROthers = kvrrs?.Where(x => model.KVRR != null && x.Id != model.KVRR.Id)?.ToList() ?? throw new NotFoundException();
            }

            return(View(model));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Withdrawal()
        {
            if (!_userService.IsSignedIn(User))
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked);

            if (config.Contains("true"))
            {
                return(View("~/Views/Lock.cshtml"));
            }

            var currentUser = await _userService.GetCurrentUser();

            //Lock if user is withdrawing in another machine

            if (WithdrawalProcessingUsers.ContainsKey(currentUser.UserName) && WithdrawalProcessingUsers[currentUser.UserName])
            {
                ViewBag.Error = ValidationMessages.WithdrawalError;
                return(View());
            }


            if (!_configuration.GetValue <bool>("PaymentSecurity:DisableVTP"))
            {
                var newOrder = new OrderRequestModel()
                {
                    PhoneNumber = "84" + currentUser.PhoneNumber.Remove(0, 1),
                    FullName    = currentUser.FullName
                };
                var order = await _orderRequestService.SaveOrder(newOrder);

                var viettelPayApi   = _configuration.GetValue <bool>("RequestPaymentLink:IsLive") ? _configuration.GetValue <string>("RequestPaymentLink:Live") : _configuration.GetValue <string>("RequestPaymentLink:Test");
                var cmd             = _configuration.GetValue <string>("RequestPaymentParam:cmdCheckAccount");
                var rsaPublicKey    = _configuration.GetValue <string>("RSAKey:public");
                var rsaPrivateKey   = _configuration.GetValue <string>("RSAKey:private");
                var rsaPublicKeyVTP = _configuration.GetValue <string>("RSAKey:VTPpublic");

                var rsa             = new RSAHelper(RSAType.RSA, Encoding.UTF8, "", rsaPublicKeyVTP);
                var passwordEncrypt = rsa.Encrypt(_configuration.GetValue <string>("RequestPaymentParam:password"));

                var dataCheckAccount = new DataCheckAccount()
                {
                    msisdn       = "84" + currentUser.PhoneNumber.Remove(0, 1),
                    customerName = currentUser.FullName
                };

                var soapDataCheckAccount = new SoapDataCheckAccount()
                {
                    username    = _configuration.GetValue <string>("RequestPaymentParam:username"),
                    password    = passwordEncrypt,
                    serviceCode = _configuration.GetValue <string>("RequestPaymentParam:serviceCode"),
                    orderId     = order.Id.ToString()
                };

                var code = await _viettelPay.CheckAccount(viettelPayApi, cmd, rsaPublicKey, rsaPrivateKey, rsaPublicKeyVTP, dataCheckAccount, soapDataCheckAccount);

                if (!string.IsNullOrWhiteSpace(code) && code == "10")
                {
                    ViewBag.Error = ValidationMessages.VTPInvalidAccount;
                }
                else if (code != "00")
                {
                    ViewBag.Error = ValidationMessages.VTPError;
                }

                TempData["OrderId"] = order.Id.ToString();
            }
            return(View());
        }