use of uk.gov.pay.products.model.Payment in project pay-products by alphagov.
the class PaymentCreatorTest method shouldCreateASuccessfulPayment_withUserDefinedReference_whenReferencePresent.
@Test
public void shouldCreateASuccessfulPayment_withUserDefinedReference_whenReferencePresent() {
int productId = 1;
String productExternalId = "product-external-id";
long productPrice = 100L;
String productName = "name";
String productReturnUrl = "https://return.url";
String productApiToken = "api-token";
String userDefinedReference = "user-defined-reference";
Integer gatewayAccountId = 1;
String paymentId = "payment-id";
String paymentExternalId = "random-external-id";
String paymentNextUrl = "http://next.url";
SupportedLanguage language = SupportedLanguage.WELSH;
Long priceOverride = 500L;
ProductEntity productEntity = createProductEntity(productId, productPrice, productExternalId, productName, "", productApiToken, gatewayAccountId, true, language);
PaymentRequest expectedPaymentRequest = createPaymentRequest(priceOverride, userDefinedReference, productName, productReturnUrl + "/" + paymentExternalId, language, false, Map.of(), CARD_PAYMENT_LINK);
PaymentResponse paymentResponse = createPaymentResponse(paymentId, priceOverride, paymentNextUrl, productReturnUrl);
when(productDao.findByExternalId(productExternalId)).thenReturn(Optional.of(productEntity));
when(randomUuid()).thenReturn(paymentExternalId);
when(productsConfiguration.getProductsUiConfirmUrl()).thenReturn(productReturnUrl);
when(publicApiRestClient.createPayment(argThat(is(productApiToken)), argThat(PaymentRequestMatcher.isSame(expectedPaymentRequest)))).thenReturn(paymentResponse);
Payment payment = paymentCreator.doCreate(productExternalId, priceOverride, userDefinedReference);
assertNotNull(payment);
assertNotNull(payment.getExternalId());
assertThat(payment.getGovukPaymentId(), is(paymentResponse.getPaymentId()));
assertThat(payment.getAmount(), is(500L));
assertThat(payment.getReferenceNumber(), is(userDefinedReference));
PaymentEntity expectedPaymentEntity = createPaymentEntity(paymentId, userDefinedReference, paymentNextUrl, productEntity, SUBMITTED, priceOverride);
verify(paymentDao).merge(argThat(PaymentEntityMatcher.isSame(expectedPaymentEntity)));
}
use of uk.gov.pay.products.model.Payment in project pay-products by alphagov.
the class PaymentFinderTest method shouldReturnPaymentWithNoExternalStatus_whenFoundByExternalIdAndStatusIsCreated.
@Test
public void shouldReturnPaymentWithNoExternalStatus_whenFoundByExternalIdAndStatusIsCreated() {
String externalId = randomUuid();
PaymentEntity paymentEntity = new PaymentEntity();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().build();
paymentEntity.setExternalId(externalId);
paymentEntity.setProductEntity(productEntity);
paymentEntity.setStatus(PaymentStatus.CREATED);
paymentEntity.setGovukPaymentId(externalId);
when(paymentDao.findByExternalId(externalId)).thenReturn(Optional.of(paymentEntity));
Optional<Payment> optionalPayment = paymentFinder.findByExternalId(externalId);
assertThat(optionalPayment.isPresent(), is(true));
Payment payment = optionalPayment.get();
assertThat(payment.getGovUkStatus(), is(nullValue()));
}
use of uk.gov.pay.products.model.Payment 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.model.Payment in project pay-products by alphagov.
the class PaymentFinderTest method shouldReturnPaymentWithNoExternalStatus_whenFoundByExternalIdAndStatusIsError.
@Test
public void shouldReturnPaymentWithNoExternalStatus_whenFoundByExternalIdAndStatusIsError() {
String externalId = randomUuid();
PaymentEntity paymentEntity = new PaymentEntity();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().build();
paymentEntity.setExternalId(externalId);
paymentEntity.setProductEntity(productEntity);
paymentEntity.setStatus(PaymentStatus.ERROR);
paymentEntity.setGovukPaymentId(externalId);
when(paymentDao.findByExternalId(externalId)).thenReturn(Optional.of(paymentEntity));
Optional<Payment> optionalPayment = paymentFinder.findByExternalId(externalId);
assertThat(optionalPayment.isPresent(), is(true));
Payment payment = optionalPayment.get();
assertThat(payment.getGovUkStatus(), is(nullValue()));
}
use of uk.gov.pay.products.model.Payment in project pay-products by alphagov.
the class PaymentFinderTest method shouldReturnPayment_whenFoundByExternalId.
@Test
public void shouldReturnPayment_whenFoundByExternalId() {
String externalId = randomUuid();
PaymentEntity paymentEntity = new PaymentEntity();
paymentEntity.setExternalId(externalId);
when(paymentDao.findByExternalId(externalId)).thenReturn(Optional.of(paymentEntity));
Optional<Payment> paymentOptional = paymentFinder.findByExternalId(externalId);
assertThat(paymentOptional.isPresent(), is(true));
assertThat(paymentOptional.get().getExternalId(), is(externalId));
}
Aggregations