// GET: Authorization
        public ActionResult Index(DataForAuthorization data)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:4074/api/Authorization");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <DataForAuthorization>("http://localhost:4074/api/Authorization/Authorize", data);
                postTask.Wait();

                var readTask = postTask.Result.Content.ReadAsStringAsync();
                readTask.Wait();


                string ResponseValue = readTask.Result;

                var    responseData = (JObject)JsonConvert.DeserializeObject(ResponseValue);
                string status       = responseData["status"].Value <string>();
                string message      = responseData["message"].Value <string>();


                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    ViewBag.Status  = status;
                    ViewBag.Messgae = message;
                    //return RedirectToAction("Index", new { token = tokenValue });
                    //return RedirectToAction("ShowToken", verify);
                }
            }

            ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");

            return(View(data));
        }
Exemplo n.º 2
0
        //private string RegenerateHash(/*string cust_name,*/ long card_num, int cvv, string salt)
        private string RegenerateToken(DataForAuthorization dataForAuthorization)
        {
            #region Instruction to follow
            //first decrypt token then match CustomerFirstName, CarNumber,CVV_Code from data if match true else false

            //token expiry implement as ui by fahad
            #endregion
            string Customerdetails = dataForAuthorization.CustomerFirstName + "," + dataForAuthorization.CarNumber + "," + dataForAuthorization.CVV_Code;
            string encryptedstring = StringCipher.Encrypt(Customerdetails, dataForAuthorization.Salt);

            return(encryptedstring);
        }
        public ActionResult ConfirmPayment(int _customer_id, int _token_id, int _amount)
        {
            IdandAmount data = new IdandAmount
            {
                customer_id = _customer_id,
                token_id    = _token_id,
                amount      = _amount
            };

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:4074/api/PaymentAuthentication");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <IdandAmount>("http://localhost:4074/api/PaymentAuthentication/PostDetailsForAuthentication", data);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    using (var query = new MonetaEntities())
                    {
                        var _tokenCode = query.TokenDetails
                                         .Where(t => t.CustomerID == _customer_id && t.TokenID == _token_id)
                                         .Select(i => i.TokenCode).FirstOrDefault();

                        int _payment_id = query.PaymentDetails
                                          .Where(t => t.CustomerID == _customer_id && t.TokenID == _token_id)
                                          .Select(i => i.PaymentId).FirstOrDefault();

                        string _email = query.CustomerDetails
                                        .Where(t => t.CustomerID == _customer_id)
                                        .Select(i => i.Email).FirstOrDefault();

                        DataForAuthorization paramsData = new DataForAuthorization
                        {
                            customerId = _customer_id,
                            tokenCode  = _tokenCode
                        };

                        //return RedirectToAction("Index", "Authorization", paramsData);
                        return(RedirectToAction("Index", "CustomerApproval", new { customer_id_ = _customer_id, payment_id_ = _payment_id, email = _email }));
                    }
                }
            }

            ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");

            return(View(data));
        }
Exemplo n.º 4
0
        public IHttpActionResult CheckTokenStatusWithPending(int customerId)
        {
            //pending transaction into list
            var dataAuthorization = new DataForAuthorization();
            IList <StatusModel> _statusModel;


            using (var query = new MonetaEntities())
            {
                _statusModel = query.PaymentDetails
                               .Where(p => p.status == "pending" && p.CustomerID == customerId)
                               .Select(x => new StatusModel()
                {
                    tokenId    = x.TokenID,
                    customerId = x.CustomerID,
                    paymentId  = x.PaymentId,
                    status     = x.status
                }).ToList <StatusModel>();
            }

            foreach (var fetch in _statusModel)
            {
                dataAuthorization.customerId = Convert.ToInt32(fetch.customerId.Value);
                dataAuthorization.paymentId  = fetch.paymentId.Value;
                dataAuthorization.tokenId    = fetch.tokenId.Value;
                dataAuthorization.paymentId  = fetch.paymentId.Value;
                // Authorize(dataAuthorization);

                //ApprovedStatus(fetch);

                Authorize(dataAuthorization);
            }

            if (_statusModel.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(_statusModel));
        }
Exemplo n.º 5
0
        //public IHttpActionResult Authorize(int customerId, string tokenCode, DateTime tokentime) //POST
        public IHttpActionResult Authorize(DataForAuthorization data) //POST
        {
            DateTime d2 = DateTime.Now;
            string   _clientSideTime = d2.ToString("hh:mm tt");

            //int customerId = data["customerId"].ToObject<int>();
            //string tokenCode = data["tokenCode"].ToObject<string>();
            //DateTime tokentime = data["tokentime"].ToObject<DateTime>();

            int    customerId = data.customerId;
            string tokenCode  = data.tokenCode;

            //DateTime tokentime = data.tokentime;

            using (var query = new MonetaEntities())
            {
                var customer_id = query.TokenDetails
                                  .Where(t => t.CustomerID == customerId && t.TokenCode == tokenCode)
                                  .Select(i => i.CustomerID).FirstOrDefault();

                var token = query.TokenDetails
                            .Where(t => t.CustomerID == customerId && t.TokenCode == tokenCode)
                            .Select(i => i.TokenCode).FirstOrDefault();

                var DbTokentime = query.TokenDetails
                                  .Where(t => t.CustomerID == customerId && t.TokenCode == tokenCode)
                                  .Select(i => i.Date).FirstOrDefault();

                DateTime d1 = Convert.ToDateTime(DbTokentime);
                string   _tokenCreatedTime = d1.ToString("hh:mm tt");



                DateTime tokenCreatedTime = Convert.ToDateTime(_tokenCreatedTime);
                DateTime clientSideTime   = Convert.ToDateTime(_clientSideTime);

                double TimeDifference = tokenCreatedTime.Subtract(clientSideTime).TotalMinutes * -1;


                if (customer_id == Convert.ToInt32(customerId) && token == Convert.ToString(tokenCode) && TimeDifference < 15)
                {
                    var response = new
                    {
                        status  = "Authorized",
                        message = "Payment has been Authorized!"
                    };

                    return(Json(response));
                }

                else if (customer_id == Convert.ToInt32(customerId) && token == Convert.ToString(tokenCode) && TimeDifference > 15)
                {
                    var response = new
                    {
                        status  = "Unauthorized",
                        message = "Your Token has expired!"
                    };

                    return(Json(response));
                }
            }

            return(Ok());
        }
Exemplo n.º 6
0
        public bool RegHash(DataForAuthorization data)
        {
            using (var query = new MonetaEntities())
            {
                //regSalt = query.CustomerDetails.Join(
                //    query.TokenDetails,
                //    cust => cust.CustomerID,
                //    token => token.CustomerID,
                //    (cust, token) => new RegSaltModel()
                //    {
                //        CutomerId = cust.CustomerID,
                //        CardNumber = cust.CardNumber,
                //        Salt = cust.Salt,
                //        CVV_Code = cust.CVV_Code,
                //        CustomerFirstName = cust.FirstName,
                //        TokenCode = token.TokenCode
                //    }).Where(p=>p.CutomerId == ).ToList<RegSaltModel>();

                IList <RegSaltModel> regSalt = new List <RegSaltModel>();
                regSalt = (from cust in query.CustomerDetails
                           join token in query.TokenDetails on cust.CustomerID equals token.CustomerID
                           where cust.CustomerID == data.customerId
                           select new RegSaltModel()
                {
                    CutomerId = cust.CustomerID,
                    CardNumber = cust.CardNumber,
                    Salt = cust.Salt,
                    CVV_Code = cust.CVV_Code,
                    CustomerFirstName = cust.FirstName,
                    TokenCode = token.TokenCode
                }).ToList <RegSaltModel>();

                int payment_id = query.PaymentDetails
                                 .Where(x => x.CustomerID == data.customerId)
                                 .Select(p => p.PaymentId).FirstOrDefault();



                DataForAuthorization dataForAuthorization = new DataForAuthorization();
                //  RegenerateHash()
                foreach (var fetch_regSalt in regSalt)
                {
                    dataForAuthorization.customerId        = fetch_regSalt.CutomerId;
                    dataForAuthorization.CarNumber         = Convert.ToInt64(fetch_regSalt.CardNumber);
                    dataForAuthorization.Salt              = fetch_regSalt.Salt;
                    dataForAuthorization.CustomerFirstName = fetch_regSalt.CustomerFirstName;
                    dataForAuthorization.tokenCode         = fetch_regSalt.TokenCode;
                    dataForAuthorization.CVV_Code          = fetch_regSalt.CVV_Code;
                    dataForAuthorization.paymentId         = payment_id;
                }
                StatusModel statusModel = new StatusModel();
                statusModel.customerId = dataForAuthorization.customerId;
                statusModel.paymentId  = payment_id;
                int id = dataForAuthorization.customerId;


                string name = string.Empty, cvv, cardNumber;

                using (var query3 = new MonetaEntities())
                {
                    string _salt = query3.CustomerDetails
                                   .Where(x => x.CustomerID == data.customerId)
                                   .Select(x => x.Salt).FirstOrDefault();

                    string _hash = query3.TokenDetails
                                   .Where(x => x.CustomerID == data.customerId)
                                   .Select(x => x.TokenCode).FirstOrDefault();

                    DecrpytandSplitToken(_hash, _salt, out name, out cardNumber, out cvv);
                }

                if (name == data.CustomerFirstName && cardNumber == data.CarNumber.ToString() && cvv == data.CVV_Code.ToString())
                {
                    Authorize(dataForAuthorization);
                    ApprovedStatus(statusModel);
                    return(true);
                }
                else
                {
                    Authorize(dataForAuthorization);
                    RejectedStatus(statusModel);
                    return(false);
                }
            }
        }