use of uk.gov.pay.products.client.publicapi.model.PaymentState in project pay-products by alphagov.
the class PaymentFinderTest method shouldReturnAList_whenFoundByProductExternalId.
@Test
public void shouldReturnAList_whenFoundByProductExternalId() {
String productExternalId = randomUuid();
String paymentExternalId_1 = randomUuid();
String paymentExternalId_2 = randomUuid();
PaymentEntity paymentEntity_1 = new PaymentEntity();
PaymentEntity paymentEntity_2 = new PaymentEntity();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().build();
paymentEntity_1.setExternalId(paymentExternalId_1);
paymentEntity_1.setProductEntity(productEntity);
paymentEntity_1.setStatus(PaymentStatus.SUBMITTED);
paymentEntity_1.setGovukPaymentId(randomUuid());
paymentEntity_2.setExternalId(paymentExternalId_2);
paymentEntity_2.setProductEntity(productEntity);
paymentEntity_2.setStatus(PaymentStatus.CREATED);
paymentEntity_2.setGovukPaymentId(randomUuid());
List<PaymentEntity> paymentList = Arrays.asList(paymentEntity_1, paymentEntity_2);
PaymentResponse paymentResponse = new PaymentResponse();
paymentResponse.setState(new PaymentState("success", true, "a message", "a code"));
when(paymentDao.findByProductExternalId(productExternalId)).thenReturn(paymentList);
when(publicApiRestClient.getPayment(productEntity.getPayApiToken(), paymentEntity_1.getGovukPaymentId())).thenReturn(Optional.of(paymentResponse));
List<Payment> expectedPaymentList = paymentFinder.findByProductExternalId(productExternalId);
assertThat(expectedPaymentList.isEmpty(), is(false));
assertThat(expectedPaymentList.size(), is(2));
Optional<Payment> payment_1 = expectedPaymentList.stream().filter(payment -> payment.getExternalId().equals(paymentExternalId_1)).findFirst();
assertThat(payment_1.isPresent(), is(true));
assertThat(payment_1.get().getGovUkStatus(), is("success"));
Optional<Payment> payment_2 = expectedPaymentList.stream().filter(payment -> payment.getExternalId().equals(paymentExternalId_2)).findFirst();
assertThat(payment_2.isPresent(), is(true));
assertThat(payment_2.get().getGovUkStatus(), is(nullValue()));
}
use of uk.gov.pay.products.client.publicapi.model.PaymentState in project pay-products by alphagov.
the class PaymentFinderTest method shouldReturnPaymentWithExternalStatus_whenFoundByExternalIdAndStatusIsSubmitted.
@Test
public void shouldReturnPaymentWithExternalStatus_whenFoundByExternalIdAndStatusIsSubmitted() {
String externalId = randomUuid();
PaymentEntity paymentEntity = new PaymentEntity();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().build();
paymentEntity.setExternalId(externalId);
paymentEntity.setProductEntity(productEntity);
paymentEntity.setStatus(PaymentStatus.SUBMITTED);
paymentEntity.setGovukPaymentId(externalId);
PaymentResponse paymentResponse = new PaymentResponse();
paymentResponse.setState(new PaymentState("submitted", true, "a message", "a code"));
when(paymentDao.findByExternalId(externalId)).thenReturn(Optional.of(paymentEntity));
when(publicApiRestClient.getPayment(productEntity.getPayApiToken(), paymentEntity.getGovukPaymentId())).thenReturn(Optional.of(paymentResponse));
Optional<Payment> optionalPayment = paymentFinder.findByExternalId(externalId);
assertThat(optionalPayment.isPresent(), is(true));
Payment payment = optionalPayment.get();
assertThat(payment.getGovUkStatus(), is("submitted"));
}
use of uk.gov.pay.products.client.publicapi.model.PaymentState in project pay-products by alphagov.
the class PaymentResponseMatcher method hasAllPaymentProperties.
public static Matcher<PaymentResponse> hasAllPaymentProperties(final JsonObject expectedPaymentResponse) {
return new BaseMatcher<>() {
@Override
public boolean matches(final Object obj) {
final PaymentResponse actualPaymentResponse = (PaymentResponse) obj;
boolean matched = true;
matched = matched && StringUtils.equals(actualPaymentResponse.getPaymentId(), expectedPaymentResponse.getString("payment_id"));
matched = matched && (actualPaymentResponse.getAmount() == (long) expectedPaymentResponse.getInt("amount"));
JsonObject expectedState = expectedPaymentResponse.getJsonObject("state");
PaymentState actualState = actualPaymentResponse.getState();
if (actualState == null)
return false;
matched = matched && StringUtils.equals(actualState.getStatus(), expectedState.getString("status"));
matched = matched && (actualState.isFinished() == expectedState.getBoolean("finished"));
matched = matched && StringUtils.equals(actualState.getMessage(), expectedState.getString("message"));
matched = matched && StringUtils.equals(actualState.getCode(), expectedState.getString("code"));
matched = matched && StringUtils.equals(actualPaymentResponse.getDescription(), expectedPaymentResponse.getString("description"));
matched = matched && StringUtils.equals(actualPaymentResponse.getReference(), expectedPaymentResponse.getString("reference"));
matched = matched && StringUtils.equals(actualPaymentResponse.getEmail(), expectedPaymentResponse.getString("email"));
matched = matched && StringUtils.equals(actualPaymentResponse.getEmail(), expectedPaymentResponse.getString("email"));
matched = matched && StringUtils.equals(actualPaymentResponse.getPaymentProvider(), expectedPaymentResponse.getString("payment_provider"));
matched = matched && StringUtils.equals(actualPaymentResponse.getReturnUrl(), expectedPaymentResponse.getString("return_url"));
matched = matched && StringUtils.equals(actualPaymentResponse.getCreatedDate(), expectedPaymentResponse.getString("created_date"));
JsonObject expectedRefundSummary = expectedPaymentResponse.getJsonObject("refund_summary");
RefundSummary actualRefundSummary = actualPaymentResponse.getRefundSummary();
if (actualRefundSummary == null)
return false;
matched = matched && StringUtils.equals(actualRefundSummary.getStatus(), expectedRefundSummary.getString("status"));
matched = matched && (actualRefundSummary.getAmountAvailable() == (long) expectedRefundSummary.getInt("amount_available"));
matched = matched && (actualRefundSummary.getAmountSubmitted() == (long) expectedRefundSummary.getInt("amount_submitted"));
JsonObject expectedSettlementSummary = expectedPaymentResponse.getJsonObject("settlement_summary");
SettlementSummary actualSettlementSummary = actualPaymentResponse.getSettlementSummary();
if (actualSettlementSummary == null)
return false;
matched = matched && StringUtils.equals(actualSettlementSummary.getCaptureSubmitTime(), expectedSettlementSummary.getString("capture_submit_time"));
matched = matched && StringUtils.equals(actualSettlementSummary.getCapturedDate(), expectedSettlementSummary.getString("captured_date"));
JsonObject expectedLinks = expectedPaymentResponse.getJsonObject("_links");
Links actualLinks = actualPaymentResponse.getLinks();
if (actualLinks == null)
return false;
JsonObject expectedSelfLink = expectedLinks.getJsonObject("self");
Link actualSelfLink = actualLinks.getSelf();
if (actualSelfLink == null)
return false;
matched = matched && StringUtils.equals(actualSelfLink.getHref(), expectedSelfLink.getString("href"));
matched = matched && StringUtils.equals(actualSelfLink.getMethod(), expectedSelfLink.getString("method"));
JsonObject expectedNextUrlLink = expectedLinks.getJsonObject("next_url");
Link actualNextUrlLink = actualLinks.getNextUrl();
if (actualNextUrlLink == null)
return false;
matched = matched && StringUtils.equals(actualNextUrlLink.getHref(), expectedNextUrlLink.getString("href"));
matched = matched && StringUtils.equals(actualNextUrlLink.getMethod(), expectedNextUrlLink.getString("method"));
JsonObject expectedNextUrlPostLink = expectedLinks.getJsonObject("next_url_post");
Link actualNextUrlPostLink = actualLinks.getNextUrlPost();
if (actualNextUrlPostLink == null)
return false;
matched = matched && StringUtils.equals(actualNextUrlPostLink.getHref(), expectedNextUrlPostLink.getString("href"));
matched = matched && StringUtils.equals(actualNextUrlPostLink.getMethod(), expectedNextUrlPostLink.getString("method"));
matched = matched && StringUtils.equals(actualNextUrlPostLink.getType(), expectedNextUrlPostLink.getString("type"));
JsonObject expectedEventsLink = expectedLinks.getJsonObject("events");
Link actualEventsLink = actualLinks.getEvents();
if (actualEventsLink == null)
return false;
matched = matched && StringUtils.equals(actualEventsLink.getHref(), expectedEventsLink.getString("href"));
matched = matched && StringUtils.equals(actualEventsLink.getMethod(), expectedEventsLink.getString("method"));
JsonObject expectedRefundsLink = expectedLinks.getJsonObject("refunds");
Link actualRefundsLink = actualLinks.getRefunds();
if (actualRefundsLink == null)
return false;
matched = matched && StringUtils.equals(actualRefundsLink.getHref(), expectedRefundsLink.getString("href"));
matched = matched && StringUtils.equals(actualRefundsLink.getMethod(), expectedRefundsLink.getString("method"));
JsonObject expectedCancelsLink = expectedLinks.getJsonObject("cancel");
Link actualCancelLink = actualLinks.getCancel();
if (actualCancelLink == null)
return false;
matched = matched && StringUtils.equals(actualCancelLink.getHref(), expectedCancelsLink.getString("href"));
matched = matched && StringUtils.equals(actualCancelLink.getMethod(), expectedCancelsLink.getString("method"));
return matched;
}
@Override
public void describeTo(final Description description) {
description.appendText("PaymentResponse ").appendValue(expectedPaymentResponse);
}
};
}
Aggregations