use of uk.gov.service.payments.commons.model.SupportedLanguage in project pay-adminusers by alphagov.
the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru.
@Test
public void shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru() {
PAYLOAD_MAP.put(FIELD_NAME, EN_SERVICE_NAME);
String anotherGatewayAccountId = "another-gateway-account-id";
List<String> gatewayAccounts = List.of(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId);
PAYLOAD_MAP.put(FIELD_GATEWAY_ACCOUNT_IDS, gatewayAccounts);
PAYLOAD_MAP.put("service_name", Map.of(SupportedLanguage.ENGLISH.toString(), EN_SERVICE_NAME, SupportedLanguage.WELSH.toString(), CY_SERVICE_NAME));
Map<SupportedLanguage, String> serviceName = Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME, SupportedLanguage.WELSH, CY_SERVICE_NAME);
Service service = buildService(gatewayAccounts, serviceName);
given(mockedServiceCreator.doCreate(gatewayAccounts, serviceName)).willReturn(service);
Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
assertThat(response.getStatus(), is(201));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("name"), is(EN_SERVICE_NAME));
assertThat(json.get("external_id"), is(notNullValue()));
assertEnServiceNameJson(EN_SERVICE_NAME, json);
assertCyServiceNameJson(CY_SERVICE_NAME, json);
assertLinks(json.get("external_id"), json);
assertThat(json.getList("gateway_account_ids"), hasSize(2));
assertThat(json.getList("gateway_account_ids"), containsInAnyOrder(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId));
}
use of uk.gov.service.payments.commons.model.SupportedLanguage in project pay-adminusers by alphagov.
the class ServiceResource method createService.
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public Response createService(JsonNode payload) {
LOGGER.info("Create Service POST request - [ {} ]", payload);
List<String> gatewayAccountIds = extractGatewayAccountIds(payload);
Map<SupportedLanguage, String> serviceNameVariants = getServiceNameVariants(payload);
Service service = serviceServicesFactory.serviceCreator().doCreate(gatewayAccountIds, serviceNameVariants);
return Response.status(CREATED).entity(service).build();
}
use of uk.gov.service.payments.commons.model.SupportedLanguage in project pay-adminusers by alphagov.
the class ServiceCreatorTest method shouldSuccess_whenProvidedWith_multipleValidNames_andNoGatewayAccountIds.
@Test
public void shouldSuccess_whenProvidedWith_multipleValidNames_andNoGatewayAccountIds() {
Map<SupportedLanguage, String> serviceNames = new HashMap<>();
serviceNames.put(SupportedLanguage.ENGLISH, EN_SERVICE_NAME);
serviceNames.put(SupportedLanguage.WELSH, CY_SERVICE_NAME);
Service service = serviceCreator.doCreate(Collections.emptyList(), serviceNames);
verify(mockedServiceDao, never()).checkIfGatewayAccountsUsed(anyList());
verify(mockedServiceDao, times(1)).persist(persistedServiceEntity.capture());
assertThat(service.getName(), is(EN_SERVICE_NAME));
List<GatewayAccountIdEntity> persistedGatewayIds = persistedServiceEntity.getValue().getGatewayAccountIds();
assertThat(persistedGatewayIds.size(), is(0));
assertEnServiceNameMap(service, EN_SERVICE_NAME);
assertThat(service.getServiceNames(), hasKey(SupportedLanguage.WELSH.toString()));
assertThat(service.getServiceNames(), hasValue(CY_SERVICE_NAME));
assertSelfLink(service);
}
use of uk.gov.service.payments.commons.model.SupportedLanguage in project pay-products by alphagov.
the class PaymentCreatorTest method shouldCreateAMotoPaymentWithCardAgentInitiatedMotoSource_whenProductIsAgentInitiatedMoto.
@Test
public void shouldCreateAMotoPaymentWithCardAgentInitiatedMotoSource_whenProductIsAgentInitiatedMoto() {
PowerMockito.mockStatic(RandomIdGenerator.class);
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.ENGLISH;
Long priceOverride = 500L;
ProductEntity productEntity = createProductEntity(productId, ProductType.AGENT_INITIATED_MOTO, productPrice, productExternalId, productName, "", productApiToken, gatewayAccountId, true, language);
PaymentRequest expectedPaymentRequest = createPaymentRequest(priceOverride, userDefinedReference, productName, productReturnUrl + "/" + paymentExternalId, language, true, Map.of(), CARD_AGENT_INITIATED_MOTO);
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.service.payments.commons.model.SupportedLanguage in project pay-products by alphagov.
the class PaymentCreatorTest method shouldThrowPaymentCreationException_whenReferenceEnabledAndNoReferencePresent.
@Test
public void shouldThrowPaymentCreationException_whenReferenceEnabledAndNoReferencePresent() {
int productId = 1;
String productExternalId = "product-external-id";
long productPrice = 100L;
String productName = "name";
String productReturnUrl = "https://return.url";
String productApiToken = "api-token";
SupportedLanguage language = SupportedLanguage.WELSH;
Integer gatewayAccountId = 1;
ProductEntity productEntity = createProductEntity(productId, productPrice, productExternalId, productName, productReturnUrl, productApiToken, gatewayAccountId, true, language);
when(productDao.findByExternalId(productExternalId)).thenReturn(Optional.of(productEntity));
thrown.expect(BadPaymentRequestException.class);
thrown.expectMessage("User defined reference is enabled but missing");
paymentCreator.doCreate(productExternalId, null, null);
}
Aggregations