internal static CieloPaymentRequest ParsePaymentRequest(Order order) { var buyerName = MysqlClient.GetUserByIdInMysql(order.BuyerId.ToString()).Name; var request = new CieloPaymentRequest() { MerchantOrderId = Guid.NewGuid().ToString(), CustomerObj = new CieloPaymentRequest.Customer() { Name = buyerName }, PaymentObj = new CieloPaymentRequest.Payment() { Type = "CreditCard", Capture = true, Amount = order.Value, Installments = 1, CreditCard = new CieloPaymentRequest.CreditCard() { CardNumber = order.CardNumber, Holder = buyerName, ExpirationDate = order.ExpirationDate, SecurityCode = order.SecurityCode } } }; return(request); }
public void Post([FromBody] User user) { MysqlClient.InsertNewUserInMysql(user.Name, CryptoUtils.CryptoMD5.HashPassword(user.Password), user.Email, user.Address, user.Payment_id, user.Payment_key); }
public IActionResult DeleteCourse(int course_id) { TeacherCS teacherCS = new TeacherCS(); CourseServiceDecorator courseServiceDecorator = new CourseServiceDecorator(teacherCS); Course course = MysqlClient.getCourseById(course_id); courseServiceDecorator.DeleteCourse(1, course); return(Ok(db.Courses)); }
public List <Product> SearchProduct(string param, string type) { if (type.Equals("category")) { return(MysqlClient.SearchProductsByCategoryInMysql(param)); } return(MysqlClient.SearchProductsByNameInMysql(param)); }
public IActionResult DeleteNew(int user_id, int course_id) { StudentCS studentCS = new StudentCS(); CourseServiceDecorator courseServiceDecorator = new CourseServiceDecorator(studentCS); Course course = new Course(); course = MysqlClient.getCourseById(course_id); courseServiceDecorator.DeleteCourse(user_id, course); return(Ok(db.Scourses)); }
public void Put(string id, [FromBody] User user) { MysqlClient.UpdateUserInMysql(id, user.Name, user.Password, user.Email, user.Address, user.Payment_id, user.Payment_key); }
public List <Course> QueryCourse(int uid) { var allId = MysqlClient.getCourseByStu(uid); IEnumerable <Course> result = new List <Course>(); foreach (var i in allId) { result = result.Append(MysqlClient.getCourseById(i)); } return(result.ToList()); }
public void Post([FromBody] Order order) { var paymentResponse = CieloConnector.CieloClient.PostPayment(order); if (paymentResponse != null && paymentResponse.PaymentObj.Status == 2) { MysqlClient.InsertNewOrderInMysql(order.Value, order.ProductName, order.OwnerId, order.BuyerId, paymentResponse.MerchantOrderId); } else { throw new Exception("Error on trying approve payment."); } }
public static CieloPaymentResponse PostPayment(Order order) { using (var cancellationToken = new CancellationTokenSource(TimeSpan.FromMilliseconds(20000))) { try { var user = MysqlClient.GetUserByIdInMysql(order.OwnerId.ToString()); var endpoint = $"{CieloSandboxPostUrl}/1/sales/"; var request = ParsePaymentRequest(order); Console.WriteLine($"Request to: {endpoint}"); using (var httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromMilliseconds(15000); var requestContent = new StringContent(JsonConvert.SerializeObject(request)); requestContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); requestContent.Headers.Add("MerchantId", user.Payment_id); requestContent.Headers.Add("MerchantKey", user.Payment_key); var response = httpClient.PostAsync(endpoint, requestContent, cancellationToken.Token).Result; string content = response.Content.ReadAsStringAsync().Result; Console.WriteLine($"Response: {content}"); response.EnsureSuccessStatusCode(); return(JsonConvert.DeserializeObject <CieloPaymentResponse>(content)); } } catch (Exception ex) { var message = $"Error on trying send payment: {ex.Message} InnerException: {ex.InnerException}"; Console.WriteLine(message); } return(null); } }
public IActionResult AlterNew(int cid, string change, int type) { TeacherCS teacherCS = new TeacherCS(); CourseServiceDecorator courseServiceDecorator = new CourseServiceDecorator(teacherCS); Course course = MysqlClient.getCourseById(cid); switch (type) { case 0: course.CourseName = change; break; case 1: course.Progress = change; break; case 2: course.Kind = change; break; case 3: course.Representive = change; break; } courseServiceDecorator.AlterCourse(course, type); return(Ok(db.Courses)); }
public List <Course> QueryCourse(int uid) { return(MysqlClient.Query()); }
public void AlterCourse(Course course, int type) { MysqlClient.AlterRowInCource(course, type); }
public void DeleteCourse(int user_id, Course course) { MysqlClient.DeleteRowInCource(course.Id); }
public void AddCourse(int user_id, Course course) { MysqlClient.AddRowInCource(course); }
public List <Order> GetOrdersByBuyerId(string buyerid) { return(MysqlClient.GetOrdersByBuyerIdInMysql(buyerid)); }
public List <Course> GetAll() { return(MysqlClient.Query()); }
public List <User> Get() { return(MysqlClient.GetUsersInMysql()); }
public void Put(string id, [FromBody] Product product) { MysqlClient.UpdateProductInMysql(id, product.Name, product.ImageUrl, product.Description, product.Quantity.ToString(), product.Price.ToString(), product.OwnerId); }
public Order Get(string id) { return(MysqlClient.GetOrderByIdInMysql(id)); }
public void AddCourse(int user_id, Course course) { MysqlClient.AddRowInScource(user_id, course.Id); }
public void Delete(string id) { MysqlClient.DeleteOrderInMysql(id); }
public void Put(string id, [FromBody] Order order) { MysqlClient.UpdateOrderInMysql(id, order.Value, order.ProductName, order.OwnerId, order.BuyerId); }
public List <Product> Get() { return(MysqlClient.GetProductsInMysql()); }
public List <Order> Get() { return(MysqlClient.GetOrdersInMysql()); }
public Product Get(string id) { return(MysqlClient.GetProductByIdInMysql(id)); }
public User GetByEmail(string email) { var user = MysqlClient.GetUserByEmailInMysql(email); return(user); }
public void Post([FromBody] Product product) { MysqlClient.InsertNewProductInMysql(product.Name, product.ImageUrl, product.Description, product.Quantity.ToString(), product.Price.ToString(), product.OwnerId); }
public List <Order> GetOrdersByOwnerId(string ownerid) { return(MysqlClient.GetOrdersByOwnerIdInMysql(ownerid)); }
public void Delete(string id) { MysqlClient.DeleteProductInMysql(id); }
public int Resgister(int type, string id, string name, string e_mail, string academy, string special, string password, string nickname) { return(MysqlClient.Resgister(type, id, name, e_mail, academy, special, password, nickname)); }