Search in sources :

Example 1 with PaymentForm

use of alfio.controller.form.PaymentForm in project alf.io by alfio-event.

the class ReservationFlowIntegrationTest method payOffline.

private String payOffline(String eventName, String reservationIdentifier) {
    PaymentForm paymentForm = new PaymentForm();
    paymentForm.setPaymentMethod(PaymentProxy.OFFLINE);
    paymentForm.setEmail("test@test.com");
    paymentForm.setBillingAddress("my billing address");
    paymentForm.setFirstName("full");
    paymentForm.setLastName("name");
    paymentForm.setTermAndConditionsAccepted(true);
    paymentForm.setPostponeAssignment(true);
    BindingResult bindingResult = new BeanPropertyBindingResult(paymentForm, "paymentForm");
    Model model = new BindingAwareModelMap();
    MockHttpServletRequest request = new MockHttpServletRequest();
    RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
    return reservationController.handleReservation(eventName, reservationIdentifier, paymentForm, bindingResult, model, request, Locale.ENGLISH, redirectAttributes);
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) PaymentForm(alfio.controller.form.PaymentForm) Model(org.springframework.ui.Model) BindingAwareModelMap(org.springframework.validation.support.BindingAwareModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)

Example 2 with PaymentForm

use of alfio.controller.form.PaymentForm in project alf.io by alfio-event.

the class ReservationApiController method validateEUVat.

@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}/vat-validation", method = RequestMethod.POST)
@Transactional
public ResponseEntity<VatDetail> validateEUVat(@PathVariable("eventName") String eventName, @PathVariable("reservationId") String reservationId, PaymentForm paymentForm, Locale locale, HttpServletRequest request) {
    String country = paymentForm.getVatCountryCode();
    Optional<Triple<Event, TicketReservation, VatDetail>> vatDetail = eventRepository.findOptionalByShortName(eventName).flatMap(e -> ticketReservationRepository.findOptionalReservationById(reservationId).map(r -> Pair.of(e, r))).filter(e -> EnumSet.of(INCLUDED, NOT_INCLUDED).contains(e.getKey().getVatStatus())).filter(e -> vatChecker.isVatCheckingEnabledFor(e.getKey().getOrganizationId())).flatMap(e -> vatChecker.checkVat(paymentForm.getVatNr(), country, e.getKey().getOrganizationId()).map(vd -> Triple.of(e.getLeft(), e.getRight(), vd)));
    vatDetail.filter(t -> t.getRight().isValid()).ifPresent(t -> {
        VatDetail vd = t.getRight();
        String billingAddress = vd.getName() + "\n" + vd.getAddress();
        PriceContainer.VatStatus vatStatus = determineVatStatus(t.getLeft().getVatStatus(), t.getRight().isVatExempt());
        ticketReservationRepository.updateBillingData(vatStatus, vd.getVatNr(), country, paymentForm.isInvoiceRequested(), reservationId);
        OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, t.getLeft(), Locale.forLanguageTag(t.getMiddle().getUserLanguage()));
        ticketReservationRepository.addReservationInvoiceOrReceiptModel(reservationId, Json.toJson(orderSummary));
        ticketReservationRepository.updateTicketReservation(reservationId, t.getMiddle().getStatus().name(), paymentForm.getEmail(), paymentForm.getFullName(), paymentForm.getFirstName(), paymentForm.getLastName(), locale.getLanguage(), billingAddress, null, Optional.ofNullable(paymentForm.getPaymentMethod()).map(PaymentProxy::name).orElse(null));
        paymentForm.getTickets().forEach((ticketId, owner) -> {
            if (isNotEmpty(owner.getEmail()) && ((isNotEmpty(owner.getFirstName()) && isNotEmpty(owner.getLastName())) || isNotEmpty(owner.getFullName()))) {
                ticketHelper.preAssignTicket(eventName, reservationId, ticketId, owner, Optional.empty(), request, (tr) -> {
                }, Optional.empty());
            }
        });
    });
    return vatDetail.map(Triple::getRight).map(vd -> {
        if (vd.isValid()) {
            return ResponseEntity.ok(vd);
        } else {
            return new ResponseEntity<VatDetail>(HttpStatus.BAD_REQUEST);
        }
    }).orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ValidationResult(alfio.model.result.ValidationResult) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) PaymentProxy(alfio.model.transaction.PaymentProxy) TicketReservationRepository(alfio.repository.TicketReservationRepository) PaymentForm(alfio.controller.form.PaymentForm) BindingResult(org.springframework.validation.BindingResult) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) RequestContextUtils(org.springframework.web.servlet.support.RequestContextUtils) Json(alfio.util.Json) Model(org.springframework.ui.Model) HttpServletRequest(javax.servlet.http.HttpServletRequest) Pair(org.apache.commons.lang3.tuple.Pair) EuVatChecker(alfio.manager.EuVatChecker) UserDetails(org.springframework.security.core.userdetails.UserDetails) Triple(org.apache.commons.lang3.tuple.Triple) VatStatus(alfio.model.PriceContainer.VatStatus) TemplateManager(alfio.util.TemplateManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) EventRepository(alfio.repository.EventRepository) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) TicketReservationManager(alfio.manager.TicketReservationManager) alfio.model(alfio.model) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) I18nManager(alfio.manager.i18n.I18nManager) AllArgsConstructor(lombok.AllArgsConstructor) Authentication(org.springframework.security.core.Authentication) Transactional(org.springframework.transaction.annotation.Transactional) PaymentProxy(alfio.model.transaction.PaymentProxy) VatStatus(alfio.model.PriceContainer.VatStatus) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PaymentForm

use of alfio.controller.form.PaymentForm in project alf.io by alfio-event.

the class BillingDocumentCreationIntegrationTest method createReservation.

private String createReservation(Consumer<ContactAndTicketsForm> formCustomizer) {
    var categories = ticketCategoryRepository.findAllTicketCategories(event.getId());
    assertFalse(categories.isEmpty());
    int categoryId = categories.get(0).getId();
    var form = new ReservationForm();
    var ticketReservation = new TicketReservationModification();
    ticketReservation.setQuantity(1);
    ticketReservation.setTicketCategoryId(categoryId);
    form.setReservation(List.of(ticketReservation));
    var res = eventApiV2Controller.reserveTickets(event.getShortName(), "en", form, new BeanPropertyBindingResult(form, "reservation"), new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse()), null);
    assertEquals(HttpStatus.OK, res.getStatusCode());
    var resBody = res.getBody();
    assertNotNull(resBody);
    assertTrue(resBody.isSuccess());
    assertEquals(0, resBody.getErrorCount());
    var reservationId = resBody.getValue();
    // reservation is now in PENDING status
    var resInfoRes = reservationApiV2Controller.getReservationInfo(reservationId, null);
    assertEquals(HttpStatus.OK, resInfoRes.getStatusCode());
    assertNotNull(resInfoRes.getBody());
    var ticketsByCat = resInfoRes.getBody().getTicketsByCategory();
    assertEquals(1, ticketsByCat.size());
    assertEquals(1, ticketsByCat.get(0).getTickets().size());
    var ticket = ticketsByCat.get(0).getTickets().get(0);
    var contactForm = new ContactAndTicketsForm();
    contactForm.setAddCompanyBillingDetails(true);
    contactForm.setSkipVatNr(false);
    contactForm.setInvoiceRequested(true);
    contactForm.setEmail("test@test.com");
    contactForm.setFirstName("full");
    contactForm.setLastName("name");
    var ticketForm1 = new UpdateTicketOwnerForm();
    ticketForm1.setFirstName("ticketfull");
    ticketForm1.setLastName("ticketname");
    ticketForm1.setEmail("tickettest@test.com");
    formCustomizer.accept(contactForm);
    contactForm.setTickets(Map.of(ticket.getUuid(), ticketForm1));
    var success = reservationApiV2Controller.validateToOverview(reservationId, "en", false, contactForm, new BeanPropertyBindingResult(contactForm, "paymentForm"), null);
    assertEquals(HttpStatus.OK, success.getStatusCode());
    var paymentForm = new PaymentForm();
    paymentForm.setPrivacyPolicyAccepted(true);
    paymentForm.setTermAndConditionsAccepted(true);
    paymentForm.setPaymentProxy(PaymentProxy.OFFLINE);
    paymentForm.setSelectedPaymentMethod(PaymentMethod.BANK_TRANSFER);
    var handleRes = reservationApiV2Controller.confirmOverview(reservationId, "en", paymentForm, new BeanPropertyBindingResult(paymentForm, "paymentForm"), new MockHttpServletRequest(), null);
    assertEquals(HttpStatus.OK, handleRes.getStatusCode());
    return reservationId;
}
Also used : ContactAndTicketsForm(alfio.controller.form.ContactAndTicketsForm) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) PaymentForm(alfio.controller.form.PaymentForm) ReservationForm(alfio.controller.form.ReservationForm) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketReservationModification(alfio.model.modification.TicketReservationModification) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

PaymentForm (alfio.controller.form.PaymentForm)3 UpdateTicketOwnerForm (alfio.controller.form.UpdateTicketOwnerForm)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 Model (org.springframework.ui.Model)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindingResult (org.springframework.validation.BindingResult)2 TicketHelper (alfio.controller.api.support.TicketHelper)1 ContactAndTicketsForm (alfio.controller.form.ContactAndTicketsForm)1 ReservationForm (alfio.controller.form.ReservationForm)1 EuVatChecker (alfio.manager.EuVatChecker)1 TicketReservationManager (alfio.manager.TicketReservationManager)1 I18nManager (alfio.manager.i18n.I18nManager)1 alfio.model (alfio.model)1 VatStatus (alfio.model.PriceContainer.VatStatus)1 TicketReservationModification (alfio.model.modification.TicketReservationModification)1 ValidationResult (alfio.model.result.ValidationResult)1 PaymentProxy (alfio.model.transaction.PaymentProxy)1 EventRepository (alfio.repository.EventRepository)1 TicketReservationRepository (alfio.repository.TicketReservationRepository)1 Json (alfio.util.Json)1