protected Dictionary <string, Object> getJson(FraisLocation item) { var json = new Dictionary <string, Object>(); if (item == null) { return(null); } json.Add("id", item.id); json.Add("Ins_id", item.Ins_id); json.Add("Ins_id2", item.Ins_id2); json.Add("libelle", item.libelle); json.Add("name", item.libelle); json.Add("montant", item.montant); json.Add("avance", item.avance); json.Add("reste", item.reste); json.Add("type", item.type); json.Add("etat", item.etat); json.Add("status", item.status); json.Add("userId", item.userId); json.Add("created", item.created.HasValue ? item.created.Value.ToString("dd/MM/yyyy HH:mm") : null); json.Add("created_format", item.created.HasValue ? Utils.dateFullMonth(item.created.Value) : null); json.Add("location", getJson(item.Location)); return(json); }
public async Task <JsonResult> contratLocationClient(String stripeToken, decimal idLocation) { if (_me == null) { return(Json(new { result_code = -1000, message = "Session expired" }, JsonRequestBehavior.AllowGet)); } if (_me.Equals("candidat")) { return(Json(new { result_code = -1, message = "Your are not allowed" }, JsonRequestBehavior.AllowGet)); } Location currentLocation = db.Location.FirstOrDefault(p => p.id == idLocation); if (currentLocation == null) { return(Json(new { result_code = -1, message = "item not found" }, JsonRequestBehavior.AllowGet)); } StripeConfiguration.SetApiKey(STRIPE_API_KEY); var amount = (long)Math.Ceiling(currentLocation.remuneration.Value) * 35 / 100; var stripeOptions = new ChargeCreateOptions { Amount = (long)amount, // 1 dollar is equal to 100 cent. Currency = "USD", Description = "Charge for payment of 35% of Location", Source = stripeToken, }; var service = new ChargeService(); currentLocation.dateSgnClt = DateTime.Now; currentLocation.avisClient = 2; currentLocation.signClient = 2; db.Entry(currentLocation).State = EntityState.Modified; FraisLocation fraisLocation = new FraisLocation(); fraisLocation.archived = 1; fraisLocation.avance = amount; fraisLocation.created = DateTime.Now; fraisLocation.etat = 0; //TODO mettre le bon etat fraisLocation.Ins_id = currentLocation.Ins_id; fraisLocation.Ins_id2 = currentLocation.Ins_id2; fraisLocation.Loc_id = currentLocation.id; fraisLocation.libelle = "Paiement de 35% pour la location"; fraisLocation.montant = Convert.ToDouble(currentLocation.remuneration); fraisLocation.userId = (int)_me.id; fraisLocation.reste = Convert.ToDouble(currentLocation.remuneration) - amount; fraisLocation.status = 0; //TODO mettre le bon status je suppose o veut dire non achevé db.FraisLocation.Add(fraisLocation); try { Charge charge = service.Create(stripeOptions); var map = new Dictionary <String, String>(); map.Add("@ViewBag.titre", "Paiement de 35% du salaire pour la location de l'employé " + currentLocation.Inscrire.nom); map.Add("@ViewBag.login", _me.nom); map.Add("@ViewBag.content", "Votre paiement a bien été pris en compte. Le montant à été prélever de votre compte avec succès. Bénéficiez du meilleur de nos service."); string body = MsMail.BuldBodyTemplate("~/EmailTemplate/CustomEmail.cshtml", map); var map1 = new Dictionary <String, String>(); map1.Add("@ViewBag.titre", "Vous êtes sollicité pour un travail "); map1.Add("@ViewBag.login", currentLocation.Inscrire.nom); map1.Add("@ViewBag.content", "Votre demande de location a été confimer. Vous êtes conviez a prendre service le plutôt possible."); string body2 = MsMail.BuldBodyTemplate("~/EmailTemplate/CustomEmail.cshtml", map1); MsMail mail = new MsMail(); MsMail mail2 = new MsMail(); db.SaveChanges(); //TODO retraviller le mail avec du HTML await mail.Send(_me.email, "Paiement location", body); await mail2.Send(currentLocation.Inscrire.email, "NiovarJobs, Demande location accepté ", body2); //TODO rediriger a la liste des candidatures return(Json(new { result_code = 1, data = getJson(currentLocation) }, JsonRequestBehavior.AllowGet)); } catch (StripeException e) { return(Json(new { result_code = -2, message = "An execption occured" }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> contratLocationClient(String stripeToken, decimal idLocation) { Location currentLocation = db.Location.FirstOrDefault(p => p.id == idLocation); if (currentLocation == null) { TempData["result_code"] = -1; TempData["message"] = "Temps fourni pour le payment est expiré veuillez réessayer."; TempData.Keep(); //TODO rediriger a la liste des candidatures return(RedirectToAction("mesDemandeLocation")); } Inscrire candidat = db.Inscrire.Where(p => p.id == currentLocation.Ins_id).First(); if (candidat == null) { return(HttpNotFound()); } Inscrire client = db.Inscrire.Where(p => p.id == currentLocation.Ins_id2).First(); if (client == null) { return(HttpNotFound()); } if (String.IsNullOrEmpty(stripeToken)) { return(HttpNotFound()); } StripeConfiguration.SetApiKey("sk_test_51Gx6jgIK0UhIWHGbs9dcTW7tyGLkl39s6waxls9Z5D8E0arsL4bjy9N0g563Tlzo5JNvbeFOkAl5fMEY85eerPIx00mYJFiqLY"); var stripeOptions = new ChargeCreateOptions { Amount = (long)Math.Ceiling(currentLocation.remuneration.Value) * 35 / 100, // 1 dollar is equal to 100 cent. Currency = "USD", Description = "Charge for payment of 35% of Location", Source = stripeToken, //Customer = customer.Id }; var service = new ChargeService(); if (Session["id"] == null) { return(HttpNotFound()); } int idUserSession = Convert.ToInt32(Session["id"]); currentLocation.dateSgnClt = DateTime.Now; currentLocation.avisClient = 2; currentLocation.signClient = 2; db.Entry(currentLocation).State = EntityState.Modified; double amount = (long)Math.Ceiling(currentLocation.remuneration.Value) * 35 / 100; FraisLocation fraisLocation = new FraisLocation(); fraisLocation.archived = 1; fraisLocation.avance = amount; fraisLocation.created = DateTime.Now; fraisLocation.etat = 0; //TODO mettre le bon etat fraisLocation.Ins_id = candidat.id; fraisLocation.Ins_id2 = client.id; fraisLocation.Loc_id = currentLocation.id; fraisLocation.libelle = "Paiement de 35% pour la location"; fraisLocation.montant = Convert.ToDouble(currentLocation.remuneration); fraisLocation.userId = idUserSession; fraisLocation.reste = Convert.ToDouble(currentLocation.remuneration) - amount; fraisLocation.status = 0; //TODO mettre le bon status je suppose o veut dire non achevé db.FraisLocation.Add(fraisLocation); try { Charge charge = service.Create(stripeOptions); var map = new Dictionary <String, String>(); map.Add("@ViewBag.titre", "Paiement de 35% du salaire pour la location de l'employé " + candidat.login); map.Add("@ViewBag.login", client.login); map.Add("@ViewBag.content", "Votre paiement a bien été pris en compte. Le montant à été prélever de votre compte avec succès. Bénéficiez du meilleur de nos service."); string body = MsMail.BuldBodyTemplate("~/EmailTemplate/CustomEmail.cshtml", map); var map1 = new Dictionary <String, String>(); map1.Add("@ViewBag.titre", "Vous êtes sollicité pour un travail "); map1.Add("@ViewBag.login", candidat.login); map1.Add("@ViewBag.content", "Votre demande de location a été confimer. Vous êtes conviez a prendre service le plutôt possible."); string body2 = MsMail.BuldBodyTemplate("~/EmailTemplate/CustomEmail.cshtml", map1); MsMail mail = new MsMail(); MsMail mail2 = new MsMail(); db.SaveChanges(); //TODO retraviller le mail avec du HTML await mail.Send(client.email, "Paiement location", body); await mail2.Send(candidat.email, "NiovarJobs, Demande location accepté ", body2); //TODO rediriger a la liste des candidatures return(RedirectToAction("mesDemandeLocation")); } catch (StripeException e) { // throw; return(RedirectToAction("contratLocationClient", new { id = currentLocation.id })); } return(RedirectToAction("contratLocationClient", new { id = currentLocation.id })); }