Search in sources :

Example 1 with StripeAgreementExistsException

use of uk.gov.pay.adminusers.exception.StripeAgreementExistsException in project pay-adminusers by alphagov.

the class StripeAgreementService method doCreate.

public void doCreate(String serviceExternalId, InetAddress ipAddress) {
    ServiceEntity serviceEntity = serviceDao.findByExternalId(serviceExternalId).orElseThrow(() -> new ServiceNotFoundException(serviceExternalId));
    if (stripeAgreementDao.findByServiceExternalId(serviceExternalId).isPresent()) {
        throw new StripeAgreementExistsException();
    }
    logger.info(format("Creating stripe agreement for service %s", serviceExternalId));
    ZonedDateTime agreementTime = ZonedDateTime.now(ZoneId.of("UTC"));
    stripeAgreementDao.persist(new StripeAgreementEntity(serviceEntity, ipAddress.getHostAddress(), agreementTime));
}
Also used : StripeAgreementExistsException(uk.gov.pay.adminusers.exception.StripeAgreementExistsException) ZonedDateTime(java.time.ZonedDateTime) ServiceNotFoundException(uk.gov.pay.adminusers.exception.ServiceNotFoundException) StripeAgreementEntity(uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity)

Example 2 with StripeAgreementExistsException

use of uk.gov.pay.adminusers.exception.StripeAgreementExistsException in project pay-adminusers by alphagov.

the class StripeAgreementServiceTest method shouldThrowException_whenStripeAgreementAlreadyExists.

@Test
public void shouldThrowException_whenStripeAgreementAlreadyExists() throws UnknownHostException {
    String serviceExternalId = "abc123";
    ServiceEntity mockServiceEntity = mock(ServiceEntity.class);
    when(mockedServiceDao.findByExternalId(serviceExternalId)).thenReturn(Optional.of(mockServiceEntity));
    StripeAgreementEntity mockStripeAgreementEntity = mock(StripeAgreementEntity.class);
    when(mockedStripeAgreementDao.findByServiceExternalId(serviceExternalId)).thenReturn(Optional.of(mockStripeAgreementEntity));
    StripeAgreementExistsException exception = assertThrows(StripeAgreementExistsException.class, () -> stripeAgreementService.doCreate(serviceExternalId, InetAddress.getByName("192.0.2.0")));
    assertThat(exception.getMessage(), is("Stripe agreement information is already stored for this service"));
}
Also used : StripeAgreementExistsException(uk.gov.pay.adminusers.exception.StripeAgreementExistsException) StripeAgreementEntity(uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Test(org.junit.jupiter.api.Test)

Aggregations

StripeAgreementExistsException (uk.gov.pay.adminusers.exception.StripeAgreementExistsException)2 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)2 StripeAgreementEntity (uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity)2 ZonedDateTime (java.time.ZonedDateTime)1 Test (org.junit.jupiter.api.Test)1 ServiceNotFoundException (uk.gov.pay.adminusers.exception.ServiceNotFoundException)1