Search in sources :

Example 1 with InvalidMerchantDetailsException

use of uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException 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 2 with InvalidMerchantDetailsException

use of uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException 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)

Aggregations

MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)2 InvalidMerchantDetailsException (uk.gov.pay.adminusers.resources.InvalidMerchantDetailsException)2 Test (org.junit.jupiter.api.Test)1 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)1 EmailTemplate (uk.gov.pay.adminusers.resources.EmailTemplate)1