Search in sources :

Example 6 with PaymentSpecification

use of alfio.manager.payment.PaymentSpecification in project alf.io by alfio-event.

the class WaitingQueueManagerIntegrationTest method testAssignTicketToWaitingQueueUnboundedCategory.

@Test
void testAssignTicketToWaitingQueueUnboundedCategory() {
    LocalDateTime start = LocalDateTime.now(clockProvider.getClock()).minusMinutes(1);
    LocalDateTime end = LocalDateTime.now(clockProvider.getClock()).plusMinutes(20);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()), new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
    TicketCategory unbounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
    TicketReservationModification tr = new TicketReservationModification();
    tr.setQuantity(AVAILABLE_SEATS - 1);
    tr.setTicketCategoryId(unbounded.getId());
    TicketReservationModification tr2 = new TicketReservationModification();
    tr2.setQuantity(1);
    tr2.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification(tr2, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(multi), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCost = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    PaymentSpecification specification = new PaymentSpecification(reservationId, null, reservationCost.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult result = ticketReservationManager.performPayment(specification, reservationCost, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(result.isSuccessful());
    String reservationIdSingle = ticketReservationManager.createTicketReservation(event, Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscountSingle = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCostSingle = priceAndDiscountSingle.getLeft();
    assertTrue(priceAndDiscountSingle.getRight().isEmpty());
    specification = new PaymentSpecification(reservationIdSingle, null, reservationCostSingle.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult resultSingle = ticketReservationManager.performPayment(specification, reservationCostSingle, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(resultSingle.isSuccessful());
    assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation());
    assertTrue(waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));
    ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false, false, null);
    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager.distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
    Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions.get(0);
    assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress());
    TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle();
    assertEquals(Integer.valueOf(unbounded.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getQuantity());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now(clockProvider.getClock())));
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) Triple(org.apache.commons.lang3.tuple.Triple) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) PaymentSpecification(alfio.manager.payment.PaymentSpecification) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with PaymentSpecification

use of alfio.manager.payment.PaymentSpecification in project alf.io by alfio-event.

the class WaitingQueueManagerIntegrationTest method testAssignTicketToWaitingQueueBoundedCategory.

@Test
void testAssignTicketToWaitingQueueBoundedCategory() {
    LocalDateTime start = LocalDateTime.now(clockProvider.getClock()).minusMinutes(2);
    LocalDateTime end = LocalDateTime.now(clockProvider.getClock()).plusMinutes(20);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()), new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
    TicketCategory bounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
    TicketReservationModification tr = new TicketReservationModification();
    tr.setQuantity(AVAILABLE_SEATS - 1);
    tr.setTicketCategoryId(bounded.getId());
    TicketReservationModification tr2 = new TicketReservationModification();
    tr2.setQuantity(1);
    tr2.setTicketCategoryId(bounded.getId());
    TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification(tr2, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(multi), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCost = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    PaymentSpecification specification = new PaymentSpecification(reservationId, null, reservationCost.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult result = ticketReservationManager.performPayment(specification, reservationCost, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(result.isSuccessful());
    String reservationIdSingle = ticketReservationManager.createTicketReservation(event, Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscountSingle = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCostSingle = priceAndDiscountSingle.getLeft();
    assertTrue(priceAndDiscountSingle.getRight().isEmpty());
    specification = new PaymentSpecification(reservationIdSingle, null, reservationCostSingle.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult resultSingle = ticketReservationManager.performPayment(specification, reservationCostSingle, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(resultSingle.isSuccessful());
    assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation());
    assertTrue(waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));
    ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false, false, null);
    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager.distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
    Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions.get(0);
    assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress());
    TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle();
    assertEquals(Integer.valueOf(bounded.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getQuantity());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now(clockProvider.getClock())));
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) Triple(org.apache.commons.lang3.tuple.Triple) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) PaymentSpecification(alfio.manager.payment.PaymentSpecification) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with PaymentSpecification

use of alfio.manager.payment.PaymentSpecification in project alf.io by alfio-event.

the class WaitingQueueManagerIntegrationTest method reserveTickets.

private String reserveTickets(Event event, TicketCategory category, int num) {
    TicketReservationModification tr = new TicketReservationModification();
    tr.setQuantity(num);
    tr.setTicketCategoryId(category.getId());
    TicketReservationWithOptionalCodeModification tcm = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(tcm), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCost = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    PaymentSpecification specification = new PaymentSpecification(reservationId, null, reservationCost.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult result = ticketReservationManager.performPayment(specification, reservationCost, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(result.isSuccessful());
    return reservationId;
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) PaymentSpecification(alfio.manager.payment.PaymentSpecification)

Example 9 with PaymentSpecification

use of alfio.manager.payment.PaymentSpecification in project alf.io by alfio-event.

the class WaitingQueueManagerIntegrationTest method testWaitingQueueForUnboundedCategory.

@Test
void testWaitingQueueForUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(clockProvider.getClock()), LocalTime.now(clockProvider.getClock())), new DateTimeModification(LocalDate.now(clockProvider.getClock()), LocalTime.now(clockProvider.getClock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
    TicketCategory unbounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
    TicketReservationModification tr = new TicketReservationModification();
    tr.setQuantity(AVAILABLE_SEATS);
    tr.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.<String>empty(), Locale.ENGLISH, false, null);
    var reservation = ticketReservationManager.findById(reservationId).orElseThrow();
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCost = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    var orderSummary = ticketReservationManager.orderSummaryForReservation(reservation, event);
    PaymentSpecification spec = new PaymentSpecification(reservationId, null, reservationCost.getPriceWithVAT(), event, "blabla", new CustomerName("a", "b", "c", true), "", null, Locale.ENGLISH, false, false, orderSummary, null, null, PriceContainer.VatStatus.INCLUDED, true, true);
    PaymentResult result = ticketReservationManager.performPayment(spec, reservationCost, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(result.isSuccessful());
    assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation());
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) PaymentSpecification(alfio.manager.payment.PaymentSpecification) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with PaymentSpecification

use of alfio.manager.payment.PaymentSpecification in project alf.io by alfio-event.

the class TicketReservationManagerIntegrationTest method deferredOfflinePayment.

@Test
void deferredOfflinePayment() {
    // enable deferred payment
    configurationRepository.insert(DEFERRED_BANK_TRANSFER_ENABLED.name(), "true", "");
    List<TicketCategoryModification> categories = List.of(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Pair<Event, String> eventAndUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = eventAndUsername.getKey();
    TicketCategory unbounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
    TicketReservationModification trForDeferred = new TicketReservationModification();
    trForDeferred.setQuantity(1);
    trForDeferred.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification modForDeferred = new TicketReservationWithOptionalCodeModification(trForDeferred, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modForDeferred), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice totalPrice = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    PaymentSpecification specificationDeferred = new PaymentSpecification(reservationId, null, totalPrice.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult confirm = ticketReservationManager.performPayment(specificationDeferred, totalPrice, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(confirm.isSuccessful());
    var status = ticketReservationRepository.findOptionalStatusAndValidationById(reservationId).orElseThrow().getStatus();
    assertEquals(TicketReservation.TicketReservationStatus.DEFERRED_OFFLINE_PAYMENT, status);
    // confirm deferred payment
    ticketReservationManager.confirmOfflinePayment(event, reservationId, null);
    reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modForDeferred), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    specificationDeferred = new PaymentSpecification(reservationId, null, totalPrice.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    confirm = ticketReservationManager.performPayment(specificationDeferred, totalPrice, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(confirm.isSuccessful());
    try {
        ticketReservationManager.deleteOfflinePayment(event, reservationId, false, true, null);
        fail("Credit should not be enabled for deferred payments");
    } catch (IllegalArgumentException ex) {
    // do nothing, because this is the expected behavior
    }
    ticketReservationManager.deleteOfflinePayment(event, reservationId, false, false, null);
    assertFalse(ticketReservationManager.findById(reservationId).isPresent());
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) LocalDate(java.time.LocalDate) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) PaymentSpecification(alfio.manager.payment.PaymentSpecification) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PaymentSpecification (alfio.manager.payment.PaymentSpecification)10 PaymentResult (alfio.manager.support.PaymentResult)9 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 BaseIntegrationTest (alfio.util.BaseIntegrationTest)7 LocalDate (java.time.LocalDate)5 IntegrationTestUtil.initEvent (alfio.test.util.IntegrationTestUtil.initEvent)4 Triple (org.apache.commons.lang3.tuple.Triple)3 TestConfiguration (alfio.TestConfiguration)2 DataSourceConfiguration (alfio.config.DataSourceConfiguration)2 Initializer (alfio.config.Initializer)2 UserManager (alfio.manager.user.UserManager)2 alfio.model (alfio.model)2 AlfioMetadata (alfio.model.metadata.AlfioMetadata)2 alfio.model.modification (alfio.model.modification)2 DateTimeModification.fromZonedDateTime (alfio.model.modification.DateTimeModification.fromZonedDateTime)2 PaymentMethod (alfio.model.transaction.PaymentMethod)2 PaymentProxy (alfio.model.transaction.PaymentProxy)2 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)2 OrganizationRepository (alfio.repository.user.OrganizationRepository)2