use of alfio.manager.support.PaymentResult 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());
}
use of alfio.manager.support.PaymentResult 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());
}
use of alfio.manager.support.PaymentResult in project alf.io by alfio-event.
the class TicketReservationManagerTest method handleOfflinePaymentMethod.
@Test
void handleOfflinePaymentMethod() {
when(ticketReservationRepository.findOptionalStatusAndValidationById(eq(RESERVATION_ID))).thenReturn(Optional.of(new TicketReservationStatusAndValidation(PENDING, true)));
initConfirmReservation();
when(ticketReservationRepository.postponePayment(eq(RESERVATION_ID), eq(OFFLINE_PAYMENT), any(Date.class), anyString(), anyString(), isNull(), isNull(), anyString(), isNull())).thenReturn(1);
when(ticketReservation.getPromoCodeDiscountId()).thenReturn(null);
when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
BankTransferManager bankTransferManager = mock(BankTransferManager.class);
when(bankTransferManager.accept(eq(PaymentMethod.BANK_TRANSFER), any(), any())).thenReturn(true);
when(paymentManager.streamActiveProvidersByProxy(eq(PaymentProxy.OFFLINE), any())).thenReturn(Stream.of(bankTransferManager));
when(bankTransferManager.getTokenAndPay(any())).thenReturn(PaymentResult.successful(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID));
PaymentSpecification spec = new PaymentSpecification(RESERVATION_ID, new StripeCreditCardToken(GATEWAY_TOKEN), 100, event, "test@email", new CustomerName("Full Name", null, null, event.mustUseFirstAndLastName()), "", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
var invoiceNumber = "1234";
when(billingDocumentManager.generateInvoiceNumber(eq(spec), any())).thenReturn(Optional.of(invoiceNumber));
PaymentResult result = trm.performPayment(spec, new TotalPrice(100, 0, 0, 0, "CHF"), PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
Assertions.assertTrue(result.isSuccessful());
Assertions.assertEquals(Optional.of(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID), result.getGatewayId());
verify(waitingQueueManager, never()).fireReservationConfirmed(eq(RESERVATION_ID));
verify(ticketReservationRepository).findReservationByIdForUpdate(eq(RESERVATION_ID));
verify(billingDocumentManager).generateInvoiceNumber(eq(spec), any());
verify(ticketReservationRepository).setInvoiceNumber(RESERVATION_ID, invoiceNumber);
verify(ticketReservationRepository).updateBillingData(eq(PriceContainer.VatStatus.INCLUDED), eq(100), eq(100), eq(0), eq(0), eq(EVENT_CURRENCY), eq("123456"), eq("IT"), eq(true), eq(RESERVATION_ID));
}
use of alfio.manager.support.PaymentResult in project alf.io by alfio-event.
the class StripeManagerTest method stripeError.
@Test
void stripeError() {
BaseStripeManager baseStripeManager = new BaseStripeManager(configurationManager, configurationRepository, ticketRepository, mock(Environment.class)) {
@Override
protected Optional<Charge> charge(PaymentSpecification spec, Map<String, Object> chargeParams) throws StripeException {
throw new AuthenticationException("401", "42", "401", 401);
}
};
StripeCreditCardManager stripeCreditCardManager = new StripeCreditCardManager(transactionRepository, baseStripeManager, TestUtil.clockProvider());
PaymentSpecification spec = new PaymentSpecification("", new StripeCreditCardToken(""), 100, event, "", customerName);
PaymentResult result = stripeCreditCardManager.doPayment(spec);
assertEquals(result, PaymentResult.failed("error.STEP2_STRIPE_abort"));
}
Aggregations