Search in sources :

Example 1 with PaymentOutcome

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;
}
Also used : PersistedCard(uk.gov.pay.connector.charge.model.domain.PersistedCard) Supplemental(uk.gov.pay.connector.charge.model.telephone.Supplemental) PaymentOutcome(uk.gov.pay.connector.charge.model.telephone.PaymentOutcome) ExternalChargeState(uk.gov.pay.connector.common.model.api.ExternalChargeState) ExternalTransactionState(uk.gov.pay.connector.common.model.api.ExternalTransactionState) ChargeStatus.fromString(uk.gov.pay.connector.charge.model.domain.ChargeStatus.fromString) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse)

Example 2 with PaymentOutcome

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"));
}
Also used : TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PaymentOutcome(uk.gov.pay.connector.charge.model.telephone.PaymentOutcome) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 3 with PaymentOutcome

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"));
}
Also used : Supplemental(uk.gov.pay.connector.charge.model.telephone.Supplemental) TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PaymentOutcome(uk.gov.pay.connector.charge.model.telephone.PaymentOutcome) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 4 with PaymentOutcome

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"));
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) PaymentOutcome(uk.gov.pay.connector.charge.model.telephone.PaymentOutcome) BeforeClass(org.junit.BeforeClass)

Example 5 with PaymentOutcome

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));
}
Also used : TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) PaymentOutcome(uk.gov.pay.connector.charge.model.telephone.PaymentOutcome) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) Test(org.junit.Test)

Aggregations

PaymentOutcome (uk.gov.pay.connector.charge.model.telephone.PaymentOutcome)21 Test (org.junit.Test)16 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)16 Supplemental (uk.gov.pay.connector.charge.model.telephone.Supplemental)9 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)7 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)7 ConstraintViolation (javax.validation.ConstraintViolation)5 ChargeResponse (uk.gov.pay.connector.charge.model.ChargeResponse)5 ValidatorFactory (javax.validation.ValidatorFactory)4 BeforeClass (org.junit.BeforeClass)4 CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)1 ChargeStatus.fromString (uk.gov.pay.connector.charge.model.domain.ChargeStatus.fromString)1 PersistedCard (uk.gov.pay.connector.charge.model.domain.PersistedCard)1 ExternalChargeState (uk.gov.pay.connector.common.model.api.ExternalChargeState)1 ExternalTransactionState (uk.gov.pay.connector.common.model.api.ExternalTransactionState)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1