use of uk.gov.pay.connector.charge.model.telephone.PaymentOutcome in project pay-connector by alphagov.
the class ChargeService method populateResponseBuilderWith.
private ChargeResponse.ChargeResponseBuilder populateResponseBuilderWith(AbstractChargeResponseBuilder<ChargeResponse.ChargeResponseBuilder, ChargeResponse> responseBuilder, ChargeEntity chargeEntity) {
PersistedCard persistedCard = null;
if (chargeEntity.getCardDetails() != null) {
persistedCard = chargeEntity.getCardDetails().toCard();
}
ChargeResponse.ChargeResponseBuilder builderOfResponse = responseBuilder.withAmount(chargeEntity.getAmount()).withReference(chargeEntity.getReference()).withDescription(chargeEntity.getDescription()).withProviderId(chargeEntity.getGatewayTransactionId()).withCardDetails(persistedCard).withEmail(chargeEntity.getEmail()).withChargeId(chargeEntity.getExternalId());
chargeEntity.getExternalMetadata().ifPresent(externalMetadata -> {
final PaymentOutcome paymentOutcome = new PaymentOutcome(externalMetadata.getMetadata().get("status").toString());
ExternalTransactionState state;
if (externalMetadata.getMetadata().get("status").toString().equals("success")) {
state = new ExternalTransactionState(externalMetadata.getMetadata().get("status").toString(), true);
} else {
String message = Stream.of(ExternalChargeState.values()).filter(chargeState -> chargeState.getCode() != null).collect(Collectors.toMap(ExternalChargeState::getCode, ExternalChargeState::getMessage)).get(externalMetadata.getMetadata().get("code").toString());
state = new ExternalTransactionState(externalMetadata.getMetadata().get("status").toString(), true, externalMetadata.getMetadata().get("code").toString(), message);
paymentOutcome.setCode(externalMetadata.getMetadata().get("code").toString());
}
if (externalMetadata.getMetadata().get("error_code") != null || externalMetadata.getMetadata().get("error_message") != null) {
paymentOutcome.setSupplemental(new Supplemental((String) externalMetadata.getMetadata().get("error_code"), (String) externalMetadata.getMetadata().get("error_message")));
}
if (externalMetadata.getMetadata().get("authorised_date") != null) {
builderOfResponse.withAuthorisedDate(ZonedDateTime.parse(((String) externalMetadata.getMetadata().get("authorised_date"))).toInstant());
}
if (externalMetadata.getMetadata().get("created_date") != null) {
builderOfResponse.withCreatedDate(ZonedDateTime.parse(((String) externalMetadata.getMetadata().get("created_date"))).toInstant());
}
builderOfResponse.withProcessorId((String) externalMetadata.getMetadata().get("processor_id")).withAuthCode((String) externalMetadata.getMetadata().get("auth_code")).withTelephoneNumber((String) externalMetadata.getMetadata().get("telephone_number")).withState(state).withPaymentOutcome(paymentOutcome);
});
return builderOfResponse;
}
use of uk.gov.pay.connector.charge.model.telephone.PaymentOutcome in project pay-connector by alphagov.
the class PaymentOutcomeValidatorTest method failsValidationForInvalidPaymentOutcomeStatus.
@Test
public void failsValidationForInvalidPaymentOutcomeStatus() {
TelephoneChargeCreateRequest telephoneChargeCreateRequest = telephoneRequestBuilder.withPaymentOutcome(new PaymentOutcome("invalid")).build();
Set<ConstraintViolation<TelephoneChargeCreateRequest>> constraintViolations = validator.validate(telephoneChargeCreateRequest);
assertThat(constraintViolations.size(), isNumber(1));
assertThat(constraintViolations.iterator().next().getMessage(), is("Field [payment_outcome] must include a valid status and error code"));
}
use of uk.gov.pay.connector.charge.model.telephone.PaymentOutcome in project pay-connector by alphagov.
the class PaymentOutcomeValidatorTest method failsValidationForInvalidErrorCode.
@Test
public void failsValidationForInvalidErrorCode() {
PaymentOutcome paymentOutcome = new PaymentOutcome("failed", "error", new Supplemental("ECKOH01234", "textual message describing error code"));
TelephoneChargeCreateRequest telephoneChargeCreateRequest = telephoneRequestBuilder.withPaymentOutcome(paymentOutcome).build();
Set<ConstraintViolation<TelephoneChargeCreateRequest>> constraintViolations = validator.validate(telephoneChargeCreateRequest);
assertThat(constraintViolations.size(), isNumber(1));
assertThat(constraintViolations.iterator().next().getMessage(), is("Field [payment_outcome] must include a valid status and error code"));
}
use of uk.gov.pay.connector.charge.model.telephone.PaymentOutcome in project pay-connector by alphagov.
the class ZoneDateTimeValidatorTest method setUpValidator.
@BeforeClass
public static void setUpValidator() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
telephoneRequestBuilder.withAmount(1200L).withDescription("Some description").withReference("Some reference").withProcessorId("1PROC").withProviderId("1PROV").withCardExpiry(CardExpiryDate.valueOf("01/99")).withCardType("visa").withLastFourDigits("1234").withFirstSixDigits("123456").withPaymentOutcome(new PaymentOutcome("success"));
}
use of uk.gov.pay.connector.charge.model.telephone.PaymentOutcome in project pay-connector by alphagov.
the class ChargeServiceFindTest method shouldNotFindCharge.
@Test
public void shouldNotFindCharge() {
PaymentOutcome paymentOutcome = new PaymentOutcome("success");
TelephoneChargeCreateRequest telephoneChargeCreateRequest = telephoneRequestBuilder.withProviderId("new").withPaymentOutcome(paymentOutcome).build();
Optional<ChargeResponse> telephoneChargeResponse = service.findCharge(1234L, telephoneChargeCreateRequest);
ArgumentCaptor<String> gatewayTransactionIdArgumentCaptor = forClass(String.class);
verify(mockedChargeDao).findByGatewayTransactionIdAndAccount(anyLong(), gatewayTransactionIdArgumentCaptor.capture());
String providerId = gatewayTransactionIdArgumentCaptor.getValue();
assertThat(providerId, is("new"));
assertThat(telephoneChargeResponse.isPresent(), is(false));
}
Aggregations