public void Error_DifferentCustomerCompanyId() { var wrongCustomer = CreateCustomer("ttt", profiles[1]); var koszyk = new PaymentBasketDTO(); koszyk.CustomerId = wrongCustomer.GlobalId; koszyk.TotalPrice = 12.3m; var zakup = new PaymentDTO(); zakup.Count = 1; zakup.Product = entries[0].Reservations.ElementAt(0).Map <ProductDTO>(); koszyk.Payments.Add(zakup); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { koszyk = service.PaymentBasketOperation(data.Token, koszyk); }); Assert.AreEqual(profiles[0].GlobalId, koszyk.ProfileId); Assert.AreNotEqual(Guid.Empty, koszyk.GlobalId); var db = Session.Get <PaymentBasket>(koszyk.GlobalId); Assert.AreEqual(DateTime.UtcNow.Date, db.DateTime.Date); Assert.AreEqual(1, db.Payments.Count); }
public PaymentBasketDTO PaymentBasketOperation(Token token, PaymentBasketDTO koszyk) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new PaymentService(Session, securityInfo, Configuration); return(service.PaymentBasketOperation(koszyk)); }
public void PayForOneProductWithTwoCount() { var koszyk = new PaymentBasketDTO(); koszyk.CustomerId = customers[0].GlobalId; koszyk.TotalPrice = 30m; var zakup = new PaymentDTO(); zakup.Count = 2; zakup.Product = entries[3].Reservations.ElementAt(0).Map <ProductDTO>(); koszyk.Payments.Add(zakup); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { koszyk = service.PaymentBasketOperation(data.Token, koszyk); }); Assert.AreEqual(profiles[0].GlobalId, koszyk.ProfileId); Assert.AreNotEqual(Guid.Empty, koszyk.GlobalId); var db = Session.Get <PaymentBasket>(koszyk.GlobalId); Assert.AreEqual(DateTime.UtcNow.Date, db.DateTime.Date); Assert.AreEqual(1, db.Payments.Count); }
public PaymentBasketDTO PaymentBasketOperation(PaymentBasketDTO koszyk) { if (koszyk.GlobalId != Guid.Empty) { throw new InvalidOperationException("This koszyk is already paid"); } decimal totalSum = 0; var db = koszyk.Map <PaymentBasket>(); using (var trans = Session.BeginSaveTransaction()) { var dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); db.Customer = Session.Get <Customer>(koszyk.CustomerId); if (db.Customer != null && db.Customer.Profile != dbProfile) { throw new CrossProfileOperationException(); } db.DateTime = Configuration.TimerService.UtcNow; db.Profile = dbProfile; foreach (var zakupDto in koszyk.Payments) { var zakup = zakupDto.Map <Payment>(); zakup.Product = Session.Get <Product>(zakupDto.Product.GlobalId); if (zakup.Product.Profile != dbProfile) { throw new CrossProfileOperationException(); } if (zakup.Product.Payment != null) {//gdy po pobraniu produktu on juz ma jakis Zakup to znaczy ze jest już zapłacony! throw new ProductAlreadyPaidException(); } if (zakup.DateTime == DateTime.MinValue) { zakup.DateTime = Configuration.TimerService.UtcNow; } zakup.PaymentBasket = db; zakup.Product.Payment = zakup; db.Payments.Add(zakup); totalSum += zakup.Count * zakup.Product.Price; } if (totalSum != koszyk.TotalPrice) { throw new ConsistencyException(); } db = Session.Merge(db); trans.Commit(); } return(db.Map <PaymentBasketDTO>()); }
public void PayForReservation() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); ScheduleEntryReservationDTO reservation = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { ReservationsOperationParam param = new ReservationsOperationParam(); param.CustomerId = customers[0].GlobalId; param.EntryId = entries[0].GlobalId; param.OperationType = ReservationsOperationType.Make; reservation = service.ReservationsOperation(data.Token, param).Reservation; }); var koszyk = new PaymentBasketDTO(); koszyk.CustomerId = customers[0].GlobalId; koszyk.TotalPrice = 20m; var zakup = new PaymentDTO(); zakup.Count = 1; zakup.Product = reservation; koszyk.Payments.Add(zakup); RunServiceMethod(delegate(InternalBodyArchitectService service) { koszyk = service.PaymentBasketOperation(data.Token, koszyk); }); Assert.AreEqual(koszyk.GlobalId, koszyk.Payments[0].PaymentBasketId); GetScheduleEntriesParam param1 = new GetScheduleEntriesParam(); param1.EntryId = entries[0].GlobalId; RunServiceMethod(delegate(InternalBodyArchitectService service) { var entryData = service.GetScheduleEntries(data.Token, param1, new PartialRetrievingInfo()); Assert.IsTrue(entryData.Items[0].Reservations.ElementAt(0).IsPaid); }); var dbZakup = Session.Get <Payment>(koszyk.Payments[0].GlobalId); Assert.Greater(dbZakup.DateTime, DateTime.MinValue); }
public void Error_DifferentProductCompanyId() { var koszyk = new PaymentBasketDTO(); koszyk.CustomerId = customers[0].GlobalId; koszyk.TotalPrice = 12.3m; var zakup = new PaymentDTO(); zakup.Count = 1; zakup.Product = zakup.Product = entries[2].Reservations.ElementAt(0).Map <ProductDTO>(); koszyk.Payments.Add(zakup); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { koszyk = service.PaymentBasketOperation(data.Token, koszyk); }); }
public void PayForAlreadyPaidProduct() { var zakup = CreatePayment(entries[0].Reservations.ElementAt(0), profiles[0]); insertToDatabase(zakup); var koszyk = new PaymentBasketDTO(); koszyk.CustomerId = customers[0].GlobalId; koszyk.TotalPrice = 10m; var zakupdto = new PaymentDTO(); zakupdto.Count = 1; zakupdto.Product = entries[0].Reservations.ElementAt(0).Map <ProductDTO>(); koszyk.Payments.Add(zakupdto); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { koszyk = service.PaymentBasketOperation(data.Token, koszyk); }); }
public void MarkAsPaid() { SelectedAppointment.IsRunning = true; parentView.RunAsynchronousOperation(delegate { try { PaymentBasketDTO basket = new PaymentBasketDTO(); PaymentDTO payment = new PaymentDTO(); payment.Product = SelectedReservation.Reservation; payment.Count = 1; payment.Price = SelectedReservation.Reservation.Price; basket.Payments.Add(payment); basket.TotalPrice = payment.Price; basket = ServiceManager.PaymentBasketOperation(basket); var newReservation = new ScheduleEntryReservationViewModel((ScheduleEntryReservationDTO)basket.Payments[0].Product); parentView.SynchronizationContext.Send(delegate { SelectedAppointment.IsRunning = false; Reservations.Remove(SelectedReservation); Reservations.Add(newReservation); SelectedReservation = newReservation; }, null); } catch (Exception ex) { parentView.SynchronizationContext.Send( delegate { SelectedAppointment.IsRunning = false; ExceptionHandler.Default.Process(ex, "Exception_ScheduleEntriesDesignViewModel_MarkAsPaid".TranslateInstructor(), ErrorWindow.EMailReport); }, null); } }); }
public PaymentBasketDTO PaymentBasketOperation(Token token, PaymentBasketDTO koszyk) { return(exceptionHandling(token, () => InternalService.PaymentBasketOperation(token, koszyk))); }