Search in sources :

Example 1 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-products by alphagov.

the class ProductCreatorTest method update_shouldUpdateProduct.

@Test
public void update_shouldUpdateProduct() {
    ProductEntity productEntity = aProductEntity().withRequireCaptcha(false).build();
    when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.of(productEntity));
    JsonPatchRequest patchRequest = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("path", "require_captcha", "op", "replace", "value", true)));
    Product updatedProduct = productCreator.update(gatewayAccountId, externalId, Collections.singletonList(patchRequest));
    assertThat(updatedProduct.isRequireCaptcha(), is(true));
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) Product(uk.gov.pay.products.model.Product) ProductEntityFixture.aProductEntity(uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Test(org.junit.Test)

Example 2 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountCredentialsService method updateGatewayAccountCredentials.

@Transactional
public GatewayAccountCredentials updateGatewayAccountCredentials(GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity, Iterable<JsonPatchRequest> updateRequests) {
    for (JsonPatchRequest updateRequest : updateRequests) {
        if (JsonPatchOp.REPLACE == updateRequest.getOp()) {
            updateGatewayAccountCredentialField(updateRequest, gatewayAccountCredentialsEntity);
        }
    }
    gatewayAccountCredentialsDao.merge(gatewayAccountCredentialsEntity);
    GatewayAccountEntity gatewayAccountEntity = gatewayAccountCredentialsEntity.getGatewayAccountEntity();
    LOGGER.info("Updated credentials for gateway account [id={}]", gatewayAccountEntity.getId(), kv(GATEWAY_ACCOUNT_ID, gatewayAccountEntity.getId()), kv(GATEWAY_ACCOUNT_TYPE, gatewayAccountEntity.getType()), kv(PROVIDER, gatewayAccountCredentialsEntity.getPaymentProvider()), kv("state", gatewayAccountCredentialsEntity.getState()), kv(USER_EXTERNAL_ID, gatewayAccountCredentialsEntity.getLastUpdatedByUserExternalId()));
    return new GatewayAccountCredentials(gatewayAccountCredentialsEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentials(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountCredentials) Transactional(com.google.inject.persist.Transactional)

Example 3 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountCredentialsServiceTest method shouldNotChangeState_whenCredentialsNotInCreatedState.

@Test
void shouldNotChangeState_whenCredentialsNotInCreatedState() {
    GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().build();
    GatewayAccountCredentialsEntity credentialsEntity = aGatewayAccountCredentialsEntity().withGatewayAccountEntity(gatewayAccountEntity).withState(VERIFIED_WITH_LIVE_PAYMENT).build();
    gatewayAccountEntity.setGatewayAccountCredentials(List.of(credentialsEntity));
    JsonPatchRequest patchRequest = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("path", "credentials", "op", "replace", "value", Map.of("merchant_id", "new-merchant-id"))));
    gatewayAccountCredentialsService.updateGatewayAccountCredentials(credentialsEntity, Collections.singletonList(patchRequest));
    assertThat(credentialsEntity.getState(), is(VERIFIED_WITH_LIVE_PAYMENT));
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldUpdateMotoMaskCardSecurityCodeInputTrue.

@Test
public void shouldUpdateMotoMaskCardSecurityCodeInputTrue() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", "moto_mask_card_security_code_input", "value", true)));
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    Optional<GatewayAccount> optionalGatewayAccount = gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request);
    assertThat(optionalGatewayAccount.isPresent(), is(true));
    verify(mockGatewayAccountEntity).setMotoMaskCardSecurityCodeInput(true);
    verify(mockGatewayAccountDao).merge(mockGatewayAccountEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccount(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount) Test(org.junit.jupiter.api.Test)

Example 5 with JsonPatchRequest

use of uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest in project pay-connector by alphagov.

the class GatewayAccountServiceTest method shouldUpdateAllowZeroAmountFalse.

@Test
public void shouldUpdateAllowZeroAmountFalse() {
    JsonPatchRequest request = JsonPatchRequest.from(objectMapper.valueToTree(Map.of("op", "replace", "path", "allow_zero_amount", "value", false)));
    when(mockGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(mockGatewayAccountEntity));
    Optional<GatewayAccount> optionalGatewayAccount = gatewayAccountService.doPatch(GATEWAY_ACCOUNT_ID, request);
    assertThat(optionalGatewayAccount.isPresent(), is(true));
    verify(mockGatewayAccountEntity).setAllowZeroAmount(false);
    verify(mockGatewayAccountDao).merge(mockGatewayAccountEntity);
}
Also used : JsonPatchRequest(uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest) GatewayAccount(uk.gov.pay.connector.gatewayaccount.model.GatewayAccount) Test(org.junit.jupiter.api.Test)

Aggregations

JsonPatchRequest (uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest)39 Test (org.junit.jupiter.api.Test)36 GatewayAccount (uk.gov.pay.connector.gatewayaccount.model.GatewayAccount)28 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 GatewayAccountEntityFixture.aGatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity)4 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)4 GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity)4 InOrder (org.mockito.InOrder)3 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Transactional (com.google.inject.persist.Transactional)1 GatewayAccountCredentials (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountCredentials)1 ProductEntityFixture.aProductEntity (uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity)1 Product (uk.gov.pay.products.model.Product)1 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)1