// POST: api/Rosom
        public string Post([FromBody] Rosom_Response Rosom)
        {
            Rosom_Request rosom_resquest = db.Rosom_Request.Where(x => x.Response_SADADNumber == Rosom.SADADNumber).FirstOrDefault();

            if (rosom_resquest != null)
            {
                Rosom.Trackingkey        = rosom_resquest.Trackingkey;
                Rosom.Payment_Process_Id = rosom_resquest.Payment_Process_Id;
                Rosom.Rosom_Request_Id   = rosom_resquest.Id;
                db.Rosom_Response.Add(Rosom);
                db.SaveChanges();

                Payment_Process Pay_process = rosom_resquest.Payment_Process;
                Pay_process.Payment_IsPaid      = true;
                Pay_process.Payment_URL_IsValid = false;
                db.Entry(Pay_process).State     = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                Student std           = Pay_process.Student;
                int     new_Status_Id = (int)std.Student_Status_Id + 1;
                std.Student_Status_Id = new_Status_Id;
                db.Entry(std).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                // isnert new Sequences record to paid
                Sequence seq = db.Sequences.Create();
                seq.Emp_Id       = 1;
                seq.Status_Id    = new_Status_Id;
                seq.Student_Id   = std.Student_Id;
                seq.Note         = "Auto payment";
                seq.DateCreation = DateTime.Now;
                db.Sequences.Add(seq);
                db.SaveChanges();


                db.Configuration.LazyLoadingEnabled = false;
                /* Add it to log file */
                Student stdLogFile = db.Students.Find(std.Student_Id);
                stdLogFile.Employee = db.Employees.Find(seq.Emp_Id);
                stdLogFile.Status   = db.Status.Find(seq.Status_Id);

                LogData = "data:" + JsonConvert.SerializeObject(stdLogFile, logFileModule.settings);
                logFileModule.logfile(10, "تغير الحالة تلقائي", "Update Status Automatic", LogData);

                Payment_Process paymentLogFile = db.Payment_Process.Find(Pay_process.Payment_Id);
                LogData = "data:" + JsonConvert.SerializeObject(paymentLogFile, logFileModule.settings);
                logFileModule.logfile(10, "اضافة عملية دفع", "add payment process", LogData);

                return("{'Status': {'Code': 0,'Description': 'Success','Severity': 'Info'}}");
            }

            return("{'Status': {'Code': 2000,'Description': 'Bill not found','Severity': 'Info'}}");
        }
Example #2
0
        // POST: api/Rosom
        public string Post([FromBody] Rosom_Response Rosom)
        {
            try
            {
                Rosom_Request rosom_resquest = db.Rosom_Request.Where(x => x.Response_SADADNumber == Rosom.SADADNumber).FirstOrDefault();
                if (rosom_resquest != null)
                {
                    Rosom.Trackingkey        = rosom_resquest.Trackingkey;
                    Rosom.Payment_Process_Id = rosom_resquest.Payment_Process_Id;
                    Rosom.Rosom_Request_Id   = rosom_resquest.Id;
                    db.Rosom_Response.Add(Rosom);
                    //db.SaveChanges();

                    Payment_Process Pay_process = rosom_resquest.Payment_Process;
                    if (Pay_process.Payment_IsPaid == true && Pay_process.Payment_URL_IsValid == false)
                    {
                        return("{'Status': {'Code': 0,'Description': 'Success','Severity': 'Info'}}");
                    }

                    Pay_process.Payment_IsPaid      = true;
                    Pay_process.Payment_URL_IsValid = false;
                    db.Entry(Pay_process).State     = System.Data.EntityState.Modified;
                    db.SaveChanges();

                    Student std           = Pay_process.Student;
                    int     new_Status_Id = (int)std.Student_Status_Id + 1;
                    std.Student_Status_Id = new_Status_Id;
                    db.Entry(std).State   = System.Data.EntityState.Modified;
                    db.SaveChanges();

                    // isnert new Sequences record to paid
                    Sequence seq = db.Sequences.Create();
                    seq.Emp_Id       = 1;
                    seq.Status_Id    = new_Status_Id;
                    seq.Student_Id   = std.Student_Id;
                    seq.Note         = "Auto payment";
                    seq.DateCreation = DateTime.Now;
                    db.Sequences.Add(seq);
                    db.SaveChanges();


                    db.Configuration.LazyLoadingEnabled = false;
                    /* Add it to log file */
                    Student stdLogFile = db.Students.Find(std.Student_Id);
                    stdLogFile.Employee = db.Employees.Find(seq.Emp_Id);
                    stdLogFile.Status   = db.Status.Find(seq.Status_Id);

                    LogData = "data:" + JsonConvert.SerializeObject(stdLogFile, logFileModule.settings);
                    logFileModule.logfile(10, "تغير الحالة تلقائي", "Update Status Automatic", LogData);

                    Payment_Process paymentLogFile = db.Payment_Process.Find(Pay_process.Payment_Id);
                    LogData = "data:" + JsonConvert.SerializeObject(paymentLogFile, logFileModule.settings);
                    logFileModule.logfile(10, "اضافة عملية دفع", "add payment process", LogData);

                    bool            Make_Equation = false;
                    List <Sequence> seq_Check     = db.Sequences.Where(x => x.Student_Id == std.Student_Id && x.Status_Id == 1016).ToList(); // 1016 : Certificate Equation Completed
                    if (seq_Check.Count > 0)
                    {
                        Make_Equation = true;
                    }

                    // InCase if student not new
                    if (std.Student_Status_Id == 7 && std.Student_Type_Id != 1 && !Make_Equation)
                    {
                        try
                        {
                            // Update student record to Equation
                            int new_Status_Id_Tran = 19;//معادلة الشهادة
                            std.Student_Status_Id = new_Status_Id_Tran;
                            db.Entry(std).State   = System.Data.EntityState.Modified;
                            db.SaveChanges();

                            // isnert new Sequences record to paid
                            Sequence seq2 = db.Sequences.Create();
                            seq2.Emp_Id       = 1;
                            seq2.Status_Id    = new_Status_Id_Tran;
                            seq2.Student_Id   = std.Student_Id;
                            seq2.Note         = "Auto Transaction";
                            seq2.DateCreation = DateTime.Now;
                            db.Sequences.Add(seq2);
                            db.SaveChanges();


                            db.Configuration.LazyLoadingEnabled = false;
                            /* Add it to log file */
                            Student stdLogFile2 = db.Students.Find(std.Student_Id);
                            stdLogFile2.Employee = db.Employees.Find(seq2.Emp_Id);
                            stdLogFile2.Status   = db.Status.Find(seq2.Status_Id);

                            LogData = "data:" + JsonConvert.SerializeObject(stdLogFile2, logFileModule.settings);
                            logFileModule.logfile(10, "تغير الحالة تلقائي", "Update Status Automatic", LogData);
                        }
                        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 checkPayment Status", LogData);
                        }
                    }

                    return("{'Status': {'Code': 0,'Description': 'Success','Severity': 'Info'}}");
                }

                return("{'Status': {'Code': 2000,'Description': 'Bill not found','Severity': 'Info'}}");
            }
            catch (Exception er) { return("{'Status': {'Code': 2000,'Description': 'Bill not found','Severity': 'Info'}}"); }
        }
Example #3
0
        public 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 = "8ac7a4c87284f6c901728e6183ff150e";
                    }
                    else if (PaymentType.SelectedValue == "3")
                    {
                        Entity_ID = "8ac7a4c87284f6c901728e633a371512";
                    }

                    if (PaymentType.SelectedValue != "4")
                    {
                        Dictionary <string, dynamic> responseData =
                            Prepare_Check_Payment_Request(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")
                        {
                            string        InvoiceId = responseData["InvoiceId"];
                            Rosom_Request Rosom     = db.Rosom_Request.FirstOrDefault(x => x.Trackingkey == Trackingkey && x.InvoiceId == InvoiceId);
                            Rosom.Response_Status_Code = responseData["result"]["code"];
                            // Rosom. = responseData["result"]["description"];
                            Rosom.Response_SADADNumber = responseData["SADADNumber"];
                            Rosom.Result_JSON          = responseData.ToString();
                            db.Entry(Rosom).State      = System.Data.Entity.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 /> " + "Thank you for completed the application from at Riyadh Elm University. We will contact you within 48 hours." + " <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 " + checkout_payment.Student.Student_Name_En + "\n" + "Thank you for completed the application form at Riyadh Elm University. We will contact you within 48 hours." + " \n" + "Best Regard," + " \n" + "Admission System";
                            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
                    {
                        int studentID = 0;
                        int.TryParse(checkout_payment.Student_Id.ToString(), out studentID);
                        Dictionary <string, dynamic> responseData =
                            Prepare_Check_Payment_Request_SADAD(UUID, checkout_payment.Send_Amount.ToString(), checkout_payment.Student.Student_SSN, checkout_payment.Send_PaymentType, StudentFirstName.Text, StudentLastName.Text, studentID);
                        if (responseData["Status"]["Code"] == 0)
                        {
                            checkout_payment.Result_Code        = responseData["InvoiceId"];
                            checkout_payment.Result_Description = responseData["SADADNumber"];
                            checkout_payment.Result_BuildNumber = responseData["Status"]["Code"];
                            checkout_payment.Result_Timestamp   = responseData["Status"]["Description"];
                            checkout_payment.Result_Ndc         = responseData["Status"]["Severity"];
                            db.Entry(checkout_payment).State    = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            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 Checkout", LogData);
                return(false);
            }

            return(Response);
            /* End Prepare the checkout */
        }
        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 */
        }
Example #5
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);
        }