Пример #1
0
        public object[] Installment(int merchant, int year, int month, int day)
        {
            object[] data = null;

            using (var db = new Entities())
            {
                ObjectResult<Pay_TransactionChartInstallment_Result> listDashboard = db.Pay_TransactionChartInstallment(merchant, year, month, day);

                List<Pay_TransactionChartInstallment_Result> listDashboardChart = listDashboard.ToList();

                if (listDashboardChart != null)
                {
                    var chartData = new object[listDashboardChart.Count() + 1];
                    chartData[0] = new object[]
                    {
                        "Installment",
                        "Value",
                        "Amount",
                        "Currency"
                    };
                    int j = 0;
                    foreach (var i in listDashboardChart)
                    {
                        j++;
                        chartData[j] = new object[] { i.installment, i.value, i.amount, string.Concat("R$ ", i.value.Value.ToString("0.00")) };
                    }
                    data = chartData;
                }
            }

            return data;
        }
Пример #2
0
        public object[] CardBrand(int merchant, int year, int month, int day)
        {
            object[] data = null;

            using (var db = new Entities())
            {
                ObjectResult<Pay_TransactionChartCardBrand_Result> listDashboard = db.Pay_TransactionChartCardBrand(merchant, year, month, day);

                List<Pay_TransactionChartCardBrand_Result> listDashboardChart = listDashboard.ToList();

                if (listDashboardChart != null)
                {
                    var chartData = new object[listDashboardChart.Count() + 1];
                    chartData[0] = new object[]
                    {
                        "CardBrand",
                        "Value",
                        "Amount",
                        "Currency"
                    };
                    int j = 0;
                    foreach (var i in listDashboardChart)
                    {
                        j++;
                        chartData[j] = new object[] { Business.Description.getCardBrand((Business.Enums.CardBrand)int.Parse(i.cardBrand)), i.value.Value, i.amount.Value, string.Concat("R$ ", i.value.Value.ToString("0.00")) };
                    }
                    data = chartData;
                }
            }

            return data;
        }
Пример #3
0
        public Notification(Sys_User participant, Entities db)
        {
            helper = new EmailHelper();
            _db = db;

            Log = new Sys_WebmailLog
            {
                Sys_User = participant,
                dtCreatedAt = DateTime.Now,
                flStatus = true,
                flSent = false
            };
        }
Пример #4
0
        public static void Write(string session, int user, int system)
        {
            using (var db = new Entities())
            {
                Sys_UserSession userSession = db.Sys_UserSession.Find(user, system);

                if (userSession != null)
                {
                    userSession.dsSession = session;
                    userSession.dtLastUpdate = DateTime.Now;
                    db.Entry(userSession).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    userSession = new Sys_UserSession();

                    userSession.idUser = user;
                    userSession.idSystem = system;

                    userSession.dsSession = session;

                    userSession.idUserLastUpdate = user;

                    userSession.dtCreate = DateTime.Now;
                    userSession.dtLastUpdate = DateTime.Now;

                    userSession.flStatus = "A";

                    db.Entry(userSession).State = EntityState.Added;
                    db.SaveChanges();
                }

                Sys_User sysUser = db.Sys_User.Find(user);
                sysUser.dsSession = session;
                db.Entry(sysUser).State = EntityState.Modified;

                db.SaveChanges();
            }
        }
Пример #5
0
        public Login(int id, int idRole, int idPerson, int idEnterprise, int idMerchant, int idSystem, string name, string email, string session)
        {
            this.@return = true;
            this.id = id;
            this.idRole = idRole;
            this.idPerson = idPerson;
            this.idEnterprise = idEnterprise;
            this.idMerchant = idMerchant;
            this.name = name;
            this.email = email;
            this.session = session;

            using (var db = new Entities())
            {
                Sys_System sysSystem = db.Sys_System.Where(c => c.idSystem == idSystem).SingleOrDefault();

                if (sysSystem != null)
                {
                    system = new System(sysSystem);

                    Sys_Merchant sysMerchant = db.Sys_Merchant.Where(c => c.idMerchant == idMerchant).SingleOrDefault();

                    if (sysMerchant != null)
                    {
                        merchant = new Merchant(sysMerchant);

                        posList = new List<POS>();

                        foreach (Sys_MerchantPinPad merchantPinPad in db.Sys_MerchantPinPad.Where(c => c.idMerchant == idMerchant && c.flStatus.Equals("A")).ToList())
                        {
                            posList.Add(new POS(db.Pos_PinPad.Where(c => c.idPinPad == merchantPinPad.idPinpad).SingleOrDefault()));
                        }
                    }
                }
            }
        }
Пример #6
0
        public Response getLogin(string accessToken, string email,string jsonParams)
        {
            Response response = null;

            using (var db = new Entities())
            {
                if (!string.IsNullOrEmpty(email) && ValidaEmail(email))
                {
                    if (!string.IsNullOrEmpty(accessToken) && TokenController.IsValidToken(accessToken, email))
                    {
                        dynamic myObj;
                        try
                        {
                            myObj = JsonConvert.DeserializeObject(jsonParams);

                            string password = null;

                            int idSystem = -1;
                            string ipAddress = null;
                            string dsAgent = null;

                            if (myObj.password != null)
                                password = myObj.password; //required

                            if (myObj.system != null)
                                idSystem = myObj.system; //required

                            if (myObj.ipAddress != null)
                                ipAddress = myObj.ipAddress; //required

                            if (myObj.userAgent != null)
                                dsAgent = myObj.userAgent; //required

                            if (!string.IsNullOrEmpty(password))
                            {
                                string newSession = SessionController.New(email);

                                ObjectResult<Sys_UserLogin_Result> listUser = db.Sys_UserLogin(email, PasswordEncrypt(password), idSystem, ipAddress, dsAgent, accessToken, newSession);

                                List<Sys_UserLogin_Result> listUserLogin = listUser.ToList();

                                if (listUserLogin != null && listUserLogin.Count > 0)
                                {
                                    int idUser = -1;
                                    int idRole = -1;
                                    int idPerson = -1;
                                    int idEnterprise = -1;
                                    int idMerchant = -1;
                                    int idUserCreate = -1;
                                    int idUserUpdate = -1;

                                    DateTime expire_at = DateTime.MinValue;
                                    DateTime create_at = DateTime.MinValue;
                                    DateTime update_at = DateTime.MinValue;

                                    string session = string.Empty;
                                    string nmUser = string.Empty;
                                    string stUser = string.Empty;
                                    string dsEmail = string.Empty;

                                    idUser = (int)listUserLogin[0].idUser;

                                    if (listUserLogin[0].idRole != null)
                                        idRole = (int)listUserLogin[0].idRole;

                                    if (listUserLogin[0].idPerson != null)
                                        idPerson = (int)listUserLogin[0].idPerson;

                                    if (listUserLogin[0].idEnterprise != null)
                                        idEnterprise = (int)listUserLogin[0].idEnterprise;

                                    if (listUserLogin[0].idMerchant != null)
                                        idMerchant = (int)listUserLogin[0].idMerchant;

                                    if (listUserLogin[0].idUserCreate != null)
                                        idUserCreate = (int)listUserLogin[0].idUserCreate;

                                    if (listUserLogin[0].idUserLastUpdate != null)
                                        idUserUpdate = (int)listUserLogin[0].idUserLastUpdate;

                                    nmUser = (string)listUserLogin[0].nmUser;
                                    dsEmail = (string)listUserLogin[0].dsEmail;
                                    stUser = (string)listUserLogin[0].stUser;
                                    session = newSession;

                                    SessionController.Write(newSession, idUser, idSystem);

                                    if (listUserLogin[0].dtExpire != null)
                                        expire_at = (DateTime)listUserLogin[0].dtExpire;

                                    if (listUserLogin[0].dtCreate != null)
                                        create_at = (DateTime)listUserLogin[0].dtCreate;

                                    if (listUserLogin[0].dtLastUpdate != null)
                                        update_at = (DateTime)listUserLogin[0].dtLastUpdate;

                                    if (idUser > 0 && expire_at > DateTime.Now)
                                    {
                                        response = new Login(idUser, idRole, idPerson, idEnterprise, idMerchant, idSystem, nmUser, dsEmail, session);
                                    }
                                    else if (idUser == -1)/*Invalid Email*/
                                    {
                                        response = new ResponseFailure("invalid-login");
                                    }
                                    else if (idUser == -2)/*Invalid password*/
                                    {
                                        response = new ResponseFailure("invalid-login");
                                    }
                                    else if (idUser == -3)/*Invalid previleges*/
                                    {
                                        response = new ResponseFailure("invalid-login");
                                    }
                                    else if (idUser == -4)/*Invalid Expire Date*/
                                    {
                                        response = new ResponseFailure("invalid-login");
                                    }
                                    else
                                    {
                                        response = new ResponseFailure("invalid-login");
                                    }
                                }
                                else
                                {
                                    response = new ResponseFailure("invalid-login");
                                }
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-login");
                            }
                        }
                        catch (Exception ex)
                        {
                            response = new ResponseFailure(ex.Message);
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-token");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }
            }

            return response;
        }
Пример #7
0
        public JsonResult generateNewSession(string session, string email, int system)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email) && ValidaEmail(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            Sys_UserSession sysSession = participant.Sys_UserSession.Where(s => s.idUser == participant.idUser && s.idSystem == system).FirstOrDefault();

                            if (active_session <= 60 && sysSession.dsSession.Equals(session))
                            {
                                string newSession = SessionController.New(email);
                                SessionController.Write(newSession, participant.idUser, system);

                                response = new Login(participant.idUser, participant.idRole.Value, participant.idPerson.Value, participant.idPerson.Value, participant.idMerchant.Value, system, participant.nmUser, email, newSession);
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #8
0
        public JsonResult generateNewPassword(string accessToken, string email)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email) && ValidaEmail(email))
                {
                    if (!string.IsNullOrEmpty(accessToken) && TokenController.IsValidToken(accessToken, email))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            var passwd = NewPassword();
                            var encrypted = PasswordEncrypt(passwd);
                            participant.dsPassword = encrypted;

                            db.Entry(participant).State = EntityState.Modified;
                            db.SaveChanges();

                            //var notifier = new Notification(participant, db);
                            // //NOTIFICAR {MUDANÇA DE SENHA}
                            //notifier.NotifyPasswordChange(encrypted, passwd);

                            response = new NewPassword(participant.idUser, participant.nmUser, (participant.idRole.HasValue ? participant.idRole.Value : -1), participant.dsEmail);
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-Email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-token");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-Email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #9
0
        public JsonResult Update(string session, string email, int merchant, int system)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            if (active_session <= 60 && participant.dsSession.Equals(session))
                            {
                                Stream req = Request.InputStream;
                                req.Seek(0, System.IO.SeekOrigin.Begin);
                                string json = new StreamReader(req).ReadToEnd();

                                dynamic myObj;
                                try
                                {
                                    myObj = JsonConvert.DeserializeObject(json);

                                    string newSession = SessionController.New(email);
                                    SessionController.Write(newSession, participant.idUser, system);

                                    if (myObj.id != null & myObj.id > 0)
                                    {
                                        Pay_Transaction payTransaction = null;
                                        long idMobile = myObj.id;
                                        Guid idServer = Guid.Empty;
                                        string strIdServer = null;

                                        if (myObj.idServer != null)
                                            strIdServer = myObj.idServer;

                                        if (!string.IsNullOrEmpty(strIdServer) && Guid.TryParse(strIdServer, out idServer))
                                        {
                                            payTransaction = db.Pay_Transaction.Where(z => z.idTransaction == idServer).FirstOrDefault();
                                        }
                                        else
                                        {
                                            payTransaction = db.Pay_Transaction.Where(z => z.idMobile == idMobile).FirstOrDefault();
                                        }

                                        if (payTransaction != null)
                                        {
                                            if (myObj.token != null && !((string)myObj.token).Equals("null"))
                                                payTransaction.token = myObj.token;
                                            if (myObj.serial_number != null && !((string)myObj.serial_number).Equals("null"))
                                                payTransaction.pinpadSerialNumber = myObj.serial_number;

                                            //if (myObj.techonology != null)

                                            if (myObj.type != null)
                                                payTransaction.type = myObj.type;
                                            if (myObj.operation != null)
                                                payTransaction.operation = myObj.operation;
                                            if (myObj.state != null)
                                                payTransaction.state = myObj.state;

                                            if (myObj.fiscalDate != null && !((string)myObj.fiscalDate).Equals("null"))
                                                payTransaction.fiscalDate = myObj.fiscalDate;
                                            if (myObj.fiscalHour != null && !((string)myObj.fiscalHour).Equals("null"))
                                                payTransaction.fiscalHour = myObj.fiscalHour;

                                            if (myObj.cs_pinpad_info != null && !((string)myObj.cs_pinpad_info).Equals("null"))
                                                payTransaction.pinpadInfo = myObj.cs_pinpad_info;
                                            if (myObj.value != null && !((string)myObj.value).Equals("null"))
                                                payTransaction.value = myObj.value;
                                            if (myObj.status != null)
                                                payTransaction.statusCode = myObj.status;

                                            //if (myObj.message != null && !((string)myObj.message).Equals("null"))
                                            //payTransaction.statusMessage = myObj.message;

                                            if (myObj.type != null)
                                                payTransaction.type = myObj.type;
                                            if (myObj.creditcard != null && !((string)myObj.creditcard).Equals("null"))
                                                payTransaction.cardBIN = myObj.creditcard;
                                            if (myObj.card_brand != null && !((string)myObj.card_brand).Equals("null"))
                                                payTransaction.cardBrand = myObj.card_brand;
                                            if (myObj.card_type != null && !((string)myObj.card_type).Equals("null"))
                                                payTransaction.cardType = myObj.card_type;
                                            if (myObj.installments != null && !((string)myObj.installments).Equals("null"))
                                                payTransaction.installmentAmount = myObj.installments;
                                            if (myObj.nsu != null && !((string)myObj.nsu).Equals("null"))
                                                payTransaction.acquirerNSU = myObj.nsu;
                                            if (myObj.auth_code != null && !((string)myObj.auth_code).Equals("null"))
                                                payTransaction.authorizationNumber = myObj.auth_code;
                                            if (myObj.return_code != null && !((string)myObj.return_code).Equals("null"))
                                                payTransaction.acquirerResponseCode = myObj.return_code;
                                            if (myObj.cs_payment_type != null && !((string)myObj.cs_payment_type).Equals("null"))
                                                payTransaction.paymentType = myObj.cs_payment_type;
                                            if (myObj.cs_payment_function != null && !((string)myObj.cs_payment_function).Equals("null"))
                                                payTransaction.paymentFunction = myObj.cs_payment_function;
                                            if (myObj.cs_payment_function_description != null && !((string)myObj.cs_payment_function_description).Equals("null"))
                                                payTransaction.paymentFunctionDescription = myObj.cs_payment_function_description;
                                            if (myObj.cs_card_brand_number != null && !((string)myObj.cs_card_brand_number).Equals("null"))
                                                payTransaction.cardBrandCode = myObj.cs_card_brand_number;
                                            if (myObj.cs_sitef_nsu != null && !((string)myObj.cs_sitef_nsu).Equals("null"))
                                                payTransaction.sitefNSU = myObj.cs_sitef_nsu;
                                            if (myObj.cs_sitef_request_number != null && !((string)myObj.cs_sitef_request_number).Equals("null"))
                                                payTransaction.clisitefRequestNumber = myObj.cs_sitef_request_number;
                                            if (myObj.cs_sitef_confirmation_data != null && !((string)myObj.cs_sitef_confirmation_data).Equals("null"))
                                                payTransaction.clisitefConfirmationData = myObj.cs_sitef_confirmation_data;
                                            if (myObj.cs_sitef_refund_date != null && !((string)myObj.cs_sitef_refund_date).Equals("null"))
                                                payTransaction.refundDate = myObj.cs_sitef_refund_date;
                                            if (myObj.cs_sitef_refund_number != null && !((string)myObj.cs_sitef_refund_number).Equals("null"))
                                                payTransaction.refundDocumentNumber = myObj.cs_sitef_refund_number;
                                            if (myObj.cs_pinpad_info != null && !((string)myObj.cs_pinpad_info).Equals("null"))
                                                payTransaction.pinpadInfo = myObj.cs_pinpad_info;
                                            if (myObj.cs_sitef_version != null && !((string)myObj.cs_sitef_version).Equals("null"))
                                                payTransaction.sitefVersion = myObj.cs_sitef_version;
                                            if (myObj.cs_merchant_installments_allowed != null && !((string)myObj.cs_merchant_installments_allowed).Equals("null"))
                                                payTransaction.merchantInstallmentAllowed = myObj.cs_merchant_installments_allowed;
                                            if (myObj.cs_issuer_installments_allowed != null && !((string)myObj.cs_issuer_installments_allowed).Equals("null"))
                                                payTransaction.issuerInstallmentAllowed = myObj.cs_issuer_installments_allowed;
                                            if (myObj.cs_max_merchant_installments != null && !((string)myObj.cs_max_merchant_installments).Equals("null"))
                                                payTransaction.maxMerchantInstallments = myObj.cs_max_merchant_installments;
                                            if (myObj.cs_max_issuer_installments != null && !((string)myObj.cs_max_issuer_installments).Equals("null"))
                                                payTransaction.maxIssuerInstallments = myObj.cs_max_issuer_installments;
                                            if (myObj.cs_customer_receipt != null && !((string)myObj.cs_customer_receipt).Equals("null"))
                                                payTransaction.customerReceipt = myObj.cs_customer_receipt;
                                            if (myObj.cs_merchant_receipt != null && !((string)myObj.cs_merchant_receipt).Equals("null"))
                                                payTransaction.merchantReceipt = myObj.cs_merchant_receipt;

                                            if (myObj.flStatus != null && !((string)myObj.flStatus).Equals("null"))
                                                payTransaction.flStatus = myObj.flStatus;

                                            payTransaction.dtLastUpdate = DateTime.Now;

                                            db.Entry(payTransaction).State = EntityState.Modified;
                                            db.SaveChanges();

                                            response = new PayRequest(newSession, payTransaction);
                                        }
                                        else
                                        {
                                            response = new ResponseFailure("invalid-data");
                                        }
                                    }
                                    else
                                    {
                                        response = new ResponseFailure("invalid-data");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    response = new ResponseFailure("invalid-data");
                                }
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #10
0
        public JsonResult SendReceipt(string session, string email, int merchant, int system)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            if (active_session <= 60 && participant.dsSession.Equals(session))
                            {
                                Stream req = Request.InputStream;
                                req.Seek(0, System.IO.SeekOrigin.Begin);
                                string json = new StreamReader(req).ReadToEnd();

                                dynamic myObj;
                                try
                                {
                                    myObj = JsonConvert.DeserializeObject(json);

                                    string newSession = SessionController.New(email);
                                    SessionController.Write(newSession, participant.idUser, system);

                                    if (myObj.id != null & myObj.id > 0)
                                    {
                                        Pay_Transaction payTransaction = null;
                                        int idSystem = 0;
                                        bool isMerchantReceiptSend = false;
                                        bool isCustomerReceiptSend = false;
                                        bool isCustomerReceiptPhoneSend = false;

                                        long idMobile = myObj.id;
                                        Guid idServer = Guid.Empty;
                                        string strIdServer = null;

                                        if (myObj.idServer != null)
                                            strIdServer = myObj.idServer;

                                        if (!string.IsNullOrEmpty(strIdServer) && Guid.TryParse(strIdServer, out idServer))
                                        {
                                            payTransaction = db.Pay_Transaction.Where(z => z.idTransaction == idServer).FirstOrDefault();
                                        }
                                        else
                                        {
                                            payTransaction = db.Pay_Transaction.Where(z => z.idMobile == idMobile).FirstOrDefault();
                                        }

                                        if (myObj.idSystem != null)
                                            idSystem = myObj.idSystem;

                                        if (payTransaction != null)
                                        {
                                            if (myObj.cs_customer_receipt != null && !((string)myObj.cs_customer_receipt).Equals("null"))
                                            {
                                                payTransaction.customerReceipt = myObj.cs_customer_receipt;
                                            }
                                            if (myObj.cs_merchant_receipt != null && !((string)myObj.cs_merchant_receipt).Equals("null"))
                                            {
                                                payTransaction.merchantReceipt = myObj.cs_merchant_receipt;
                                                isMerchantReceiptSend = true;
                                            }
                                            if (myObj.cardholder_email != null && !((string)myObj.cardholder_email).Equals("null") && !((string)myObj.cardholder_email).Equals(""))
                                            {
                                                payTransaction.customerEmail = myObj.cardholder_email;
                                                isCustomerReceiptSend = true;
                                            }
                                            if (myObj.cardholder_phone != null && !((string)myObj.cardholder_phone).Equals("null") && !((string)myObj.cardholder_phone).Equals(""))
                                            {
                                                payTransaction.customerPhone = myObj.cardholder_phone;
                                                if (payTransaction.customerPhone.Length >= 10)
                                                    isCustomerReceiptPhoneSend = true;
                                            }

                                            db.Entry(payTransaction).State = EntityState.Modified;
                                            db.SaveChanges();

                                            Message msgEmail = new Message(int.Parse(ConfigurationManager.AppSettings["CustomerIdWebMail"]));
                                            msgEmail.ConnectionStrings = ConfigurationManager.AppSettings["ConnectionString"];
                                            msgEmail.Schema = ConfigurationManager.AppSettings["CustomerMailSchema"];
                                            if (payTransaction.operation.Value != (int)Business.Enums.Operation.REFUND)
                                            {
                                                msgEmail.Subject = ConfigurationManager.AppSettings["CustomerMailSubject"];
                                            }
                                            else
                                            {
                                                msgEmail.Subject = ConfigurationManager.AppSettings["CustomerMailSubjectRefund"];
                                            }
                                            msgEmail.cdIdentification1 = payTransaction.idTransaction.ToString();

                                            msgEmail.IdSystem = idSystem;
                                            msgEmail.IdUserCreate = participant.idUser;

                                            if (isCustomerReceiptSend)
                                            {
                                                msgEmail.MailTo = payTransaction.customerEmail;
                                                msgEmail.Body = payTransaction.customerReceipt;
                                                msgEmail.Send();
                                            }

                                            if (isMerchantReceiptSend)
                                            {
                                                msgEmail.MailTo = payTransaction.merchantEmail;
                                                msgEmail.Body = payTransaction.merchantReceipt;
                                                msgEmail.Send();
                                            }

                                            if (isCustomerReceiptPhoneSend)
                                            {
                                                try
                                                {
                                                    VirtualPlay.Direct100.SMS.Authentication authSMS =
                                                        new VirtualPlay.Direct100.SMS.Authentication(ConfigurationManager.AppSettings["Direct100_User"]
                                                                         , ConfigurationManager.AppSettings["Direct100_Password"]);

                                                    if (authSMS.IsAuthenticate())
                                                    {
                                                        VirtualPlay.Direct100.SMS.Message.Result msgResult;
                                                        VirtualPlay.Direct100.SMS.Message sendMessage = new VirtualPlay.Direct100.SMS.Message(authSMS.User);
                                                        sendMessage.Schema = ConfigurationManager.AppSettings["CustomerMailSchema"];
                                                        sendMessage.IdSystem = idSystem;
                                                        sendMessage.IdUser = participant.idUser;
                                                        sendMessage.Extra = payTransaction.idTransaction.ToString();
                                                        sendMessage.ConnectionStrings =
                                                                ConfigurationManager.AppSettings["ConnectionString"];

                                                        string numberPhone = string.Concat("55", payTransaction.customerPhone.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", ""));
                                                        string messageString = string.Empty;

                                                        if (payTransaction.operation.Value != (int)Business.Enums.Operation.REFUND)
                                                        {
                                                            messageString =
                                                                ConfigurationManager.AppSettings["CustomerPaymentSMS"]
                                                                                     .Replace("#CARTAO#"
                                                                                            , payTransaction.paymentFunctionDescription)
                                                                                     .Replace("#VALOR#"
                                                                                            , payTransaction.value)
                                                                                     .Replace("#ESTABELECIMENTO#"
                                                                                            , payTransaction.merchantName)
                                                                                     .Replace("#dd-MM-yy HH:mm#"
                                                                                            , payTransaction.date.Value.ToString("dd-MM-yy HH:mm"));
                                                        }
                                                        else
                                                        {
                                                            messageString =
                                                                ConfigurationManager.AppSettings["CustomerPaymentSMSRefund"]
                                                                                     .Replace("#CARTAO#"
                                                                                            , payTransaction.paymentFunctionDescription)
                                                                                     .Replace("#VALOR#"
                                                                                            , payTransaction.value)
                                                                                     .Replace("#ESTABELECIMENTO#"
                                                                                            , payTransaction.merchantName)
                                                                                     .Replace("#dd-MM-yy HH:mm#"
                                                                                            , payTransaction.date.Value.ToString("dd-MM-yy HH:mm"));
                                                        }
                                                        msgResult = sendMessage.Send(authSMS.Token, numberPhone, messageString);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    //Erro ou não foi possível enviar o SMS
                                                }
                                            }

                                            response = new PayRequest(newSession, payTransaction);
                                        }
                                        else
                                        {
                                            response = new ResponseFailure("invalid-data");
                                        }
                                    }
                                    else
                                    {
                                        response = new ResponseFailure("invalid-data");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    response = new ResponseFailure("invalid-data");
                                }
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #11
0
        public JsonResult New(string session, string email, int merchant, int system)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            if (active_session <= 60 && participant.dsSession.Equals(session))
                            {
                                Stream req = Request.InputStream;
                                req.Seek(0, System.IO.SeekOrigin.Begin);
                                string json = new StreamReader(req).ReadToEnd();

                                dynamic myObj;
                                try
                                {
                                    myObj = JsonConvert.DeserializeObject(json);

                                    string newSession = SessionController.New(email);
                                    SessionController.Write(newSession, participant.idUser, system);

                                    var payTransaction = new Pay_Transaction();
                                    payTransaction.idMerchant = merchant;
                                    payTransaction.dtCreate = DateTime.Now;
                                    payTransaction.dtLastUpdate = DateTime.Now;

                                    payTransaction.date = payTransaction.dtCreate;

                                    if (myObj.merchantEmail != null)
                                        payTransaction.merchantEmail = myObj.merchantEmail; //required
                                    if (myObj.merchantName != null)
                                        payTransaction.merchantName = myObj.merchantName;
                                    if (myObj.merchantInstallmentAllowed != null)
                                        payTransaction.merchantInstallmentAllowed = myObj.merchantInstallmentAllowed;

                                    if (myObj.isTest != null)
                                        payTransaction.isTest = myObj.isTest;
                                    if (myObj.operation != null)
                                        payTransaction.operation = myObj.operation;
                                    if (myObj.pinpadInfo != null)
                                        payTransaction.pinpadInfo = myObj.pinpadInfo;
                                    if (myObj.serial_number != null)
                                        payTransaction.pinpadSerialNumber = myObj.serial_number;
                                    if (myObj.state != null)
                                        payTransaction.state = myObj.state;
                                    if (myObj.statusCode != null)
                                        payTransaction.statusCode = myObj.statusCode;
                                    if (myObj.type != null)
                                        payTransaction.type = myObj.type;
                                    if (myObj.value != null)
                                        payTransaction.value = myObj.value;

                                    if (myObj.latitude != null)
                                        payTransaction.latitude = myObj.latitude;
                                    if (myObj.longitude != null)
                                        payTransaction.longitude = myObj.longitude;

                                    if (myObj.flStatus != null && !((string)myObj.flStatus).Equals("null"))
                                        payTransaction.flStatus = myObj.flStatus;

                                    db.Pay_Transaction.Add(payTransaction);
                                    db.SaveChanges();

                                    response = new PayRequest(newSession, payTransaction);
                                }
                                catch (Exception ex)
                                {
                                    response = new ResponseFailure("invalid-data");
                                }
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #12
0
        public JsonResult NewSignature(string session, string email, int system)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            if (active_session <= 60 && participant.dsSession.Equals(session))
                            {
                                Stream req = Request.InputStream;
                                req.Seek(0, System.IO.SeekOrigin.Begin);
                                string json = new StreamReader(req).ReadToEnd();

                                dynamic myObj;
                                try
                                {
                                    myObj = JsonConvert.DeserializeObject(json.Replace(@"\", ""));

                                    string newSession = SessionController.New(email);
                                    SessionController.Write(newSession, participant.idUser, system);

                                    Pay_Transaction payTrans = null;
                                    long idMobile = 0;

                                    var payTransaction = new Pay_TransactionSignature();
                                    payTransaction.dtCreate = DateTime.Now;

                                    if (myObj.idServer != null)
                                        payTransaction.idTransaction = myObj.idServer; //required

                                    if (myObj.id != null)
                                        idMobile = myObj.id;

                                    if (myObj.signature != null)
                                    {
                                        string signature = myObj.signature;
                                        payTransaction.imSignature = FixBase64ForImage(signature);
                                    }

                                    if (myObj.createdAt != null)
                                    {

                                    }

                                    payTrans = db.Pay_Transaction.Where(p => p.idMobile == idMobile).FirstOrDefault();
                                    if (payTrans != null)
                                    {
                                        payTransaction.idTransaction = payTrans.idTransaction; //required
                                    }

                                    db.Pay_TransactionSignature.Add(payTransaction);
                                    db.SaveChanges();

                                    if (payTrans != null)
                                    {
                                        payTrans.idSignature = payTransaction.idSignature;
                                        payTrans.dtLastUpdate = DateTime.Now;

                                        db.Entry(payTrans).State = EntityState.Modified;
                                    }

                                    db.SaveChanges();

                                    response = new PaySignature(newSession, payTransaction);
                                }
                                catch (Exception ex)
                                {
                                    response = new ResponseFailure("invalid-data");
                                }
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Пример #13
0
        public JsonResult generateNewSession(string session, string email)
        {
            using (var db = new Entities())
            {
                Response response = null;

                if (!string.IsNullOrEmpty(email) && ValidaEmail(email))
                {
                    if (!string.IsNullOrEmpty(session))
                    {
                        var participants = db.Sys_User.Where(z => z.dsEmail == email);

                        List<Sys_User> listParticipant = participants.ToList();

                        if (listParticipant != null && listParticipant.Count > 0)
                        {
                            int active_session = 0;

                            Sys_User participant = db.Sys_User.Find(listParticipant[0].idUser);

                            if (participant.dtLastSession != null)
                            {
                                DateTime dateNow = DateTime.Now;

                                TimeSpan timeSpan = dateNow.Subtract((DateTime)participant.dtLastSession);
                                active_session = timeSpan.Minutes;
                            }

                            if (active_session <= 60 && participant.dsSession.Equals(session))
                            {
                                participant.dtLastSession = DateTime.Now;
                                participant.dsSession = NewSession(email);

                                db.Entry(participant).State = EntityState.Modified;
                                db.SaveChanges();

                                response = new Login(participant.idUser, participant.idRole.Value, participant.idPerson.Value, participant.idPerson.Value, participant.idMerchant.Value, 0, participant.nmUser, email, participant.dsSession);
                            }
                            else
                            {
                                response = new ResponseFailure("invalid-session");
                            }
                        }
                        else
                        {
                            response = new ResponseFailure("invalid-email");
                        }
                    }
                    else
                    {
                        response = new ResponseFailure("invalid-session");
                    }
                }
                else
                {
                    response = new ResponseFailure("invalid-email");
                }

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }