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)));
}
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"));
}
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"));
}
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"));
}
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()));
}
Aggregations