Search in sources :

Example 1 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class ServiceDaoIT method shouldSaveAService_withMerchantDetails.

@Test
void shouldSaveAService_withMerchantDetails() {
    MerchantDetailsEntity merchantDetails = MerchantDetailsEntityBuilder.aMerchantDetailsEntity().build();
    ServiceEntity insertedServiceEntity = ServiceEntityBuilder.aServiceEntity().withMerchantDetailsEntity(merchantDetails).build();
    serviceDao.persist(insertedServiceEntity);
    List<Map<String, Object>> savedService = databaseHelper.findServiceByExternalId(insertedServiceEntity.getExternalId());
    assertThat(savedService.size(), is(1));
    assertThat(savedService.get(0).get("external_id"), is(insertedServiceEntity.getExternalId()));
    assertThat(savedService.get(0).get("merchant_name"), is(merchantDetails.getName()));
    assertThat(savedService.get(0).get("merchant_telephone_number"), is(merchantDetails.getTelephoneNumber()));
    assertThat(savedService.get(0).get("merchant_address_line1"), is(merchantDetails.getAddressLine1()));
    assertThat(savedService.get(0).get("merchant_address_line2"), is(merchantDetails.getAddressLine2()));
    assertThat(savedService.get(0).get("merchant_address_city"), is(merchantDetails.getAddressCity()));
    assertThat(savedService.get(0).get("merchant_address_postcode"), is(merchantDetails.getAddressPostcode()));
    assertThat(savedService.get(0).get("merchant_address_country"), is(merchantDetails.getAddressCountryCode()));
    assertThat(savedService.get(0).get("merchant_email"), is(merchantDetails.getEmail()));
    assertThat(savedService.get(0).get("merchant_url"), is(merchantDetails.getUrl()));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class EmailService method getTemplateMappingsFor.

private Map<EmailTemplate, StaticEmailContent> getTemplateMappingsFor(String gatewayAccountId) throws InvalidMerchantDetailsException {
    ServiceEntity service = getServiceFor(gatewayAccountId);
    MerchantDetailsEntity merchantDetails = service.getMerchantDetailsEntity();
    if (merchantDetails == null) {
        LOGGER.info("Merchant details are empty: can't send email for account {}", gatewayAccountId);
        throw new InvalidMerchantDetailsException("Merchant details are empty: can't send email for account " + gatewayAccountId);
    } else if (isMissingMandatoryFields(merchantDetails)) {
        LOGGER.info("Merchant details are missing mandatory fields: can't send email for account {}", gatewayAccountId);
        throw new InvalidMerchantDetailsException("Merchant details are missing mandatory fields: can't send email for account " + gatewayAccountId);
    }
    final Map<String, String> personalisation = Map.of(SERVICE_NAME_KEY, service.getServiceNames().get(SupportedLanguage.ENGLISH).getName(), ORGANISATION_NAME_KEY, merchantDetails.getName(), ORGANISATION_ADDRESS_KEY, formatMerchantAddress(merchantDetails), ORGANISATION_PHONE_NUMBER_KEY, merchantDetails.getTelephoneNumber(), ORGANISATION_EMAIL_ADDRESS_KEY, merchantDetails.getEmail());
    return Map.of(EmailTemplate.ONE_OFF_PAYMENT_CONFIRMED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getOneOffMandateAndPaymentCreatedEmailTemplateId(), personalisation), EmailTemplate.ON_DEMAND_PAYMENT_CONFIRMED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getOnDemandPaymentConfirmedEmailTemplateId(), personalisation), EmailTemplate.PAYMENT_FAILED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getPaymentFailedEmailTemplateId(), personalisation), EmailTemplate.MANDATE_CANCELLED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getMandateCancelledEmailTemplateId(), personalisation), EmailTemplate.MANDATE_FAILED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getMandateFailedEmailTemplateId(), personalisation), EmailTemplate.ON_DEMAND_MANDATE_CREATED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getOnDemandMandateCreatedEmailTemplateId(), personalisation), EmailTemplate.ONE_OFF_MANDATE_CREATED, new StaticEmailContent(notificationService.getNotifyDirectDebitConfiguration().getOneOffMandateAndPaymentCreatedEmailTemplateId(), personalisation));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) InvalidMerchantDetailsException(uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity)

Example 3 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldThrowAnExceptionIfMerchantDetailsAreMissing.

@Test
public void shouldThrowAnExceptionIfMerchantDetailsAreMissing() {
    // reset mocks as these are not used here and Mockito can continue enforcing strict stubs
    Mockito.reset(mockNotificationService, mockNotifyDirectDebitConfiguration, mockServiceEntity, mockCountryConverter);
    EmailTemplate template = EmailTemplate.MANDATE_FAILED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(null, TELEPHONE_NUMBER, ADDRESS_LINE_1, "address line 2", CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    InvalidMerchantDetailsException exception = assertThrows(InvalidMerchantDetailsException.class, () -> emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation));
    assertThat(exception.getMessage(), is("Merchant details are missing mandatory fields: can't send email for account " + GATEWAY_ACCOUNT_ID));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) InvalidMerchantDetailsException(uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForOnDemandPaymentConfirmed.

@Test
public void shouldSendAnEmailForOnDemandPaymentConfirmed() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.ON_DEMAND_PAYMENT_CONFIRMED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, null, CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_ON_DEMAND_PAYMENT_CONFIRMED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("service name"), is("a service"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation address"), is("address line 1, city, postcode, Cake Land"));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
    assertThat(allContent.get("organisation email address"), is(MERCHANT_EMAIL));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with MerchantDetailsEntity

use of uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity in project pay-adminusers by alphagov.

the class EmailServiceTest method shouldSendAnEmailForMandateFailed.

@Test
public void shouldSendAnEmailForMandateFailed() throws InvalidMerchantDetailsException {
    EmailTemplate template = EmailTemplate.MANDATE_FAILED;
    Map<String, String> personalisation = Map.of("field 1", "theValueOfField1", "field 2", "theValueOfField2");
    MerchantDetailsEntity merchantDetails = new MerchantDetailsEntity(MERCHANT_NAME, TELEPHONE_NUMBER, ADDRESS_LINE_1, "address line 2", CITY, POSTCODE, ADDRESS_COUNTRY_CODE, MERCHANT_EMAIL, null);
    given(mockServiceEntity.getMerchantDetailsEntity()).willReturn(merchantDetails);
    ArgumentCaptor<Map<String, String>> personalisationCaptor = forClass(Map.class);
    emailService.sendEmail(EMAIL_ADDRESS, GATEWAY_ACCOUNT_ID, template, personalisation);
    verify(mockNotificationService).sendEmail(eq("NOTIFY_MANDATE_FAILED_EMAIL_TEMPLATE_ID_VALUE"), eq(EMAIL_ADDRESS), personalisationCaptor.capture());
    Map<String, String> allContent = personalisationCaptor.getValue();
    assertThat(allContent.get("field 1"), is("theValueOfField1"));
    assertThat(allContent.get("field 2"), is("theValueOfField2"));
    assertThat(allContent.get("organisation name"), is(MERCHANT_NAME));
    assertThat(allContent.get("organisation phone number"), is(TELEPHONE_NUMBER));
    assertThat(allContent.get("organisation email address"), is(MERCHANT_EMAIL));
}
Also used : MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) EmailTemplate(uk.gov.pay.adminusers.resources.EmailTemplate) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)14 Test (org.junit.jupiter.api.Test)11 Map (java.util.Map)9 EmailTemplate (uk.gov.pay.adminusers.resources.EmailTemplate)8 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)5 Service (uk.gov.pay.adminusers.model.Service)3 MerchantDetailsEntityBuilder.aMerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntityBuilder.aMerchantDetailsEntity)2 ServiceEntityBuilder.aServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder.aServiceEntity)2 InvalidMerchantDetailsException (uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException)2 Timestamp (java.sql.Timestamp)1 Timestamp.from (java.sql.Timestamp.from)1 OTHER (java.sql.Types.OTHER)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 Jdbi (org.jdbi.v3.core.Jdbi)1 PGobject (org.postgresql.util.PGobject)1 ForgottenPassword (uk.gov.pay.adminusers.model.ForgottenPassword)1 MerchantDetails (uk.gov.pay.adminusers.model.MerchantDetails)1 Permission (uk.gov.pay.adminusers.model.Permission)1