Search in sources :

Example 1 with StripeCreditCardToken

use of alfio.model.transaction.token.StripeCreditCardToken in project alf.io by alfio-event.

the class TicketReservationManagerTest method handleOnSitePaymentMethod.

@Test
void handleOnSitePaymentMethod() {
    when(ticketReservationRepository.findOptionalStatusAndValidationById(eq(RESERVATION_ID))).thenReturn(Optional.of(new TicketReservationStatusAndValidation(PENDING, true)));
    initConfirmReservation();
    when(ticketRepository.updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.TO_BE_PAID.toString()))).thenReturn(1);
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(ZonedDateTime.class), eq(PaymentProxy.ON_SITE.toString()), isNull())).thenReturn(1);
    when(ticketReservationRepository.findOptionalReservationById(eq(RESERVATION_ID))).thenReturn(Optional.of(ticketReservation));
    when(configurationManager.getFor(eq(ENABLE_TICKET_TRANSFER), any())).thenReturn(new MaybeConfiguration(ENABLE_TICKET_TRANSFER));
    when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
    OnSiteManager onSiteManager = mock(OnSiteManager.class);
    when(onSiteManager.accept(eq(PaymentMethod.ON_SITE), any(), any())).thenReturn(true);
    when(paymentManager.streamActiveProvidersByProxy(eq(PaymentProxy.ON_SITE), any())).thenReturn(Stream.of(onSiteManager));
    when(ticketReservation.getPromoCodeDiscountId()).thenReturn(null);
    when(onSiteManager.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);
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), anyString(), anyString(), anyString(), isNull(), isNull(), eq(Locale.ENGLISH.getLanguage()), isNull(), any(), any(), isNull())).thenReturn(1);
    PaymentResult result = trm.performPayment(spec, new TotalPrice(100, 0, 0, 0, "CHF"), PaymentProxy.ON_SITE, PaymentMethod.ON_SITE, null);
    Assertions.assertTrue(result.isSuccessful());
    Assertions.assertEquals(Optional.of(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID), result.getGatewayId());
    verify(ticketReservationRepository).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(), eq(PaymentProxy.ON_SITE.toString()), isNull());
    verify(ticketReservationRepository).findReservationByIdForUpdate(eq(RESERVATION_ID));
    verify(ticketRepository).updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.TO_BE_PAID.toString()));
    verify(specialPriceRepository).updateStatusForReservation(eq(singletonList(RESERVATION_ID)), eq(SpecialPrice.Status.TAKEN.toString()));
    verify(waitingQueueManager).fireReservationConfirmed(eq(RESERVATION_ID));
    verify(ticketReservationRepository, atLeastOnce()).findReservationById(RESERVATION_ID);
    verify(billingDocumentManager).generateInvoiceNumber(eq(spec), any());
    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));
    verify(ticketRepository, atLeastOnce()).findTicketsInReservation(anyString());
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) StripeCreditCardToken(alfio.model.transaction.token.StripeCreditCardToken) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with StripeCreditCardToken

use of alfio.model.transaction.token.StripeCreditCardToken in project alf.io by alfio-event.

the class TicketReservationManagerTest method testPaidReservation.

private void testPaidReservation(boolean enableTicketTransfer, boolean expectSuccess, boolean expectCompleteReservation) {
    initConfirmReservation();
    when(configurationManager.getFor(eq(ENABLE_TICKET_TRANSFER), any())).thenReturn(new MaybeConfiguration(ENABLE_TICKET_TRANSFER, new ConfigurationKeyValuePathLevel(null, Boolean.toString(enableTicketTransfer), null)));
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(), eq(PaymentProxy.STRIPE.toString()), isNull())).thenReturn(1);
    when(ticketRepository.updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.ACQUIRED.toString()))).thenReturn(1);
    when(ticketReservation.getPromoCodeDiscountId()).thenReturn(null);
    when(ticketReservationRepository.findOptionalReservationById(eq(RESERVATION_ID))).thenReturn(Optional.of(ticketReservation));
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(IN_PAYMENT.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), isNull(), eq(PaymentProxy.STRIPE.toString()), isNull())).thenReturn(1);
    when(ticketRepository.findTicketsInReservation(eq(RESERVATION_ID))).thenReturn(List.of(ticket));
    when(ticket.getFullName()).thenReturn("Giuseppe Garibaldi");
    when(ticket.getUserLanguage()).thenReturn("en");
    StripeCreditCardManager stripeCreditCardManager = mock(StripeCreditCardManager.class);
    when(stripeCreditCardManager.accept(eq(PaymentMethod.CREDIT_CARD), any(), any())).thenReturn(true);
    when(paymentManager.streamActiveProvidersByProxy(eq(PaymentProxy.STRIPE), any())).thenReturn(Stream.of(stripeCreditCardManager));
    when(stripeCreditCardManager.getTokenAndPay(any())).thenReturn(PaymentResult.successful(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);
    when(ticketReservation.getStatus()).thenReturn(IN_PAYMENT);
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(List.of());
    PaymentResult result = trm.performPayment(spec, new TotalPrice(100, 0, 0, 0, "CHF"), PaymentProxy.STRIPE, PaymentMethod.CREDIT_CARD, null);
    if (expectSuccess) {
        Assertions.assertTrue(result.isSuccessful());
        Assertions.assertEquals(Optional.of(TRANSACTION_ID), result.getGatewayId());
        verify(ticketReservationRepository).findReservationByIdForUpdate(eq(RESERVATION_ID));
        verify(ticketReservationRepository, atLeastOnce()).findReservationById(RESERVATION_ID);
        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));
        verify(ticketRepository, expectCompleteReservation ? atLeastOnce() : times(1)).findTicketsInReservation(anyString());
        var verificationMode = expectCompleteReservation ? times(1) : never();
        verify(ticketReservationRepository, verificationMode).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.IN_PAYMENT.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(), eq(PaymentProxy.STRIPE.toString()), isNull());
        verify(ticketRepository, verificationMode).updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.ACQUIRED.toString()));
        verify(specialPriceRepository, verificationMode).updateStatusForReservation(eq(singletonList(RESERVATION_ID)), eq(SpecialPrice.Status.TAKEN.toString()));
        verify(ticketReservationRepository, verificationMode).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(), eq(PaymentProxy.STRIPE.toString()), isNull());
        verify(waitingQueueManager, verificationMode).fireReservationConfirmed(eq(RESERVATION_ID));
        verify(billingDocumentManager, verificationMode).generateInvoiceNumber(eq(spec), any());
        verify(ticketReservationRepository, never()).setInvoiceNumber(eq(RESERVATION_ID), any());
    } else {
        Assertions.assertFalse(result.isSuccessful());
        Assertions.assertTrue(result.isFailed());
    }
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) StripeCreditCardToken(alfio.model.transaction.token.StripeCreditCardToken) ConfigurationKeyValuePathLevel(alfio.model.system.ConfigurationKeyValuePathLevel) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration)

Example 3 with StripeCreditCardToken

use of alfio.model.transaction.token.StripeCreditCardToken in project alf.io by alfio-event.

the class TicketReservationManagerTest method returnFailureCodeIfPaymentNotSuccessful.

@Test
void returnFailureCodeIfPaymentNotSuccessful() {
    initConfirmReservation();
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(IN_PAYMENT.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), isNull(), isNull(), eq(PaymentProxy.STRIPE.toString()), isNull())).thenReturn(1);
    when(ticketReservationRepository.updateReservationStatus(eq(RESERVATION_ID), eq(TicketReservationStatus.PENDING.toString()))).thenReturn(1);
    when(ticketReservation.getPromoCodeDiscountId()).thenReturn(null);
    StripeCreditCardManager stripeCreditCardManager = mock(StripeCreditCardManager.class);
    when(paymentManager.streamActiveProvidersByProxy(eq(PaymentProxy.STRIPE), any())).thenReturn(Stream.of(stripeCreditCardManager));
    when(stripeCreditCardManager.getTokenAndPay(any())).thenReturn(PaymentResult.failed("error-code"));
    when(stripeCreditCardManager.accept(eq(PaymentMethod.CREDIT_CARD), any(), any())).thenReturn(true);
    PaymentSpecification spec = new PaymentSpecification(RESERVATION_ID, new StripeCreditCardToken(GATEWAY_TOKEN), 100, event, "email@user", new CustomerName("Full Name", null, null, event.mustUseFirstAndLastName()), null, null, Locale.ENGLISH, true, false, null, "IT", "12345", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult result = trm.performPayment(spec, new TotalPrice(100, 0, 0, 0, "CHF"), PaymentProxy.STRIPE, PaymentMethod.CREDIT_CARD, null);
    Assertions.assertFalse(result.isSuccessful());
    Assertions.assertFalse(result.getGatewayId().isPresent());
    Assertions.assertEquals(Optional.of("error-code"), result.getErrorCode());
    verify(ticketReservationRepository).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.IN_PAYMENT.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), isNull(), isNull(), eq(PaymentProxy.STRIPE.toString()), isNull());
    verify(ticketReservationRepository).findReservationByIdForUpdate(eq(RESERVATION_ID));
    verify(ticketReservationRepository).updateReservationStatus(eq(RESERVATION_ID), eq(TicketReservationStatus.PENDING.toString()));
    verify(configurationManager, never()).hasAllConfigurationsForInvoice(eq(event));
    verify(ticketReservationRepository).updateBillingData(eq(PriceContainer.VatStatus.INCLUDED), eq(100), eq(100), eq(0), eq(0), eq(EVENT_CURRENCY), eq("12345"), 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 4 with StripeCreditCardToken

use of alfio.model.transaction.token.StripeCreditCardToken in project alf.io by alfio-event.

the class StripeManagerTest method successFlow.

@Test
public void successFlow() {
    BaseStripeManager baseStripeManager = new BaseStripeManager(configurationManager, configurationRepository, ticketRepository, mock(Environment.class)) {

        @Override
        protected Optional<Charge> charge(PaymentSpecification spec, Map<String, Object> chargeParams) {
            return Optional.of(new Charge() {

                {
                    setId(paymentId);
                    setDescription("description");
                }
            });
        }
    };
    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.successful(paymentId));
}
Also used : 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)

Example 5 with StripeCreditCardToken

use of alfio.model.transaction.token.StripeCreditCardToken in project alf.io by alfio-event.

the class StripeManagerTest method internalError.

@Test
public void internalError() {
    BaseStripeManager baseStripeManager = new BaseStripeManager(configurationManager, configurationRepository, ticketRepository, mock(Environment.class)) {

        @Override
        protected Optional<Charge> charge(PaymentSpecification spec, Map<String, Object> chargeParams) {
            return Optional.of(new Charge() {

                {
                    setId(paymentId);
                    setDescription("description");
                }
            });
        }
    };
    StripeCreditCardManager stripeCreditCardManager = new StripeCreditCardManager(transactionRepository, baseStripeManager, TestUtil.clockProvider());
    when(event.getCurrency()).thenReturn("CHF");
    when(transactionRepository.insert(anyString(), isNull(), anyString(), any(ZonedDateTime.class), anyInt(), eq("CHF"), anyString(), anyString(), anyLong(), anyLong(), eq(Transaction.Status.COMPLETE), anyMap())).thenThrow(new NullPointerException());
    PaymentSpecification spec = new PaymentSpecification("", new StripeCreditCardToken(""), 100, event, "", customerName);
    Assertions.assertThrows(IllegalStateException.class, () -> stripeCreditCardManager.doPayment(spec));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) 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