Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateDealCustom(int objectID, string userID, decimal transactionAmount)
        {
            var user = await _userService.GetUserById(userID);

            var objectName = user.FullName;

            if (!_configuration.GetValue <bool>("PaymentSecurity:DisableVTP"))
            {
                var newOrder = new OrderRequestModel()
                {
                    PhoneNumber = "84" + user.PhoneNumber.Remove(0, 1),
                    FullName    = user.FullName,
                    Amount      = transactionAmount
                };
                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:cmdRequest");
                var cmdCheckAccount = _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, rsaPrivateKey, rsaPublicKeyVTP);
                var passwordEncrypt = rsa.Encrypt(_configuration.GetValue <string>("RequestPaymentParam:password"));

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

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

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

                if (!string.IsNullOrWhiteSpace(codeCheckAccount) && codeCheckAccount == "10")
                {
                    return(Json(new { success = false, message = ValidationMessages.VTPInvalidAccount2 }));
                }
                else if (codeCheckAccount != "00")
                {
                    return(Json(new { success = false, message = ValidationMessages.VTPError }));
                }

                var dataRequestPayment = new DataRequestPayment()
                {
                    msisdn       = "84" + user.PhoneNumber.Remove(0, 1),
                    customerName = user.FullName,
                    transId      = order.Id.ToString(),
                    amount       = transactionAmount.ToString("0"),
                    smsContent   = _configuration.GetValue <string>("RequestPaymentParam:smsContent"),
                    note         = "Rut tien tu Savenow"
                };

                var soapDataRequestPayment = new SoapDataRequestPayment()
                {
                    username     = _configuration.GetValue <string>("RequestPaymentParam:username"),
                    password     = passwordEncrypt,
                    serviceCode  = _configuration.GetValue <string>("RequestPaymentParam:serviceCode"),
                    orderId      = order.Id.ToString(),
                    totalTrans   = "1",
                    totalAmount  = transactionAmount.ToString("0"),
                    transContent = _configuration.GetValue <string>("RequestPaymentParam:smsContent")
                };

                var code = await _viettelPay.Request(viettelPayApi, cmd, rsaPublicKey, rsaPrivateKey, rsaPublicKeyVTP, dataRequestPayment, soapDataRequestPayment);

                if (!string.IsNullOrWhiteSpace(code) && code == "10")
                {
                    return(Json(new { success = false, message = ValidationMessages.VTPInvalidAccount }));
                }
                else if (code != "00")
                {
                    return(Json(new { success = false, message = ValidationMessages.VTPError }));
                }
            }

            await _transactionHistoryService.UpdateStatusTransactionHistory(objectID, TransactionStatus.Success);

            await _taskCompletedService.SaveTaskCompleted(new TaskCompletedModel()
            {
                ObjectID = objectID, ObjectName = objectName, TaskType = TaskTypeAccountant.DealCustomer, TransactionAmount = transactionAmount
            });

            return(Json(new { success = true }));
        }