use of alfio.model.PromoCodeDiscount in project alf.io by alfio-event.
the class PromoCodeDiscountApiController method updatePromoCode.
@PostMapping("/promo-code/{promoCodeId}")
public void updatePromoCode(@PathVariable("promoCodeId") int promoCodeId, @RequestBody PromoCodeDiscountModification promoCode) {
PromoCodeDiscount pcd = promoCodeRepository.findById(promoCodeId);
ZoneId zoneId = zoneIdFromEventId(pcd.getEventId(), promoCode.getUtcOffset());
eventManager.updatePromoCode(promoCodeId, promoCode.getStart().toZonedDateTime(zoneId), promoCode.getEnd().toZonedDateTime(zoneId), promoCode.getMaxUsage(), promoCode.getCategories(), promoCode.getDescription(), promoCode.getEmailReference(), promoCode.getHiddenCategoryId());
}
use of alfio.model.PromoCodeDiscount in project alf.io by alfio-event.
the class PromoCodeDiscountApiController method updatePromocode.
@RequestMapping(value = "/promo-code/{promoCodeId}", method = POST)
public void updatePromocode(@PathVariable("promoCodeId") int promoCodeId, @RequestBody PromoCodeDiscountModification promoCode) {
PromoCodeDiscount pcd = promoCodeRepository.findById(promoCodeId);
ZoneId zoneId = zoneIdFromEventId(pcd.getEventId(), promoCode.getUtcOffset());
eventManager.updatePromoCode(promoCodeId, promoCode.getStart().toZonedDateTime(zoneId), promoCode.getEnd().toZonedDateTime(zoneId));
}
use of alfio.model.PromoCodeDiscount in project alf.io by alfio-event.
the class PromoCodeRequestManager method checkCode.
public ValidatedResponse<Pair<Optional<SpecialPrice>, Optional<PromoCodeDiscount>>> checkCode(Event event, String promoCode) {
ZoneId eventZoneId = event.getZoneId();
ZonedDateTime now = ZonedDateTime.now(clockProvider.withZone(eventZoneId));
Optional<String> maybeSpecialCode = Optional.ofNullable(StringUtils.trimToNull(promoCode));
Optional<SpecialPrice> specialCode = maybeSpecialCode.flatMap(specialPriceRepository::getByCode);
Optional<PromoCodeDiscount> promotionCodeDiscount = maybeSpecialCode.flatMap((trimmedCode) -> promoCodeRepository.findPublicPromoCodeInEventOrOrganization(event.getId(), trimmedCode));
var result = Pair.of(specialCode, promotionCodeDiscount);
var errorResponse = new ValidatedResponse<>(ValidationResult.failed(new ValidationResult.ErrorDescriptor("promoCode", ErrorsCode.STEP_1_CODE_NOT_FOUND, ErrorsCode.STEP_1_CODE_NOT_FOUND)), result);
//
if (specialCode.isPresent()) {
if (eventManager.getOptionalByIdAndActive(specialCode.get().getTicketCategoryId(), event.getId()).isEmpty()) {
return errorResponse;
}
if (specialCode.get().getStatus() != SpecialPrice.Status.FREE) {
return errorResponse;
}
} else if (promotionCodeDiscount.isPresent() && !promotionCodeDiscount.get().isCurrentlyValid(eventZoneId, now)) {
return errorResponse;
} else if (promotionCodeDiscount.isPresent() && isDiscountCodeUsageExceeded(promotionCodeDiscount.get())) {
return errorResponse;
} else if (promotionCodeDiscount.isEmpty()) {
return errorResponse;
}
return new ValidatedResponse<>(ValidationResult.success(), result);
}
use of alfio.model.PromoCodeDiscount in project alf.io by alfio-event.
the class PromoCodeRequestManager method makeSimpleReservation.
private Pair<Optional<String>, BindingResult> makeSimpleReservation(Event event, int ticketCategoryId, String promoCode, ServletWebRequest request, Optional<PromoCodeDiscount> promoCodeDiscount, Principal principal) {
Locale locale = RequestUtils.getMatchingLocale(request, event);
ReservationForm form = new ReservationForm();
form.setPromoCode(promoCode);
TicketReservationModification reservation = new TicketReservationModification();
reservation.setQuantity(1);
reservation.setTicketCategoryId(ticketCategoryId);
form.setReservation(Collections.singletonList(reservation));
var bindingRes = new BeanPropertyBindingResult(form, "reservationForm");
return Pair.of(createTicketReservation(form, bindingRes, event, locale, promoCodeDiscount.map(PromoCodeDiscount::getPromoCode), principal), bindingRes);
}
Aggregations