Search in sources :

Example 1 with PromoCodeDiscount

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());
}
Also used : ZoneId(java.time.ZoneId) PromoCodeDiscount(alfio.model.PromoCodeDiscount)

Example 2 with PromoCodeDiscount

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));
}
Also used : ZoneId(java.time.ZoneId) PromoCodeDiscount(alfio.model.PromoCodeDiscount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PromoCodeDiscount

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);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) SpecialPrice(alfio.model.SpecialPrice) PromoCodeDiscount(alfio.model.PromoCodeDiscount) ValidatedResponse(alfio.manager.support.response.ValidatedResponse)

Example 4 with PromoCodeDiscount

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);
}
Also used : Locale(java.util.Locale) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ReservationForm(alfio.controller.form.ReservationForm) PromoCodeDiscount(alfio.model.PromoCodeDiscount) TicketReservationModification(alfio.model.modification.TicketReservationModification)

Aggregations

PromoCodeDiscount (alfio.model.PromoCodeDiscount)4 ZoneId (java.time.ZoneId)3 ReservationForm (alfio.controller.form.ReservationForm)1 ValidatedResponse (alfio.manager.support.response.ValidatedResponse)1 SpecialPrice (alfio.model.SpecialPrice)1 TicketReservationModification (alfio.model.modification.TicketReservationModification)1 ZonedDateTime (java.time.ZonedDateTime)1 Locale (java.util.Locale)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1