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