Search in sources :

Example 6 with StripeCreditCardToken

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));
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) StripeCreditCardToken(alfio.model.transaction.token.StripeCreditCardToken) Test(org.junit.jupiter.api.Test)

Example 7 with StripeCreditCardToken

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"));
}
Also used : AuthenticationException(com.stripe.exception.AuthenticationException) PaymentResult(alfio.manager.support.PaymentResult) StripeCreditCardToken(alfio.model.transaction.token.StripeCreditCardToken) Charge(com.stripe.model.Charge) Environment(org.springframework.core.env.Environment) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

StripeCreditCardToken (alfio.model.transaction.token.StripeCreditCardToken)7 PaymentResult (alfio.manager.support.PaymentResult)6 Test (org.junit.jupiter.api.Test)6 Charge (com.stripe.model.Charge)3 Map (java.util.Map)3 Environment (org.springframework.core.env.Environment)3 MaybeConfiguration (alfio.manager.system.ConfigurationManager.MaybeConfiguration)2 ConfigurationKeyValuePathLevel (alfio.model.system.ConfigurationKeyValuePathLevel)1 AuthenticationException (com.stripe.exception.AuthenticationException)1 ZonedDateTime (java.time.ZonedDateTime)1