use of uk.gov.service.payments.commons.model.Source in project pay-publicapi by alphagov.
the class RequestJsonParser method validateAndGetSource.
private static Source validateAndGetSource(JsonNode paymentRequest) {
if (paymentRequest.has(INTERNAL)) {
JsonNode internalNode = paymentRequest.get(INTERNAL);
if (internalNode.has(SOURCE_FIELD_NAME)) {
String errorMessage = "Accepted values are only CARD_PAYMENT_LINK, CARD_AGENT_INITIATED_MOTO";
PaymentError paymentError = aPaymentError(SOURCE_FIELD_NAME, CREATE_PAYMENT_VALIDATION_ERROR, errorMessage);
String sourceString = validateSkipNullValueAndGetString(internalNode.get(SOURCE_FIELD_NAME), paymentError);
try {
Source source = Source.valueOf(sourceString);
if (ALLOWED_SOURCES.contains(source)) {
return source;
}
throw new BadRequestException(paymentError);
} catch (IllegalArgumentException e) {
throw new WebApplicationException(Response.status(SC_UNPROCESSABLE_ENTITY).entity(paymentError).build());
}
}
}
return CARD_API;
}
use of uk.gov.service.payments.commons.model.Source in project pay-products by alphagov.
the class PaymentCreator method paymentCreation.
private NonTransactionalOperation<TransactionContext, PaymentEntity> paymentCreation(Long priceOverride) {
return context -> {
PaymentEntity paymentEntity = context.get(PaymentEntity.class);
ProductEntity productEntity = paymentEntity.getProductEntity();
String returnUrl = format("%s/%s", productsConfiguration.getProductsUiConfirmUrl(), paymentEntity.getExternalId());
Long paymentPrice = priceOverride != null ? priceOverride : productEntity.getPrice();
boolean isMoto = productEntity.getType() == ProductType.AGENT_INITIATED_MOTO;
Source source = productEntity.getType() == ProductType.AGENT_INITIATED_MOTO ? Source.CARD_AGENT_INITIATED_MOTO : Source.CARD_PAYMENT_LINK;
PaymentRequest paymentRequest = new PaymentRequest(paymentPrice, paymentEntity.getReferenceNumber(), productEntity.getName(), returnUrl, productEntity.getLanguage(), isMoto, productEntity.toProductMetadataMap(), source);
try {
PaymentResponse paymentResponse = publicApiRestClient.createPayment(productEntity.getPayApiToken(), paymentRequest);
paymentEntity.setGovukPaymentId(paymentResponse.getPaymentId());
paymentEntity.setNextUrl(getNextUrl(paymentResponse));
paymentEntity.setStatus(PaymentStatus.SUBMITTED);
paymentEntity.setAmount(paymentResponse.getAmount());
logger.info("Payment creation for product external id {} successful", paymentEntity.getProductEntity().getExternalId(), kv(PAYMENT_EXTERNAL_ID, paymentEntity.getGovukPaymentId()), kv("product_external_id", paymentEntity.getProductEntity().getExternalId()));
if (PanDetector.isSuspectedPan(paymentEntity.getReferenceNumber())) {
logger.warn("Suspected PAN entered by user in reference field", kv(PAYMENT_EXTERNAL_ID, paymentEntity.getGovukPaymentId()), kv(GATEWAY_ACCOUNT_ID, paymentEntity.getGatewayAccountId()), kv("number_of_digits", PanDetector.cleanedReference(paymentEntity.getReferenceNumber()).length()));
}
} catch (PublicApiResponseErrorException e) {
logger.error("Payment creation for product external id {} failed {}", paymentEntity.getProductEntity().getExternalId(), e);
paymentEntity.setStatus(PaymentStatus.ERROR);
}
return paymentEntity;
};
}
use of uk.gov.service.payments.commons.model.Source in project pay-connector by alphagov.
the class SourceDeserialiserTest method shouldDeserialiseNullToNull.
@Test
void shouldDeserialiseNullToNull() throws IOException {
given(mockJsonParser.getValueAsString()).willReturn(null);
Source result = sourceDeserialiser.deserialize(mockJsonParser, mockDeserializationContext);
assertThat(result, is(nullValue()));
}
use of uk.gov.service.payments.commons.model.Source in project pay-connector by alphagov.
the class SourceDeserialiserTest method shouldDeserialiseAcceptedSources.
@ParameterizedTest
@EnumSource(value = Source.class, names = { "CARD_API", "CARD_PAYMENT_LINK", "CARD_AGENT_INITIATED_MOTO" })
void shouldDeserialiseAcceptedSources(Source source) throws IOException {
given(mockJsonParser.getValueAsString()).willReturn(source.name());
Source result = sourceDeserialiser.deserialize(mockJsonParser, mockDeserializationContext);
assertThat(result, is(source));
}
Aggregations