Beispiel #1
0
        private string GetSoapDataCheckAccount(DataCheckAccount dataCheckAccount, SoapDataCheckAccount soapDataCheckAccount, string privateKey, string publicKey, out string sign)
        {
            var list = new List <DataCheckAccount>();

            list.Add(dataCheckAccount);

            var dataCheckAccountJson     = JsonConvert.SerializeObject(list);
            var dataCheckAccountJsonGzip = StringHelper.GzipBase64(dataCheckAccountJson);

            soapDataCheckAccount.data = dataCheckAccountJsonGzip;
            var soapDataCheckAccountJson = JsonConvert.SerializeObject(soapDataCheckAccount);

            var rsa = new RSAHelper(RSAType.RSA, Encoding.UTF8, privateKey, publicKey);

            sign = rsa.Sign(soapDataCheckAccountJson);

            return(soapDataCheckAccountJson);
        }
Beispiel #2
0
        public async Task <string> CheckAccount(string apiURL, string cmd, string rsaPublicKey, string rsaPrivateKey, string rsaPublicKeyVTP, DataCheckAccount dataCheckAccount, SoapDataCheckAccount soapDataCheckAccount)
        {
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"" + apiURL + "");
                webRequest.ContentType = "text/xml;charset=UTF-8;action=\"SOAP:Action\"";
                webRequest.Method      = "POST";
                webRequest.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

                var         sign            = string.Empty;
                var         data            = GetSoapDataCheckAccount(dataCheckAccount, soapDataCheckAccount, rsaPrivateKey, rsaPublicKey, out sign);
                XmlDocument soapEnvelopeXml = CreateSoapEnvelope(cmd, data, sign);

                using (Stream stream = webRequest.GetRequestStream())
                {
                    soapEnvelopeXml.Save(stream);
                }

                using (WebResponse response = webRequest.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        string soapResult = await rd.ReadToEndAsync();

                        var     xDoc             = XDocument.Parse(soapResult);
                        var     resultReturn     = xDoc.Descendants("return").Single().Value;
                        dynamic resultReturnJson = JObject.Parse(resultReturn);
                        var     soapData         = resultReturnJson.data.ToString();
                        var     soapSign         = resultReturnJson.signature.ToString();

                        var     rsa             = new RSAHelper(RSAType.RSA, Encoding.UTF8, "", rsaPublicKeyVTP);
                        var     soapDataReplace = soapData.Replace("  \"", "\"").Replace(" \"", "\"").Replace("\r", "").Replace("\n", "");
                        var     verifySign      = rsa.Verify(soapDataReplace, soapSign);
                        dynamic soapDataJson    = JObject.Parse(soapData);
                        var     dataZip         = soapDataJson.data.ToString();
                        var     dataUnzip       = StringHelper.UnzipBase64(dataZip);

                        if (!verifySign)
                        {
                            var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
                            logger.Error("ViettelPay Check Account Error: Code: " + soapDataJson.errorCode?.ToString() + ", Message: " + soapDataJson.errorMsg?.ToString() + ", Verify Sign: False");

                            return(string.Empty);
                        }

                        if (soapDataJson.errorCode.ToString() != "00")
                        {
                            var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
                            logger.Error("ViettelPay Check Account Error: Code: " + soapDataJson.errorCode?.ToString() + ", Message: " + soapDataJson.errorMsg?.ToString());
                        }

                        return(soapDataJson.errorCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("ViettelPay Check Account Error: " + ex.Message);
            }
        }
        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());
        }
Beispiel #4
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 }));
        }