use of uk.gov.pay.connector.charge.model.domain.ChargeStatus.CREATED in project pay-connector by alphagov.
the class LedgerTransactionFixture method from.
public static LedgerTransactionFixture from(ChargeEntity chargeEntity, List<RefundEntity> refundsList) {
LedgerTransactionFixture ledgerTransactionFixture = aValidLedgerTransaction().withCreatedDate(chargeEntity.getCreatedDate().atZone(UTC)).withStatus(ChargeStatus.fromString(chargeEntity.getStatus()).toExternal().getStatusV2()).withExternalId(chargeEntity.getExternalId()).withAmount(chargeEntity.getAmount()).withDescription(chargeEntity.getDescription()).withReference(chargeEntity.getReference().toString()).withLanguage(chargeEntity.getLanguage()).withEmail(chargeEntity.getEmail()).withReturnUrl(chargeEntity.getReturnUrl()).withGatewayTransactionId(chargeEntity.getGatewayTransactionId()).withCredentialExternalId(chargeEntity.getGatewayAccountCredentialsEntity().getExternalId()).withDelayedCapture(chargeEntity.isDelayedCapture()).withSource(chargeEntity.getSource()).withMoto(chargeEntity.isMoto()).withFee(chargeEntity.getFeeAmount().orElse(null)).withCorporateCardSurcharge(chargeEntity.getCorporateSurcharge().orElse(null)).withWalletType(chargeEntity.getWalletType()).withTotalAmount(getTotalAmountFor(chargeEntity)).withNetAmount(chargeEntity.getNetAmount().orElse(null));
ledgerTransactionFixture.withCreatedDate(getEventDate(chargeEntity.getEvents(), List.of(CREATED, PAYMENT_NOTIFICATION_CREATED)));
if (chargeEntity.getGatewayAccount() != null) {
GatewayAccountEntity gatewayAccount = chargeEntity.getGatewayAccount();
ledgerTransactionFixture.withPaymentProvider(chargeEntity.getPaymentProvider());
ledgerTransactionFixture.withGatewayAccountId(gatewayAccount.getId());
ledgerTransactionFixture.isLive(gatewayAccount.isLive());
}
if (nonNull(chargeEntity.getCardDetails())) {
CardDetailsEntity chargeEntityCardDetails = chargeEntity.getCardDetails();
Address ledgerAddress = chargeEntityCardDetails.getBillingAddress().map(addressEntity -> {
return new Address(addressEntity.getLine1(), addressEntity.getLine2(), addressEntity.getPostcode(), addressEntity.getCity(), addressEntity.getCounty(), addressEntity.getCountry());
}).orElse(null);
CardDetails cardDetails = new CardDetails(chargeEntityCardDetails.getCardHolderName(), ledgerAddress, chargeEntityCardDetails.getCardTypeDetails().map(CardBrandLabelEntity::getLabel).orElse(null), ofNullable(chargeEntityCardDetails.getLastDigitsCardNumber()).map(LastDigitsCardNumber::toString).orElse(null), ofNullable(chargeEntityCardDetails.getFirstDigitsCardNumber()).map(FirstDigitsCardNumber::toString).orElse(null), ofNullable(chargeEntityCardDetails.getExpiryDate()).map(CardExpiryDate::toString).orElse(null), ofNullable(chargeEntityCardDetails.getCardType()).map(cardType -> cardType.toString().toLowerCase()).orElse(null));
ledgerTransactionFixture.withCardDetails(cardDetails);
}
ledgerTransactionFixture.withCapturedDate(getEventDate(chargeEntity.getEvents(), List.of(CAPTURED)));
ledgerTransactionFixture.withCaptureSubmittedDate(getEventDate(chargeEntity.getEvents(), List.of(CAPTURE_SUBMITTED)));
ChargeResponse.RefundSummary refundSummary = new ChargeResponse.RefundSummary();
ExternalChargeRefundAvailability refundAvailability;
if (refundsList != null) {
refundAvailability = new DefaultExternalRefundAvailabilityCalculator().calculate(Charge.from(chargeEntity), refundsList.stream().map(Refund::from).collect(Collectors.toList()));
} else {
refundAvailability = new DefaultExternalRefundAvailabilityCalculator().calculate(Charge.from(chargeEntity), List.of());
}
refundSummary.setStatus(refundAvailability.getStatus());
ledgerTransactionFixture.withRefundSummary(refundSummary);
if (chargeEntity.get3dsRequiredDetails() != null) {
AuthorisationSummary authorisationSummary = new AuthorisationSummary();
ThreeDSecure threeDSecure = new ThreeDSecure();
threeDSecure.setRequired(true);
threeDSecure.setVersion(chargeEntity.get3dsRequiredDetails().getThreeDsVersion());
authorisationSummary.setThreeDSecure(threeDSecure);
ledgerTransactionFixture.withAuthorisationSummary(authorisationSummary);
}
return ledgerTransactionFixture;
}
Aggregations