Search in sources :

Example 1 with LedgerTransaction

use of uk.gov.pay.connector.client.ledger.model.LedgerTransaction in project pay-connector by alphagov.

the class EventFactoryTest method shouldCreatedARefundAvailabilityUpdatedEvent_ifPaymentIsHistoric.

@Test
public void shouldCreatedARefundAvailabilityUpdatedEvent_ifPaymentIsHistoric() throws Exception {
    ChargeResponse.RefundSummary refundSummary = new ChargeResponse.RefundSummary();
    refundSummary.setStatus("available");
    LedgerTransaction transaction = new LedgerTransaction();
    transaction.setTransactionId(charge.getExternalId());
    transaction.setPaymentProvider("sandbox");
    transaction.setRefundSummary(refundSummary);
    transaction.setAmount(charge.getAmount());
    transaction.setTotalAmount(charge.getAmount());
    transaction.setCreatedDate(Instant.now().toString());
    transaction.setGatewayAccountId(charge.getGatewayAccount().getId().toString());
    transaction.setServiceId(charge.getServiceId());
    transaction.setLive(charge.getGatewayAccount().isLive());
    when(chargeService.findCharge(transaction.getTransactionId())).thenReturn(Optional.of(Charge.from(transaction)));
    RefundHistory refundErrorHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.REFUND_ERROR.getValue()).withUserExternalId("user_external_id").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
    when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundErrorHistory.getExternalId(), refundErrorHistory.getStatus())).thenReturn(Optional.of(refundErrorHistory));
    StateTransition refundStateTransition = new RefundStateTransition(refundErrorHistory.getExternalId(), refundErrorHistory.getStatus(), RefundError.class);
    List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
    assertThat(refundEvents.size(), is(2));
    RefundAvailabilityUpdated refundAvailabilityUpdated = (RefundAvailabilityUpdated) refundEvents.stream().filter(e -> ResourceType.PAYMENT.equals(e.getResourceType())).findFirst().get();
    assertThat(refundAvailabilityUpdated.getResourceExternalId(), is(transaction.getTransactionId()));
    assertThat(refundAvailabilityUpdated.getResourceType(), is(ResourceType.PAYMENT));
    assertThat(refundAvailabilityUpdated.getEventDetails(), is(instanceOf(RefundAvailabilityUpdatedEventDetails.class)));
}
Also used : RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CaptureConfirmedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureConfirmedEventDetails) PaymentNotificationCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentNotificationCreatedEventDetails) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) PaymentCreated(uk.gov.pay.connector.events.model.charge.PaymentCreated) BackfillerRecreatedUserEmailCollected(uk.gov.pay.connector.events.model.charge.BackfillerRecreatedUserEmailCollected) GatewayRequires3dsAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayRequires3dsAuthorisation) Is(org.hamcrest.core.Is) PaymentExpired(uk.gov.pay.connector.events.model.charge.PaymentExpired) CancelledByUserEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CancelledByUserEventDetails) PaymentProvider(uk.gov.pay.connector.gateway.PaymentProvider) SandboxPaymentProvider(uk.gov.pay.connector.gateway.sandbox.SandboxPaymentProvider) CaptureSubmitted(uk.gov.pay.connector.events.model.charge.CaptureSubmitted) PaymentProviders(uk.gov.pay.connector.gateway.PaymentProviders) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) JUnitParamsRunner(junitparams.JUnitParamsRunner) RefundEventWithGatewayTransactionIdDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundEventWithGatewayTransactionIdDetails) ChargeEntityFixture(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture) CancelledByExternalService(uk.gov.pay.connector.events.model.charge.CancelledByExternalService) CancelledByUser(uk.gov.pay.connector.events.model.charge.CancelledByUser) EventFactory(uk.gov.pay.connector.events.model.EventFactory) GatewayTimeoutDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayTimeoutDuringAuthorisation) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) CaptureSubmittedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.CaptureSubmittedEventDetails) CancelledByExpiration(uk.gov.pay.connector.events.model.charge.CancelledByExpiration) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) AuthorisationErrorCheckedWithGatewayChargeWasMissing(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasMissing) RefundStatus(uk.gov.pay.connector.refund.model.domain.RefundStatus) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) Instant(java.time.Instant) RefundHistoryEntityFixture(uk.gov.pay.connector.pact.RefundHistoryEntityFixture) List(java.util.List) CaptureConfirmed(uk.gov.pay.connector.events.model.charge.CaptureConfirmed) Auth3dsRequiredEntity(uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity) CancelByExternalServiceSubmitted(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceSubmitted) StatusCorrectedToCapturedToMatchGatewayStatus(uk.gov.pay.connector.events.model.charge.StatusCorrectedToCapturedToMatchGatewayStatus) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) CancelByExpirationFailed(uk.gov.pay.connector.events.model.charge.CancelByExpirationFailed) RefundService(uk.gov.pay.connector.refund.service.RefundService) Optional(java.util.Optional) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) Event(uk.gov.pay.connector.events.model.Event) ResourceType(uk.gov.pay.connector.events.model.ResourceType) CancelByExternalServiceFailed(uk.gov.pay.connector.events.model.charge.CancelByExternalServiceFailed) CancelByUserFailed(uk.gov.pay.connector.events.model.charge.CancelByUserFailed) UserEmailCollectedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.UserEmailCollectedEventDetails) Parameters(junitparams.Parameters) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RefundDao(uk.gov.pay.connector.refund.dao.RefundDao) GatewayRequires3dsAuthorisationEventDetails(uk.gov.pay.connector.events.eventdetails.charge.GatewayRequires3dsAuthorisationEventDetails) ChargeEventEntityFixture(uk.gov.pay.connector.pact.ChargeEventEntityFixture) CaptureErrored(uk.gov.pay.connector.events.model.charge.CaptureErrored) RunWith(org.junit.runner.RunWith) PaymentCreatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.PaymentCreatedEventDetails) AuthorisationCancelled(uk.gov.pay.connector.events.model.charge.AuthorisationCancelled) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) EmptyEventDetails(uk.gov.pay.connector.events.eventdetails.EmptyEventDetails) Charge(uk.gov.pay.connector.charge.model.domain.Charge) AuthorisationRejected(uk.gov.pay.connector.events.model.charge.AuthorisationRejected) CancelledWithGatewayAfterAuthorisationError(uk.gov.pay.connector.events.model.charge.CancelledWithGatewayAfterAuthorisationError) ChargeService(uk.gov.pay.connector.charge.service.ChargeService) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) CaptureAbandonedAfterTooManyRetries(uk.gov.pay.connector.events.model.charge.CaptureAbandonedAfterTooManyRetries) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENTERING_CARD_DETAILS(uk.gov.pay.connector.charge.model.domain.ChargeStatus.ENTERING_CARD_DETAILS) Before(org.junit.Before) AuthorisationErrorCheckedWithGatewayChargeWasRejected(uk.gov.pay.connector.events.model.charge.AuthorisationErrorCheckedWithGatewayChargeWasRejected) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) GatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.GatewayErrorDuringAuthorisation) RefundAvailabilityUpdatedEventDetails(uk.gov.pay.connector.events.eventdetails.charge.RefundAvailabilityUpdatedEventDetails) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) AUTHORISATION_3DS_REQUIRED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.AUTHORISATION_3DS_REQUIRED) Test(org.junit.Test) ChargeEventDao(uk.gov.pay.connector.chargeevent.dao.ChargeEventDao) Mockito.when(org.mockito.Mockito.when) PaymentNotificationCreated(uk.gov.pay.connector.events.model.charge.PaymentNotificationCreated) UnexpectedGatewayErrorDuringAuthorisation(uk.gov.pay.connector.events.model.charge.UnexpectedGatewayErrorDuringAuthorisation) RefundCreatedByUserEventDetails(uk.gov.pay.connector.events.eventdetails.refund.RefundCreatedByUserEventDetails) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) StateTransition(uk.gov.pay.connector.queue.statetransition.StateTransition) RefundStateTransition(uk.gov.pay.connector.queue.statetransition.RefundStateTransition) PaymentStateTransition(uk.gov.pay.connector.queue.statetransition.PaymentStateTransition) Event(uk.gov.pay.connector.events.model.Event) RefundAvailabilityUpdated(uk.gov.pay.connector.events.model.charge.RefundAvailabilityUpdated) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) RefundHistory(uk.gov.pay.connector.refund.model.domain.RefundHistory) Test(org.junit.Test)

Example 2 with LedgerTransaction

use of uk.gov.pay.connector.client.ledger.model.LedgerTransaction in project pay-connector by alphagov.

the class LedgerServiceConsumerTest method getTransaction_shouldSerialiseLedgerPaymentTransactionCorrectly.

@Test
@PactVerification("ledger")
@Pacts(pacts = { "connector-ledger-get-payment-transaction" })
public void getTransaction_shouldSerialiseLedgerPaymentTransactionCorrectly() {
    String externalId = "e8eq11mi2ndmauvb51qsg8hccn";
    Optional<LedgerTransaction> mayBeTransaction = ledgerService.getTransaction(externalId);
    assertThat(mayBeTransaction.isPresent(), is(true));
    LedgerTransaction transaction = mayBeTransaction.get();
    assertThat(transaction.getTransactionId(), is(externalId));
    assertThat(transaction.getAmount(), is(12000L));
    assertThat(transaction.getGatewayAccountId(), is("3"));
    assertThat(transaction.getCredentialExternalId(), is("credential-external-id"));
}
Also used : LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 3 with LedgerTransaction

use of uk.gov.pay.connector.client.ledger.model.LedgerTransaction in project pay-connector by alphagov.

the class LedgerServiceConsumerTest method getRefundsFromLedgerShouldSerialiseResponseCorrectly.

@Test
@PactVerification("ledger")
@Pacts(pacts = { "connector-ledger-get-refunds-for-payment" })
public void getRefundsFromLedgerShouldSerialiseResponseCorrectly() {
    String externalId = "650516the13q5jpfo435f1m1fm";
    RefundTransactionsForPayment refundTransactionsForPayment = ledgerService.getRefundsForPayment(3L, externalId);
    assertThat(refundTransactionsForPayment.getParentTransactionId(), is(externalId));
    List<LedgerTransaction> transactions = refundTransactionsForPayment.getTransactions();
    assertThat(transactions.get(0).getTransactionId(), is("nklfm1pk9flpu91j815kp2835o"));
    assertThat(transactions.get(0).getGatewayAccountId(), is("3"));
    assertThat(transactions.get(0).getAmount(), is(100L));
    assertThat(transactions.get(0).getState().getStatus(), is("submitted"));
    assertThat(transactions.get(1).getTransactionId(), is("migtkmlt6gvm16sim5h0p7oeje"));
    assertThat(transactions.get(1).getAmount(), is(110L));
    assertThat(transactions.get(1).getGatewayAccountId(), is("3"));
    assertThat(transactions.get(1).getState().getStatus(), is("error"));
}
Also used : RefundTransactionsForPayment(uk.gov.pay.connector.client.ledger.model.RefundTransactionsForPayment) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 4 with LedgerTransaction

use of uk.gov.pay.connector.client.ledger.model.LedgerTransaction in project pay-connector by alphagov.

the class LedgerServiceConsumerTest method getTransaction_shouldSerialiseLedgerRefundTransactionCorrectly.

@Test
@PactVerification("ledger")
@Pacts(pacts = { "connector-ledger-get-refund-transaction" })
public void getTransaction_shouldSerialiseLedgerRefundTransactionCorrectly() {
    String externalId = "nklfm1pk9flpu91j815kp2835o";
    Optional<LedgerTransaction> mayBeTransaction = ledgerService.getTransaction(externalId);
    assertThat(mayBeTransaction.isPresent(), is(true));
    LedgerTransaction transaction = mayBeTransaction.get();
    assertThat(transaction.getTransactionId(), is(externalId));
    assertThat(transaction.getAmount(), is(1000L));
    assertThat(transaction.getParentTransactionId(), is("64pcdagc9c13vgi7n904aio3n9"));
    assertThat(transaction.getCreatedDate(), is("2020-07-20T13:39:38.940Z"));
    assertThat(transaction.getState().getStatus(), is("success"));
}
Also used : LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 5 with LedgerTransaction

use of uk.gov.pay.connector.client.ledger.model.LedgerTransaction in project pay-connector by alphagov.

the class ChargeServiceFindTest method shouldFindCharge_fromLedgerIfNotExists.

@Test
public void shouldFindCharge_fromLedgerIfNotExists() {
    ChargeEntity chargeEntity = aValidChargeEntity().withStatus(AUTHORISATION_SUCCESS).build();
    LedgerTransaction transaction = new LedgerTransaction();
    transaction.setTransactionId(chargeEntity.getExternalId());
    transaction.setAmount(chargeEntity.getAmount());
    transaction.setCreatedDate(Instant.now().toString());
    transaction.setGatewayAccountId(String.valueOf(GATEWAY_ACCOUNT_ID));
    transaction.setLive(true);
    when(mockedChargeDao.findByExternalIdAndGatewayAccount(chargeEntity.getExternalId(), GATEWAY_ACCOUNT_ID)).thenReturn(Optional.empty());
    when(ledgerService.getTransactionForGatewayAccount(chargeEntity.getExternalId(), GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(transaction));
    Optional<Charge> charge = service.findCharge(chargeEntity.getExternalId(), GATEWAY_ACCOUNT_ID);
    assertThat(charge.isPresent(), is(true));
    final Charge result = charge.get();
    assertThat(result.getExternalId(), is(chargeEntity.getExternalId()));
    assertThat(result.getAmount(), is(chargeEntity.getAmount()));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) Charge(uk.gov.pay.connector.charge.model.domain.Charge) Test(org.junit.Test)

Aggregations

LedgerTransaction (uk.gov.pay.connector.client.ledger.model.LedgerTransaction)49 Test (org.junit.Test)43 LedgerTransactionFixture.aValidLedgerTransaction (uk.gov.pay.connector.model.domain.LedgerTransactionFixture.aValidLedgerTransaction)30 ParityCheckStatus (uk.gov.pay.connector.charge.model.domain.ParityCheckStatus)22 Charge (uk.gov.pay.connector.charge.model.domain.Charge)7 Test (org.junit.jupiter.api.Test)5 ChargeResponse (uk.gov.pay.connector.charge.model.ChargeResponse)5 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)4 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)4 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)4 PactVerification (au.com.dius.pact.consumer.PactVerification)3 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)3 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)3 RefundEntityFixture.aValidRefundEntity (uk.gov.pay.connector.model.domain.RefundEntityFixture.aValidRefundEntity)3 RefundEntity (uk.gov.pay.connector.refund.model.domain.RefundEntity)3 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Auth3dsRequiredEntity (uk.gov.pay.connector.charge.model.domain.Auth3dsRequiredEntity)2 RefundRequest (uk.gov.pay.connector.refund.model.RefundRequest)2 Refund (uk.gov.pay.connector.refund.model.domain.Refund)2