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);
}
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));
}
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;
}
Aggregations