Search in sources :

Example 1 with CREATED

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;
}
Also used : CardExpiryDate(uk.gov.service.payments.commons.model.CardExpiryDate) DefaultExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.DefaultExternalRefundAvailabilityCalculator) ZonedDateTime(java.time.ZonedDateTime) CREATED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.CREATED) RefundEntity(uk.gov.pay.connector.refund.model.domain.RefundEntity) PAYMENT_NOTIFICATION_CREATED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.PAYMENT_NOTIFICATION_CREATED) SettlementSummary(uk.gov.pay.connector.client.ledger.model.SettlementSummary) FirstDigitsCardNumber(uk.gov.pay.connector.charge.model.FirstDigitsCardNumber) CardBrandLabelEntity(uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Charge(uk.gov.pay.connector.charge.model.domain.Charge) CAPTURED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.CAPTURED) TransactionState(uk.gov.pay.connector.client.ledger.model.TransactionState) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity) ExternalChargeRefundAvailability(uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability) ChargeEventEntity(uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity) CardDetails(uk.gov.pay.connector.client.ledger.model.CardDetails) Address(uk.gov.pay.connector.client.ledger.model.Address) LedgerTransaction(uk.gov.pay.connector.client.ledger.model.LedgerTransaction) Optional.ofNullable(java.util.Optional.ofNullable) CAPTURE_SUBMITTED(uk.gov.pay.connector.charge.model.domain.ChargeStatus.CAPTURE_SUBMITTED) LastDigitsCardNumber(uk.gov.pay.connector.charge.model.LastDigitsCardNumber) Source(uk.gov.service.payments.commons.model.Source) Collectors(java.util.stream.Collectors) ThreeDSecure(uk.gov.pay.connector.client.ledger.model.ThreeDSecure) WalletType(uk.gov.pay.connector.wallets.WalletType) List(java.util.List) AuthorisationSummary(uk.gov.pay.connector.client.ledger.model.AuthorisationSummary) Refund(uk.gov.pay.connector.refund.model.domain.Refund) ISO_INSTANT_MILLISECOND_PRECISION(uk.gov.service.payments.commons.model.ApiResponseDateTimeFormatter.ISO_INSTANT_MILLISECOND_PRECISION) UTC(java.time.ZoneOffset.UTC) DateTimeUtils(uk.gov.pay.connector.util.DateTimeUtils) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) ChargeStatus(uk.gov.pay.connector.charge.model.domain.ChargeStatus) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) Objects.nonNull(java.util.Objects.nonNull) CorporateCardSurchargeCalculator.getTotalAmountFor(uk.gov.pay.connector.charge.util.CorporateCardSurchargeCalculator.getTotalAmountFor) DefaultExternalRefundAvailabilityCalculator(uk.gov.pay.connector.gateway.util.DefaultExternalRefundAvailabilityCalculator) Address(uk.gov.pay.connector.client.ledger.model.Address) CardBrandLabelEntity(uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity) FirstDigitsCardNumber(uk.gov.pay.connector.charge.model.FirstDigitsCardNumber) AuthorisationSummary(uk.gov.pay.connector.client.ledger.model.AuthorisationSummary) LastDigitsCardNumber(uk.gov.pay.connector.charge.model.LastDigitsCardNumber) CardExpiryDate(uk.gov.service.payments.commons.model.CardExpiryDate) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) ThreeDSecure(uk.gov.pay.connector.client.ledger.model.ThreeDSecure) ExternalChargeRefundAvailability(uk.gov.pay.connector.common.model.api.ExternalChargeRefundAvailability) CardDetails(uk.gov.pay.connector.client.ledger.model.CardDetails) ChargeResponse(uk.gov.pay.connector.charge.model.ChargeResponse) CardDetailsEntity(uk.gov.pay.connector.charge.model.CardDetailsEntity)

Aggregations

UTC (java.time.ZoneOffset.UTC)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 Objects.nonNull (java.util.Objects.nonNull)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors (java.util.stream.Collectors)1 CardBrandLabelEntity (uk.gov.pay.connector.cardtype.model.domain.CardBrandLabelEntity)1 CardDetailsEntity (uk.gov.pay.connector.charge.model.CardDetailsEntity)1 ChargeResponse (uk.gov.pay.connector.charge.model.ChargeResponse)1 FirstDigitsCardNumber (uk.gov.pay.connector.charge.model.FirstDigitsCardNumber)1 LastDigitsCardNumber (uk.gov.pay.connector.charge.model.LastDigitsCardNumber)1 Charge (uk.gov.pay.connector.charge.model.domain.Charge)1 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)1 ChargeStatus (uk.gov.pay.connector.charge.model.domain.ChargeStatus)1 CAPTURED (uk.gov.pay.connector.charge.model.domain.ChargeStatus.CAPTURED)1 CAPTURE_SUBMITTED (uk.gov.pay.connector.charge.model.domain.ChargeStatus.CAPTURE_SUBMITTED)1 CREATED (uk.gov.pay.connector.charge.model.domain.ChargeStatus.CREATED)1 PAYMENT_NOTIFICATION_CREATED (uk.gov.pay.connector.charge.model.domain.ChargeStatus.PAYMENT_NOTIFICATION_CREATED)1 CorporateCardSurchargeCalculator.getTotalAmountFor (uk.gov.pay.connector.charge.util.CorporateCardSurchargeCalculator.getTotalAmountFor)1 ChargeEventEntity (uk.gov.pay.connector.chargeevent.model.domain.ChargeEventEntity)1