Search in sources :

Example 1 with SupportedLanguage

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));
}
Also used : Response(javax.ws.rs.core.Response) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) Service(uk.gov.pay.adminusers.model.Service) StripeAgreementService(uk.gov.pay.adminusers.service.StripeAgreementService) SendLiveAccountCreatedEmailService(uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService) GovUkPayAgreementService(uk.gov.pay.adminusers.service.GovUkPayAgreementService) JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.jupiter.api.Test)

Example 2 with SupportedLanguage

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();
}
Also used : SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) Service(uk.gov.pay.adminusers.model.Service) GovUkPayAgreementService(uk.gov.pay.adminusers.service.GovUkPayAgreementService) StripeAgreementService(uk.gov.pay.adminusers.service.StripeAgreementService) SendLiveAccountCreatedEmailService(uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 3 with SupportedLanguage

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);
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) HashMap(java.util.HashMap) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 4 with SupportedLanguage

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)));
}
Also used : Payment(uk.gov.pay.products.model.Payment) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) PaymentRequest(uk.gov.pay.products.client.publicapi.PaymentRequest) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) PaymentResponse(uk.gov.pay.products.client.publicapi.PaymentResponse) PaymentEntity(uk.gov.pay.products.persistence.entity.PaymentEntity) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SupportedLanguage

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);
}
Also used : SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SupportedLanguage (uk.gov.service.payments.commons.model.SupportedLanguage)17 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)8 PaymentEntity (uk.gov.pay.products.persistence.entity.PaymentEntity)7 PaymentRequest (uk.gov.pay.products.client.publicapi.PaymentRequest)6 PaymentResponse (uk.gov.pay.products.client.publicapi.PaymentResponse)5 Payment (uk.gov.pay.products.model.Payment)5 JsonObject (javax.json.JsonObject)4 Service (uk.gov.pay.adminusers.model.Service)3 PublicApiStub.setupResponseToCreatePaymentRequest (uk.gov.pay.products.stubs.publicapi.PublicApiStub.setupResponseToCreatePaymentRequest)3 PublicApiStub.setupResponseToGetPaymentRequest (uk.gov.pay.products.stubs.publicapi.PublicApiStub.setupResponseToGetPaymentRequest)3 Test (org.junit.jupiter.api.Test)2 GovUkPayAgreementService (uk.gov.pay.adminusers.service.GovUkPayAgreementService)2 SendLiveAccountCreatedEmailService (uk.gov.pay.adminusers.service.SendLiveAccountCreatedEmailService)2 StripeAgreementService (uk.gov.pay.adminusers.service.StripeAgreementService)2 PublicApiResponseErrorException (uk.gov.pay.products.exception.PublicApiResponseErrorException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Transactional (com.google.inject.persist.Transactional)1 JsonPath (io.restassured.path.json.JsonPath)1