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