Search in sources :

Example 1 with TelephoneChargeCreateRequest

use of uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest 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 2 with TelephoneChargeCreateRequest

use of uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest 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 3 with TelephoneChargeCreateRequest

use of uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest in project pay-connector by alphagov.

the class ZoneDateTimeValidatorTest method passesValidationForValidCreatedDate.

@Test
public void passesValidationForValidCreatedDate() {
    TelephoneChargeCreateRequest telephoneChargeCreateRequest = telephoneRequestBuilder.withCreatedDate("2018-02-21T16:04:25Z").build();
    Set<ConstraintViolation<TelephoneChargeCreateRequest>> constraintViolations = validator.validate(telephoneChargeCreateRequest);
    assertThat(constraintViolations.isEmpty(), is(true));
}
Also used : TelephoneChargeCreateRequest(uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 4 with TelephoneChargeCreateRequest

use of uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest 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)

Example 5 with TelephoneChargeCreateRequest

use of uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest in project pay-connector by alphagov.

the class ChargeServiceCreateTest method shouldCreateATelephoneChargeForFailureCodeOfP0050.

@Test
public void shouldCreateATelephoneChargeForFailureCodeOfP0050() {
    when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(gatewayAccountCredentialsEntity);
    Supplemental supplemental = new Supplemental("ECKOH01234", "textual message describing error code");
    PaymentOutcome paymentOutcome = new PaymentOutcome("failed", "P0050", supplemental);
    Map<String, Object> metadata = Map.of("created_date", "2018-02-21T16:04:25Z", "authorised_date", "2018-02-21T16:05:33Z", "processor_id", "1PROC", "auth_code", "666", "telephone_number", "+447700900796", "status", "failed", "code", "P0050", "error_code", "ECKOH01234", "error_message", "textual message describing error code");
    TelephoneChargeCreateRequest telephoneChargeCreateRequest = telephoneRequestBuilder.withPaymentOutcome(paymentOutcome).withCardExpiry(null).build();
    populateChargeEntity();
    service.createFromTelephonePaymentNotification(telephoneChargeCreateRequest, gatewayAccount);
    verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture());
    ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue();
    assertThat(createdChargeEntity.getId(), is(CHARGE_ENTITY_ID));
    assertThat(createdChargeEntity.getGatewayAccount().getId(), is(GATEWAY_ACCOUNT_ID));
    assertThat(createdChargeEntity.getExternalId(), is(EXTERNAL_CHARGE_ID[0]));
    assertThat(createdChargeEntity.getGatewayAccount().getGatewayName(), is("sandbox"));
    assertThat(createdChargeEntity.getPaymentProvider(), is("sandbox"));
    assertThat(createdChargeEntity.getAmount(), is(100L));
    assertThat(createdChargeEntity.getReference(), is(ServicePaymentReference.of("Some reference")));
    assertThat(createdChargeEntity.getDescription(), is("Some description"));
    assertThat(createdChargeEntity.getStatus(), is("AUTHORISATION ERROR"));
    assertThat(createdChargeEntity.getEmail(), is("jane.doe@example.com"));
    assertThat(ZonedDateTime.ofInstant(createdChargeEntity.getCreatedDate(), ZoneOffset.UTC), is(ZonedDateTimeMatchers.within(3, ChronoUnit.SECONDS, now(ZoneOffset.UTC))));
    assertThat(createdChargeEntity.getCardDetails().getLastDigitsCardNumber().toString(), is("1234"));
    assertThat(createdChargeEntity.getCardDetails().getFirstDigitsCardNumber().toString(), is("123456"));
    assertThat(createdChargeEntity.getCardDetails().getCardHolderName(), is("Jane Doe"));
    assertThat(createdChargeEntity.getCardDetails().getExpiryDate(), is(nullValue()));
    assertThat(createdChargeEntity.getCardDetails().getCardBrand(), is("visa"));
    assertThat(createdChargeEntity.getGatewayTransactionId(), is("1PROV"));
    assertThat(createdChargeEntity.getExternalMetadata().get().getMetadata(), equalTo(metadata));
    assertThat(createdChargeEntity.getLanguage(), is(SupportedLanguage.ENGLISH));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) 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) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 TelephoneChargeCreateRequest (uk.gov.pay.connector.charge.model.telephone.TelephoneChargeCreateRequest)31 ConstraintViolation (javax.validation.ConstraintViolation)20 PaymentOutcome (uk.gov.pay.connector.charge.model.telephone.PaymentOutcome)16 Supplemental (uk.gov.pay.connector.charge.model.telephone.Supplemental)8 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)7 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)7 ChargeResponse (uk.gov.pay.connector.charge.model.ChargeResponse)4 CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1