Exemple #1
0
        private void ReadyToPay(Student std)
        {
            string         amount = string.Empty, Payment_For = string.Empty;
            int            payment_type_id = 1;
            Specialization spec            = db.Specializations.Find(std.Student_Specialization_Id);

            if (std.Student_Status_Id == 6)
            {
                amount          = spec.Specialization_Registeration_Payment.ToString();
                Payment_For     = "Registration";
                payment_type_id = 1;
            }
            else
            {
                amount          = spec.Specialization_Study_Payment.ToString();
                Payment_For     = "Study";
                payment_type_id = 2;
            }

            int    student_id  = std.Student_Id;
            string entityId    = "";
            string currency    = "SAR";
            string paymentType = "DB";

            Payment_Process payment = db.Payment_Process.Create();

            payment.Student_Id          = student_id;
            payment.Send_Amount         = float.Parse(amount);
            payment.Send_Currency       = currency;
            payment.Send_EntityId       = entityId;
            payment.Send_PaymentType    = paymentType;
            payment.Payment_IsPaid      = false;
            payment.Payment_Type_Id     = payment_type_id;
            payment.DateCreation        = DateTime.Now;
            payment.Comment             = Payment_For + " Fees";
            payment.Payment_Trackingkey = StringCipher.RandomString(5) + student_id + StringCipher.RandomString(3) + DateTime.Now.GetHashCode() + StringCipher.RandomString(5);
            payment.Payment_URL_IsValid = true;
            db.Payment_Process.Add(payment);
            db.SaveChanges();

            //Send Email
            send_ReadyToPay(std, payment, Payment_For);

            // Send SMS
            SendSMS send_sms   = new SendSMS();
            string  sever_name = Request.Url.Authority.ToString();
            string  URL        = sever_name + "/Payment/PaymentProcessDetails.aspx?Trackingkey=" + payment.Payment_Trackingkey;

            if (URL.Substring(0, 4).ToLower() != "http".ToLower())
            {
                URL = "http://" + URL;
            }

            string Text          = "Dear " + std.Student_Name_En + "\nNow you can pay the fees of " + Payment_For + "\nPlease use this link: " + URL;
            string number_Phone  = std.Student_Phone;
            string reslt_message = send_sms.SendMessage(Text, number_Phone);
        }
Exemple #2
0
        private bool rest_account(string email)
        {
            email = email.Trim().ToLower();
            db.Configuration.LazyLoadingEnabled = false;
            Employee emp = db.Employees.Where(x => x.Employee_Email.ToLower() == email).FirstOrDefault();

            if (emp != null)
            {
                string New_Password       = StringCipher.RandomString(7);
                string Encrypted_Password = StringCipher.Encrypt(New_Password, "Password"); // emp.Employee_Password.ToString();
                emp.Employee_Password = Encrypted_Password;
                db.Entry(emp).State   = System.Data.EntityState.Modified;
                db.SaveChanges();

                string sever_name = Request.Url.Authority.ToString();
                // Send SMS
                SendSMS send_sms      = new SendSMS();
                string  url           = "http://registration.riyadh.edu.sa/Pages/Auth/Login.aspx";
                string  Text          = "Reset Password\n\nEmail:" + emp.Employee_Email + "\n\nPassword:"******"\n\nURL:" + url;
                string  number_Phone  = emp.Employee_Phone;
                string  reslt_message = send_sms.SendMessage(Text, number_Phone);

                SendEmail send   = new SendEmail();
                bool      result = send.ResetEmail(emp.Employee_Email, New_Password, sever_name, "Reset Password");
                if (result)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_sucess();", true);
                    txtEmail.Text = "";

                    /* Add it to log file */

                    LogData = "data:" + JsonConvert.SerializeObject(emp, logFileModule.settings);
                    logFileModule.logfile(10, "إعادة تعين كلمة السر", "reset your password", LogData);

                    return(true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_error();", true);
                    return(false);
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", " show_model_notfound();", true);
                return(false);
            }
        }
        private bool rest_account(string email)
        {
            db.Configuration.LazyLoadingEnabled = false;
            Employee emp = db.Employees.Where(x => x.Employee_Email == email).FirstOrDefault();

            if (emp != null)
            {
                string New_Password       = StringCipher.RandomString(7);
                string Encrypted_Password = StringCipher.Encrypt(New_Password, "Password"); // emp.Employee_Password.ToString();
                emp.Employee_Password = Encrypted_Password;
                db.Entry(emp).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                string    sever_name = Request.Url.Authority.ToString();
                SendEmail send       = new SendEmail();
                bool      result     = send.ResetEmail(emp.Employee_Email, New_Password, sever_name, "Reset Password");
                if (result)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_sucess();", true);
                    txtEmail.Text = "";

                    /* Add it to log file */

                    LogData = "data:" + JsonConvert.SerializeObject(emp, logFileModule.settings);
                    logFileModule.logfile(10, "إعادة تعين كلمة السر", "reset your password", LogData);

                    return(true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_error();", true);
                    return(false);
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", " show_model_notfound();", true);
                return(false);
            }
        }
Exemple #4
0
        public bool AU_Emplooyees(int EmployeeID, string ArabicName, string EnglishName, string Email, string Phone, bool Active, int GroupID, int lang)
        {
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                Employee Emp = db.Employees.Create();
                if (EmployeeID != 0)
                {
                    Emp = db.Employees.First(x => x.Employee_Id == EmployeeID);
                }
                Emp.Employee_Name_Ar = ArabicName;
                Emp.Employee_Name_En = EnglishName;
                Emp.Employee_Email   = Email;
                if (EmployeeID == 0)
                {
                    string New_Password       = StringCipher.RandomString(7);
                    string Encrypted_Password = StringCipher.Encrypt(New_Password, "Password"); // emp.Employee_Password.ToString();
                    Emp.Employee_Password = Encrypted_Password;

                    string    sever_name  = Request.Url.Authority.ToString();
                    SendEmail send        = new SendEmail();
                    bool      EmailResult = send.ResetEmail(Email, New_Password, sever_name, "New Account");
                    if (EmailResult)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_sucess();", true);
                    }
                }
                Emp.Employee_Phone  = Phone;
                Emp.Employee_Active = Active;
                Emp.Group_Id        = GroupID;
                Emp.Language_id     = lang;
                //Emp.Calendar_id = calander;
                string ImagepathProfile   = UploadFile(1);
                string ImagepathSignature = UploadFile(2);
                if (ImagepathProfile != "")
                {
                    Emp.Employee_Profile = ImagepathProfile;
                }
                else if (EmployeeID == 0)
                {
                    ImagepathProfile = "Profile.JPG";
                }
                if (EmployeeID != 0)
                {
                    db.Entry(Emp).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.Employees.Add(Emp);
                }
                db.SaveChanges();
                /* Add it to log file */
                LogData = "data:" + JsonConvert.SerializeObject(Emp, logFileModule.settings);
                if (EmployeeID != 0)
                {
                    logFileModule.logfile(10, "تعديل بيانات موظف", "update Employee", LogData);
                }
                else
                {
                    logFileModule.logfile(10, "إضافة موظف", "Add Employee", LogData);
                }
            }
            catch { return(false); }
            return(true);
        }
Exemple #5
0
        public bool AU_Emplooyees(int EmployeeID, string ArabicName, string EnglishName, string Email, string Phone, bool Active, int GroupID, int lang)
        {
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                Employee Emp = db.Employees.Create();
                if (EmployeeID != 0)
                {
                    Emp = db.Employees.First(x => x.Employee_Id == EmployeeID);
                }
                Emp.Employee_Name_Ar = ArabicName;
                Emp.Employee_Name_En = EnglishName;
                Emp.Employee_Email   = Email;
                if (EmployeeID == 0)
                {
                    string New_Password = StringCipher.RandomString(7);
                    Encrypted_Password    = StringCipher.Encrypt(New_Password, "Password"); // emp.Employee_Password.ToString();
                    Emp.Employee_Password = Encrypted_Password;

                    /* if (EmailResult)
                     * {
                     *   Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_sucess();", true);
                     * }*/

                    //Send Email
                    string    Text       = "";
                    string    sever_name = Request.Url.Authority.ToString();
                    string    StuEmail   = Email;
                    SendEmail send       = new SendEmail();
                    Text = " <Strong style='font-size:16px;'>Dear " + EnglishName + "</Strong><br /><br /> " + "Now you can access the online admission system through the link: http://registration.riyadh.edu.sa" + "<br /><br />" + "User Name :" + Email + " <br />" + "Password :"******"<br /><br />" + "Best Regard," + " <br />" + "Admission System" + " <br />";
                    bool R = send.TextEmail("Riyadh Elm University", StuEmail, Text, sever_name);

                    // Send SMS
                    SendSMS send_sms      = new SendSMS();
                    string  smsText       = "Dear " + EnglishName + "\n" + "Now you can access the online admission system through the link: http://registration.riyadh.edu.sa" + "\n\n" + "User Name : " + Email + "\n" + "Password : "******" \n\n" + "Best Regard," + " \n" + "Admission System";
                    string  number_Phone  = Phone;
                    string  reslt_message = send_sms.SendMessage(smsText, number_Phone);
                }
                Emp.Employee_Phone  = Phone;
                Emp.Employee_Active = Active;
                Emp.Group_Id        = GroupID;
                Emp.Language_id     = lang;
                //Emp.Calendar_id = calander;
                string ImagepathProfile   = UploadFile(1);
                string ImagepathSignature = UploadFile(2);
                if (ImagepathProfile != "")
                {
                    Emp.Employee_Profile = ImagepathProfile;
                }
                else if (EmployeeID == 0)
                {
                    Emp.Employee_Profile = "Profile.JPG";
                }
                if (EmployeeID != 0)
                {
                    db.Entry(Emp).State = System.Data.EntityState.Modified;
                }
                else
                {
                    db.Employees.Add(Emp);
                }
                db.SaveChanges();
                /* Add it to log file */
                LogData = "data:" + JsonConvert.SerializeObject(Emp, logFileModule.settings);
                if (EmployeeID != 0)
                {
                    logFileModule.logfile(10, "تعديل بيانات موظف", "update Employee", LogData);
                }
                else
                {
                    logFileModule.logfile(10, "إضافة موظف", "Add Employee", LogData);
                }
            }
            catch { return(false); }
            return(true);
        }
        public bool AU_Emplooyees(int EmployeeID, string ArabicName, string EnglishName, string Email, string Phone, bool Active, int GroupID, int lang, int calander)
        {
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                Employee Emp = db.Employees.Create();
                if (EmployeeID != 0)
                {
                    Emp = db.Employees.First(x => x.Employee_Id == EmployeeID);
                }
                Emp.Employee_Name_Ar = ArabicName;
                Emp.Employee_Name_En = EnglishName;
                Emp.Employee_Email   = Email;
                Employee_Structure Emp_Stu = new Employee_Structure();;
                if (EmployeeID == 0)
                {
                    string New_Password       = StringCipher.RandomString(7);
                    string Encrypted_Password = StringCipher.Encrypt(New_Password, "Password"); // emp.Employee_Password.ToString();
                    Emp.Employee_Password = Encrypted_Password;

                    string sever_name = Request.Url.Authority.ToString();

                    /*  SendEmail send = new SendEmail();
                     * bool EmailResult = send.ResetEmail(Email, New_Password, sever_name);
                     * if (EmailResult)
                     * {
                     *    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "show_model_sucess();", true);
                     * }*/
                }
                Emp.Employee_Phone  = Phone;
                Emp.Employee_Active = Active;
                Emp.Group_Id        = GroupID;
                Emp.Language_id     = lang;
                Emp.Calendar_id     = calander;
                string ImagepathProfile   = UploadFile(1);
                string ImagepathSignature = UploadFile(2);
                if (ImagepathProfile != "")
                {
                    Emp.Employee_Profile = ImagepathProfile;
                }
                else if (EmployeeID == 0)
                {
                    ImagepathProfile = "Profile.JPG";
                }
                if (ImagepathSignature != "")
                {
                    Emp.Employee_Signature = ImagepathSignature;
                }
                else if (EmployeeID == 0)
                {
                    ImagepathSignature = "Signature.JPG";
                }
                /////////////////////////////////////// Employee_Structure /////////////////////////////////////
                Boolean DefaultStructure = false;
                for (int i = 0; i < Emp_Structure.Items.Count; i++)
                {
                    int     id      = 0;
                    Boolean IsFound = false;
                    int.TryParse(Emp_Structure.Items[i].Value, out id);
                    var Emp_Stru_found = db.Employee_Structure.Where(x => x.Employee_Id == EmployeeID && x.Structure_Id == id).ToList();
                    if (Emp_Stru_found.Count > 0)
                    {
                        IsFound = true;
                    }
                    if (Emp_Structure.Items[i].Selected)
                    {
                        if (!IsFound)
                        {
                            Emp_Stu = new Employee_Structure();
                            Emp_Stu.Structure_Id     = int.Parse(Emp_Structure.Items[i].Value);
                            Emp_Stu.Status_Structure = true;
                            Emp_Stu.Type_Delegation  = false;
                            if (!DefaultStructure)
                            {
                                Emp_Stu.Default_Structure = true; DefaultStructure = true;
                            }
                            else
                            {
                                Emp_Stu.Default_Structure = false;
                            }
                            Emp.Employee_Structure.Add(Emp_Stu);
                        }
                        else
                        {
                            Emp_Stu = db.Employee_Structure.First(x => x.Employee_Id == EmployeeID && x.Structure_Id == id);
                            Emp_Stu.Status_Structure = true;
                            Emp_Stu.Type_Delegation  = false;
                            if (!DefaultStructure)
                            {
                                Emp_Stu.Default_Structure = true; DefaultStructure = true;
                            }
                            else
                            {
                                Emp_Stu.Default_Structure = false;
                            }
                            Emp.Employee_Structure.Add(Emp_Stu);
                        }
                    }
                    else if (IsFound)
                    {
                        Emp_Stu = db.Employee_Structure.First(x => x.Employee_Id == EmployeeID && x.Structure_Id == id);
                        Emp_Stu.Status_Structure  = false;
                        Emp_Stu.Type_Delegation   = false;
                        Emp_Stu.Default_Structure = false;
                        Emp.Employee_Structure.Add(Emp_Stu);
                    }
                }
                /////////////////////////////////////// Employee_Structure /////////////////////////////////////
                if (EmployeeID != 0)
                {
                    db.Entry(Emp).State = System.Data.EntityState.Modified;
                }
                else
                {
                    db.Employees.Add(Emp);
                }
                db.SaveChanges();
                /* Add it to log file */
                LogData = "data:" + JsonConvert.SerializeObject(Emp, logFileModule.settings);
                if (EmployeeID != 0)
                {
                    logFileModule.logfile(10, "تعديل بيانات موظف", "update Employee", LogData);
                }
                else
                {
                    logFileModule.logfile(10, "إضافة موظف", "Add Employee", LogData);
                }
                LogData = "data:" + JsonConvert.SerializeObject(Emp_Stu, logFileModule.settings);
                logFileModule.logfile(10, "هيكلة موظف", "Employee Structure", LogData);
            }
            catch { return(false); }
            return(true);
        }
        public async System.Threading.Tasks.Task <bool> confirm_To_Payment()
        {
            string Entity_ID = "";
            bool   Response  = false;

            try
            {
                /*  Start Prepare the checkout  */
                Payment_Process checkout_payment = db.Payment_Process.Where(x => x.Payment_Trackingkey == Trackingkey && x.Payment_URL_IsValid == true && x.Payment_IsPaid == false).FirstOrDefault();
                if (checkout_payment != null)
                {
                    if (PaymentType.SelectedValue == "1" || PaymentType.SelectedValue == "2")
                    {
                        Entity_ID = "8acda4ce72e5a3df0172fb754c3c488c";
                    }
                    else if (PaymentType.SelectedValue == "3")
                    {
                        Entity_ID = "8acda4ce72e5a3df0172fb75d45d4891";
                    }

                    if (PaymentType.SelectedValue != "4")
                    {
                        string paymentBrand = "VISA";
                        if (PaymentType.SelectedValue == "1")
                        {
                            paymentBrand = "VISA";
                        }
                        else if (PaymentType.SelectedValue == "2")
                        {
                            paymentBrand = "MASTER";
                        }
                        else if (PaymentType.SelectedValue == "3")
                        {
                            paymentBrand = "MADA";
                        }

                        VISA_MADA NewVM = db.VISA_MADA.Create();
                        NewVM.UUID = UUID;
                        NewVM.PaymentProcess_Id = checkout_payment.Payment_Id;
                        NewVM.Trackingkey       = checkout_payment.Payment_Trackingkey;
                        NewVM.Result_JSON       = string.Empty;
                        NewVM.DateCreation      = DateTime.Now;
                        db.VISA_MADA.Add(NewVM);
                        db.SaveChanges();

                        Dictionary <string, dynamic> responseData =
                            Prepare_Check_Payment_Request(UUID, paymentBrand, Entity_ID, checkout_payment.Send_Amount.ToString(), checkout_payment.Send_Currency, checkout_payment.Send_PaymentType, StudentName.Text, Studentsurname.Text, StudentEmail.Text, StudentCountry.SelectedValue, StudentState.Text, StudentCity.Text, StudentAddress.Text, StudentPostcode.Text);
                        if (responseData["result"]["code"] == "000.200.100")
                        {
                            checkout_payment.Result_Code        = responseData["result"]["code"];
                            checkout_payment.Result_Description = responseData["result"]["description"];
                            checkout_payment.Result_BuildNumber = responseData["buildNumber"];
                            checkout_payment.Result_Timestamp   = responseData["timestamp"];
                            checkout_payment.Result_Ndc         = responseData["ndc"];
                            checkout_payment.Result_Id          = responseData["id"];
                            checkout_payment.Send_EntityId      = Entity_ID;
                            db.Entry(checkout_payment);
                            db.SaveChanges();


                            Response = true;
                        }
                        else
                        {
                            Response = false;
                            //return false;
                        }
                        // Save Result in all cases
                        VISA_MADA VM_UpdateResult = db.VISA_MADA.Where(x => x.UUID == UUID).FirstOrDefault();
                        if (VM_UpdateResult != null)
                        {
                            VM_UpdateResult.Result_JSON     = JsonConvert.SerializeObject(responseData);
                            db.Entry(VM_UpdateResult).State = System.Data.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        int studentID = 0;
                        int.TryParse(checkout_payment.Student_Id.ToString(), out studentID);
                        string PayeeId = StringCipher.RandomString(10);

                        string Gender = StudentGender.SelectedValue;

                        Dictionary <string, dynamic> responseData = await Prepare_Check_Payment_Request_SADAD(checkout_payment.Payment_Id, PayeeId, UUID, checkout_payment.Send_Amount.ToString(), checkout_payment.Student.Student_SSN, checkout_payment.Send_PaymentType, StudentFirstName.Text, StudentLastName.Text, studentID, Gender);

                        if (responseData["Status"]["Code"] == 0)
                        {
                            checkout_payment.Result_Code        = (responseData["Status"]["Code"]).ToString();
                            checkout_payment.Result_Description = responseData["Status"]["Description"];
                            checkout_payment.Result_BuildNumber = responseData["SADADNumber"];
                            checkout_payment.Result_Timestamp   = responseData["Status"]["Severity"];
                            checkout_payment.Result_Ndc         = responseData["InvoiceId"];
                            db.Entry(checkout_payment).State    = System.Data.EntityState.Modified;
                            db.SaveChanges();

                            string        InvoiceId = responseData["InvoiceId"];
                            Rosom_Request Rosom     = db.Rosom_Request.FirstOrDefault(x => x.Trackingkey == Trackingkey && x.InvoiceId == InvoiceId);
                            Rosom.Response_Status_Code = (responseData["Status"]["Code"]).ToString();
                            // Rosom. = responseData["result"]["description"];
                            Rosom.Response_SADADNumber = responseData["SADADNumber"];
                            Rosom.Result_JSON          = JsonConvert.SerializeObject(responseData);
                            db.Entry(Rosom).State      = System.Data.EntityState.Modified;;
                            db.SaveChanges();

                            SADAD_Number = responseData["SADADNumber"];

                            string Text       = "";
                            string sever_name = Request.Url.Authority.ToString();
                            string StuEmail   = checkout_payment.Student.Student_Email;

                            SendEmail send = new SendEmail();
                            Text = " <Strong style='font-size:16px;'> Dear " + checkout_payment.Student.Student_Name_En + "</Strong><br /><br /> " + "The invoice number of SADAD is:<Strong>" + SADAD_Number + "</Strong>.<br />The total amount: <Strong>" + checkout_payment.Send_Amount + "</Strong> SAR.<br /><br />Please complete the payment before 48 hours." + " <br /> <br />" + "Best Regard," + " <br />";
                            bool R = send.TextEmail("Riyadh Elm University", StuEmail, Text, sever_name);

                            // Send SMS
                            SendSMS send_sms      = new SendSMS();
                            string  smsText       = "Dear " + checkout_payment.Student.Student_Name_En + "\n\n" + "The invoice number of SADAD is:" + SADAD_Number + ".\n\nThe total amount: " + checkout_payment.Send_Amount + " SAR.\n\nPlease complete the payment before 48 hours." + " \n\n" + "Best Regard";
                            string  number_Phone  = checkout_payment.Student.Student_Phone;
                            string  reslt_message = send_sms.SendMessage(smsText, number_Phone);

                            Response = true;
                        }
                        else
                        {
                            Response = false;
                            //return false;
                        }
                    }
                }
                else
                {
                    Response = false;
                    //return Response;
                }
            }
            catch (Exception er)
            {
                db.Configuration.LazyLoadingEnabled = false;
                /* Add it to log file */
                LogData = "data:" + JsonConvert.SerializeObject(er, logFileModule.settings);
                logFileModule.logfile(10, "خطأ جديد للدفع", "New Exception in Payment", LogData);
                return(false);
            }

            return(Response);
            /* End Prepare the checkout */
        }
        public string RandomTrackingkey(int student_id)
        {
            string Trackingkey = StringCipher.RandomString(5) + student_id + StringCipher.RandomString(3) + DateTime.Now.GetHashCode() + StringCipher.RandomString(5);

            return(Trackingkey);
        }
        /// <summary>
        /// ROSOM - SADAD
        /// </summary>
        /// <param name="UUID"></param>
        /// <param name="amount"></param>
        /// <param name="SSN"></param>
        /// <param name="paymentType"></param>
        /// <param name="FirstName"></param>
        /// <param name="LastName"></param>
        /// <param name="Student_id"></param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <Dictionary <string, dynamic> > Prepare_Check_Payment_Request_SADAD(int Payment_Process_Id, string PayeeId, string UUID, string amount, string SSN, string paymentType, string FirstName, string LastName, int Student_id, string Gender)
        {
            List <Rosom_Request> rosom_request = db.Rosom_Request.Where(x => x.Payment_Process_Id == Payment_Process_Id).ToList();
            string Res_str      = "";
            string NewInvoiceID = "";
            string School_Id    = "2426"; // Female

            if (Gender == "1")
            {
                School_Id = "2427"; // Male
            }
            string CreateDate = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
            string ExpiryDate = DateTime.Now.AddDays(7).ToString("yyyy-MM-ddTHH:mm:ss");

            string InvoiceId   = StringCipher.RandomString(5) + StringCipher.RandomString(3) + DateTime.Now.GetHashCode() + StringCipher.RandomString(5);
            string DisplayInfo = "REU Riyadh Elm University - Admission System. ";

            List <student_local> student_List = new List <student_local>();
            student_local        std_local    = new student_local();

            std_local.Id        = SSN;
            std_local.FirstName = FirstName;
            std_local.LastName  = LastName;
            student_List.Add(std_local);

            PaymentRange paymentRange_object = new PaymentRange();

            paymentRange_object.MinPartialAmount = Decimal.Parse(amount);
            paymentRange_object.MinAdvanceAmount = Decimal.Parse(amount);
            paymentRange_object.MaxAdvanceAmount = Decimal.Parse(amount) + 100;

            Invoice invoice_object = new Invoice();

            invoice_object.Students      = student_List;
            invoice_object.InvoiceId     = InvoiceId;
            invoice_object.PayeeId       = SSN;
            invoice_object.InvoiceStatus = "BillNew";
            invoice_object.BillType      = "OneTime";
            invoice_object.DisplayInfo   = DisplayInfo;
            invoice_object.AmountDue     = Decimal.Parse(amount);
            invoice_object.CreateDate    = CreateDate;
            invoice_object.ExpiryDate    = ExpiryDate;
            invoice_object.PaymentRange  = paymentRange_object;

            // If it's Update
            if (rosom_request.Count > 0)
            {
                invoice_object.InvoiceId     = rosom_request[rosom_request.Count - 1].InvoiceId;
                invoice_object.InvoiceStatus = "BillUpdated";
                NewInvoiceID = rosom_request[rosom_request.Count - 1].InvoiceId;
            }
            Rosom rosom_object = new Rosom();

            rosom_object.UUID       = UUID;
            rosom_object.Timestamp  = CreateDate;
            rosom_object.MerchantId = "12190";
            rosom_object.SchoolId   = School_Id;
            rosom_object.Invoice    = invoice_object;

            var json = JsonConvert.SerializeObject(rosom_object);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            // Get and Add the certificate to http client
            WebRequestHandler handler = new WebRequestHandler();

            handler.ServerCertificateValidationCallback = (message, cert, chain, errors) => { return(true); };

            // Load certificate
            string certificateSerialNumber = "79011992a06448bb4d19fd844cb54731";

            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySerialNumber, certificateSerialNumber, false);

            store.Close();

            if (certs[0] != null)
            {
                // Fetch private key
                using (certs[0].GetRSAPrivateKey()) { }

                // Add certificate to web handler
                handler.ClientCertificates.Add(certs[0]);
            }

            string     url    = "Bill/CreateBill";
            HttpClient client = new HttpClient(handler);

            client.BaseAddress = new Uri("https://rosomtest.brightware.com.sa/RosomAPI/api/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));



            var response = await client.PostAsync(url, data);

            Res_str = response.Content.ReadAsStringAsync().Result;

            if (Res_str == "")
            {
                Dictionary <string, dynamic> responseData2 = new Dictionary <string, dynamic>();
                return(responseData2);
            }


            var s = new JavaScriptSerializer();
            Dictionary <string, dynamic> responseData = s.Deserialize <Dictionary <string, dynamic> >(Res_str);

            if (responseData != null && responseData["Status"]["Code"] == 0)
            {
                Rosom_Request Rosom;
                if (rosom_request.Count > 0)
                {
                    Rosom = db.Rosom_Request.Find(rosom_request[rosom_request.Count - 1].Id);
                }
                else
                {
                    Rosom = db.Rosom_Request.Create();
                }

                Rosom.Trackingkey         = Trackingkey;
                Rosom.Payment_Process_Id  = Payment_Process_Id;
                Rosom.CreateDate          = DateTime.Now.ToLongDateString();
                Rosom.Invoice_Students_Id = InvoiceId;
                if (rosom_request.Count > 0)
                {
                    Rosom.Invoice_Students_Id = NewInvoiceID;
                }

                Rosom.PayeeId       = PayeeId;
                Rosom.InvoiceStatus = "BillNew";
                if (rosom_request.Count > 0)
                {
                    Rosom.InvoiceStatus = "BillUpdated";
                }

                Rosom.BillType    = "OneTime";
                Rosom.DisplayInfo = DisplayInfo;
                Rosom.PaymentType = 4; //SADDAD option type id;
                Rosom.IsPaid      = false;

                Rosom.DateCreation = DateTime.Now;
                Rosom.MerchantId   = "12190";
                Rosom.Timestamp    = CreateDate;
                Rosom.UUID         = UUID;
                Rosom.Invoice_Students_FirstName = FirstName;
                Rosom.Invoice_Students_LastName  = LastName;
                Rosom.InvoiceId = InvoiceId;

                if (rosom_request.Count > 0)
                {
                    Rosom.InvoiceId = NewInvoiceID;
                }

                Rosom.DisplayInfo = DisplayInfo;
                Rosom.AmountDue   = amount;
                Rosom.CreateDate  = CreateDate;
                Rosom.ExpiryDate  = ExpiryDate;

                Rosom.PaymentRange_MaxAdvanceAmount = amount;
                Rosom.PaymentRange_MinAdvanceAmount = amount;
                Rosom.PaymentRange_MinPartialAmount = amount + 1;
                if (rosom_request.Count > 0)
                {
                    db.Entry(Rosom).State = System.Data.EntityState.Modified;
                }
                else
                {
                    db.Rosom_Request.Add(Rosom);
                }
                db.SaveChanges();
            }
            return(responseData);
        }
Exemple #10
0
        public Dictionary <string, dynamic> Prepare_Check_Payment_Request_SADAD(string UUID, string amount, string SSN, string paymentType, string FirstName, string LastName, int Student_id)
        {
            string CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


            string ExpiryDate  = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd HH:mm:ss");
            string InvoiceId   = StringCipher.RandomString(5) + StringCipher.RandomString(3) + DateTime.Now.GetHashCode() + StringCipher.RandomString(5);
            string DisplayInfo = "Free text for merchant to add details to the bill";

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            Dictionary <string, dynamic> responseData;


            string data = "UUID =" + UUID +
                          "Timestamp =" + CreateDate +
                          "MerchantId =" + "'1001'" +
                          "Invoice =" + "{" +
                          "Students =" + "[" +
                          "{" +
                          "Id =" + SSN +
                          "FirstName =" + FirstName +
                          "LastName =" + LastName +
                          "}" +
                          "]," +
                          "InvoiceId =" + InvoiceId +
                          "PayeeId =" + Student_id +
                          "InvoiceStatus =" + "BillNew" +
                          "BillType =" + "OneTime" +
                          "DisplayInfo =" + DisplayInfo +
                          "AmountDue =" + amount +
                          "CreateDate =" + CreateDate +
                          "ExpiryDate =" + ExpiryDate +
                          "PaymentRange =" + "{" +
                          "MinPartialAmount =" + amount + "," +
                          "MinAdvanceAmount =" + amount + "," +
                          "MaxAdvanceAmount =" + amount +
                          "}" +
                          "}";

            string url = "";//https://test.oppwa.com/v1/checkouts;

            byte[]         buffer  = Encoding.ASCII.GetBytes(data);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

            request.Method = "POST";
            request.Headers["Authorization"] = "Bearer OGFjN2E0Yzg3Mjg0ZjZjOTAxNzI4ZTYxMTI5YjE1MGF8TldCblpGNUdUYg==";
            request.ContentType = "application/x-www-form-urlencoded";
            Stream PostData = request.GetRequestStream();

            PostData.Write(buffer, 0, buffer.Length);
            PostData.Close();
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream       dataStream = response.GetResponseStream();
                StreamReader reader     = new StreamReader(dataStream);
                var          s          = new JavaScriptSerializer();
                responseData = s.Deserialize <Dictionary <string, dynamic> >(reader.ReadToEnd());
                reader.Close();
                dataStream.Close();
            }

            if (responseData["Status"]["Code"] == 0)
            {
                Rosom_Request Rosom = db.Rosom_Request.Create();
                Rosom.Trackingkey = Trackingkey;
                Rosom.PaymentType = 4;
                Rosom.CreateDate  = DateTime.Now.ToString();
                Rosom.MerchantId  = "1001";
                Rosom.Timestamp   = CreateDate;
                Rosom.UUID        = UUID;
                Rosom.Invoice_Students_FirstName = FirstName;
                Rosom.Invoice_Students_LastName  = LastName;
                Rosom.InvoiceId   = InvoiceId;
                Rosom.DisplayInfo = DisplayInfo;
                Rosom.AmountDue   = amount;
                Rosom.CreateDate  = CreateDate;
                Rosom.ExpiryDate  = ExpiryDate;
                Rosom.PaymentRange_MaxAdvanceAmount = amount;
                Rosom.PaymentRange_MinAdvanceAmount = amount;
                Rosom.PaymentRange_MinPartialAmount = amount;
                db.Rosom_Request.Add(Rosom);
                db.SaveChanges();
            }
            return(responseData);
        }