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()));
}
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));
}
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));
}
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));
}
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));
}
Aggregations