use of uk.gov.pay.connector.token.model.domain.TokenEntity in project pay-connector by alphagov.
the class ChargeServiceFindTest method shouldFindChargeForChargeIdAndAccountIdWithNextUrlWhenChargeStatusIs.
@Test
@Parameters({ "CREATED", "ENTERING_CARD_DETAILS", "AUTHORISATION_READY" })
public void shouldFindChargeForChargeIdAndAccountIdWithNextUrlWhenChargeStatusIs(String status) throws Exception {
Long chargeId = 101L;
ChargeEntity newCharge = aValidChargeEntity().withId(chargeId).withGatewayAccountEntity(gatewayAccount).withStatus(ChargeStatus.valueOf(status)).withWalletType(WalletType.APPLE_PAY).build();
String externalId = newCharge.getExternalId();
doAnswer(invocation -> fromUri(SERVICE_HOST)).when(this.mockedUriInfo).getBaseUriBuilder();
when(mockedLinksConfig.getFrontendUrl()).thenReturn("http://frontend.test");
when(mockedProviders.byName(any(PaymentGatewayName.class))).thenReturn(mockedPaymentProvider);
when(mockedPaymentProvider.getExternalChargeRefundAvailability(any(Charge.class), any(List.class))).thenReturn(EXTERNAL_AVAILABLE);
when(mockedChargeDao.findByExternalIdAndGatewayAccount(externalId, GATEWAY_ACCOUNT_ID)).thenReturn(Optional.ofNullable(newCharge));
Optional<ChargeResponse> chargeResponseForAccount = service.findChargeForAccount(externalId, GATEWAY_ACCOUNT_ID, mockedUriInfo);
verify(mockedTokenDao).persist(tokenEntityArgumentCaptor.capture());
TokenEntity tokenEntity = tokenEntityArgumentCaptor.getValue();
assertThat(tokenEntity.getChargeEntity().getId(), is(newCharge.getId()));
assertThat(tokenEntity.getToken(), is(notNullValue()));
ChargeResponse.ChargeResponseBuilder chargeResponseWithoutCorporateCardSurcharge = chargeResponseBuilderOf(newCharge);
chargeResponseWithoutCorporateCardSurcharge.withWalletType(WalletType.APPLE_PAY);
chargeResponseWithoutCorporateCardSurcharge.withLink("self", GET, new URI(SERVICE_HOST + "/v1/api/accounts/10/charges/" + externalId));
chargeResponseWithoutCorporateCardSurcharge.withLink("refunds", GET, new URI(SERVICE_HOST + "/v1/api/accounts/10/charges/" + externalId + "/refunds"));
chargeResponseWithoutCorporateCardSurcharge.withLink("next_url", GET, new URI("http://frontend.test/secure/" + tokenEntity.getToken()));
chargeResponseWithoutCorporateCardSurcharge.withLink("next_url_post", POST, new URI("http://frontend.test/secure"), "application/x-www-form-urlencoded", new HashMap<String, Object>() {
{
put("chargeTokenId", tokenEntity.getToken());
}
});
assertThat(chargeResponseForAccount.isPresent(), is(true));
final ChargeResponse chargeResponse = chargeResponseForAccount.get();
assertThat(chargeResponse.getCorporateCardSurcharge(), is(nullValue()));
assertThat(chargeResponse.getTotalAmount(), is(nullValue()));
assertThat(chargeResponse, is(chargeResponseWithoutCorporateCardSurcharge.build()));
assertThat(chargeResponse.getWalletType(), is(WalletType.APPLE_PAY));
}
use of uk.gov.pay.connector.token.model.domain.TokenEntity in project pay-connector by alphagov.
the class CardResource method authorise.
@POST
@Path("/v1/api/charges/authorise")
@Produces(APPLICATION_JSON)
public Response authorise(@Valid @NotNull AuthoriseRequest authoriseRequest) {
// Fields are removed from the MDC when the API responds in LoggingMDCResponseFilter
MDC.put(SECURE_TOKEN, authoriseRequest.getOneTimeToken());
authoriseRequest.validate();
TokenEntity tokenEntity = tokenService.validateAndMarkTokenAsUsedForMotoApi(authoriseRequest.getOneTimeToken());
MDCUtils.addChargeAndGatewayAccountDetailsToMDC(tokenEntity.getChargeEntity());
CardInformation cardInformation = motoApiCardNumberValidationService.validateCardNumber(tokenEntity.getChargeEntity(), authoriseRequest.getCardNumber());
AuthorisationResponse response = cardAuthoriseService.doAuthoriseMotoApi(tokenEntity.getChargeEntity(), cardInformation, authoriseRequest);
return handleAuthResponseForMotoApi(response);
}
use of uk.gov.pay.connector.token.model.domain.TokenEntity in project pay-connector by alphagov.
the class TokenDaoJpaIT method findByTokenId_shouldFindUnusedToken.
@Test
public void findByTokenId_shouldFindUnusedToken() {
String tokenId = "qwerty";
databaseTestHelper.addToken(defaultTestCharge.getChargeId(), tokenId);
TokenEntity entity = tokenDao.findByTokenId(tokenId).get();
assertThat(entity.getId(), is(notNullValue()));
assertThat(entity.getChargeEntity().getId(), is(defaultTestCharge.getChargeId()));
assertThat(entity.getToken(), is(tokenId));
assertThat(entity.isUsed(), is(false));
}
use of uk.gov.pay.connector.token.model.domain.TokenEntity in project pay-connector by alphagov.
the class TokenDaoJpaIT method findByTokenId_shouldFindUsedToken.
@Test
public void findByTokenId_shouldFindUsedToken() {
String tokenId = "qwerty";
databaseTestHelper.addToken(defaultTestCharge.getChargeId(), tokenId, true);
TokenEntity entity = tokenDao.findByTokenId(tokenId).get();
assertThat(entity.getId(), is(notNullValue()));
assertThat(entity.getChargeEntity().getId(), is(defaultTestCharge.getChargeId()));
assertThat(entity.getToken(), is(tokenId));
assertThat(entity.isUsed(), is(true));
}
use of uk.gov.pay.connector.token.model.domain.TokenEntity in project pay-connector by alphagov.
the class TokenDaoJpaIT method deleteByCutOffDate_shouldDeleteOlderTokens.
@Test
public void deleteByCutOffDate_shouldDeleteOlderTokens() {
ZonedDateTime today = ZonedDateTime.now(ZoneId.of("UTC"));
ChargeEntityFixture chargeEntityFixture = new ChargeEntityFixture();
ChargeEntity chargeTestEntity = chargeEntityFixture.build();
chargeTestEntity.setId(defaultTestCharge.getChargeId());
TokenEntity presentDayToken = TokenEntity.generateNewTokenFor(chargeTestEntity);
presentDayToken.setCreatedDate(today);
presentDayToken.setToken("present-day-token");
tokenDao.persist(presentDayToken);
TokenEntity olderThanExpiryThreshold = TokenEntity.generateNewTokenFor(chargeTestEntity);
olderThanExpiryThreshold.setCreatedDate(today.minusDays(8));
olderThanExpiryThreshold.setToken("old-token");
tokenDao.persist(olderThanExpiryThreshold);
final ZonedDateTime expiryThreshold = today.minusDays(7);
tokenDao.deleteTokensOlderThanSpecifiedDate(expiryThreshold);
assertThat(tokenDao.findByTokenId("old-token"), isEmpty());
assertThat(tokenDao.findByTokenId("present-day-token"), isPresent());
}
Aggregations