use of alfio.model.transaction.token.StripeCreditCardToken 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.model.transaction.token.StripeCreditCardToken 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