Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-12826 Update Gateway Request classes to records #5388

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private StripeFeeCalculator() {
}

public static Long getTotalAmountForConnectFee(Long stripeFee, CaptureGatewayRequest request, Double feePercentage) {
Double platformFee = getPlatformFee(feePercentage, request.getAmount());
Double platformFee = getPlatformFee(feePercentage, request.amount());
return stripeFee + platformFee.longValue();
}

Expand All @@ -41,7 +41,7 @@ private static Double getPlatformFee(Double feePercentage, Long grossChargeAmoun
}

private static boolean is3dsUsed(CaptureGatewayRequest request) {
return request.getEvents()
return request.events()
.stream()
.anyMatch(chargeEventEntity -> chargeEventEntity.getStatus().equals(AUTHORISATION_3DS_REQUIRED));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,31 @@
import uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity;
import uk.gov.service.payments.commons.model.AuthorisationMode;

public class ChargeQueryGatewayRequest implements GatewayRequest {

private final GatewayAccountEntity gatewayAccountEntity;
private final GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity;
private final String chargeExternalId;
private final String transactionId;
private final AuthorisationMode authorisationMode;
private boolean isForRecurringPayment;

public ChargeQueryGatewayRequest(GatewayAccountEntity gatewayAccountEntity, GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity,
String chargeExternalId, String transactionId, AuthorisationMode authorisationMode, boolean isForRecurringPayment) {
this.gatewayAccountEntity = gatewayAccountEntity;
this.gatewayAccountCredentialsEntity = gatewayAccountCredentialsEntity;
this.chargeExternalId = chargeExternalId;
this.transactionId = transactionId;
this.authorisationMode = authorisationMode;
this.isForRecurringPayment = isForRecurringPayment;
}

import java.util.Optional;

public record ChargeQueryGatewayRequest (
GatewayAccountEntity gatewayAccount,
GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity,
String chargeExternalId,
String transactionId,
AuthorisationMode authorisationMode,
boolean isForRecurringPayment
) implements GatewayRequest {
@Override
public GatewayAccountEntity getGatewayAccount() {
return gatewayAccountEntity;
public GatewayAccountEntity gatewayAccount() {
return gatewayAccount;
}

@Override
public GatewayOperation getRequestType() {
public GatewayOperation requestType() {
return GatewayOperation.QUERY;
}

public String getChargeExternalId() {
return chargeExternalId;
}

public String getTransactionId() {
return transactionId;
}

public AuthorisationMode getAuthorisationMode() {
return authorisationMode;
@Override
public GatewayCredentials gatewayCredentials() {
return gatewayAccountCredentialsEntity.getCredentialsObject();
}

@Override
public GatewayCredentials getGatewayCredentials() {
return gatewayAccountCredentialsEntity.getCredentialsObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@

import java.util.Optional;

public class Auth3dsResponseGatewayRequest implements GatewayRequest {

private final ChargeEntity charge;
private final Auth3dsResult auth3dsResult;

public Auth3dsResponseGatewayRequest(ChargeEntity charge, Auth3dsResult auth3dsResult) {
this.charge = charge;
this.auth3dsResult = auth3dsResult;
}

public Auth3dsResult getAuth3dsResult() {
return auth3dsResult;
}

public record Auth3dsResponseGatewayRequest (
ChargeEntity charge,
Auth3dsResult auth3dsResult
) implements GatewayRequest {
public Optional<String> getTransactionId() {
return Optional.ofNullable(charge.getGatewayTransactionId());
}
Expand All @@ -36,30 +26,22 @@ public String getChargeExternalId() {
public Optional<ProviderSessionIdentifier> getProviderSessionId() {
return Optional.ofNullable(charge.getProviderSessionId()).map(ProviderSessionIdentifier::of);
}

public ChargeEntity getCharge() {
return charge;
public Optional<String> transactionId() {
return Optional.ofNullable(charge.getGatewayTransactionId());
}

@Override
public GatewayAccountEntity getGatewayAccount() {
return charge.getGatewayAccount();
}
public GatewayAccountEntity gatewayAccount() { return charge.getGatewayAccount(); }

@Override
public GatewayOperation getRequestType() {
return GatewayOperation.AUTHORISE;
}
public GatewayOperation requestType() { return GatewayOperation.AUTHORISE; }

@Override
public GatewayCredentials getGatewayCredentials() {
return charge.getGatewayAccountCredentialsEntity().getCredentialsObject();
}
public GatewayCredentials gatewayCredentials() { return charge.getGatewayAccountCredentialsEntity().getCredentialsObject(); }

@Override
public AuthorisationMode getAuthorisationMode() {
return charge.getAuthorisationMode();
}
public AuthorisationMode authorisationMode() { return charge.getAuthorisationMode(); }

@Override
public boolean isForRecurringPayment() {
Expand All @@ -69,12 +51,8 @@ public boolean isForRecurringPayment() {
public static Auth3dsResponseGatewayRequest valueOf(ChargeEntity charge, Auth3dsResult auth3DsResult) {
return new Auth3dsResponseGatewayRequest(charge, auth3DsResult);
}

public String getAmount() {
return String.valueOf(CorporateCardSurchargeCalculator.getTotalAmountFor(charge));
}

public String getDescription() {
return charge.getDescription();
}

public String amount() { return String.valueOf(CorporateCardSurchargeCalculator.getTotalAmountFor(charge)); }

public String description() { return charge.getDescription(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,142 +2,19 @@

import uk.gov.pay.connector.agreement.model.AgreementEntity;
import uk.gov.pay.connector.charge.model.ServicePaymentReference;
import uk.gov.pay.connector.charge.model.domain.ChargeEntity;
import uk.gov.pay.connector.charge.util.CorporateCardSurchargeCalculator;
import uk.gov.pay.connector.gateway.GatewayOperation;
import uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity;
import uk.gov.pay.connector.gatewayaccount.model.GatewayCredentials;
import uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity;
import uk.gov.service.payments.commons.model.AuthorisationMode;
import uk.gov.service.payments.commons.model.SupportedLanguage;

import java.util.Optional;

public abstract class AuthorisationGatewayRequest implements GatewayRequest {
private final String gatewayTransactionId;
private final String email;
private final SupportedLanguage language;
private final boolean moto;
private final String amount;
private final String description;
private final ServicePaymentReference reference;
private final String govUkPayPaymentId;
private final GatewayCredentials credentials;
private final GatewayAccountEntity gatewayAccount;
private final AuthorisationMode authorisationMode;
private final boolean savePaymentInstrumentToAgreement;
private final Optional<AgreementEntity> agreement;

protected AuthorisationGatewayRequest(ChargeEntity charge) {
// NOTE: we don't store the ChargeEntity as we want to discourage code that deals with this request from
// updating the charge in the database.
this.gatewayTransactionId = charge.getGatewayTransactionId();
this.email = charge.getEmail();
this.language = charge.getLanguage();
this.moto = charge.isMoto();
this.amount = String.valueOf(CorporateCardSurchargeCalculator.getTotalAmountFor(charge));
this.description = charge.getDescription();
this.reference = charge.getReference();
this.govUkPayPaymentId = charge.getExternalId();
this.credentials = Optional.ofNullable(charge.getGatewayAccountCredentialsEntity())
.map(GatewayAccountCredentialsEntity::getCredentialsObject)
.orElse(null);
this.gatewayAccount = charge.getGatewayAccount();
this.authorisationMode = charge.getAuthorisationMode();
this.savePaymentInstrumentToAgreement = charge.isSavePaymentInstrumentToAgreement();
this.agreement = charge.getAgreement();
}

public AuthorisationGatewayRequest(String gatewayTransactionId,
String email,
SupportedLanguage language,
boolean moto,
String amount,
String description,
ServicePaymentReference reference,
String govUkPayPaymentId,
GatewayCredentials credentials,
GatewayAccountEntity gatewayAccount,
AuthorisationMode authorisationMode,
boolean savePaymentInstrumentToAgreement,
AgreementEntity agreement) {
this.gatewayTransactionId = gatewayTransactionId;
this.email = email;
this.language = language;
this.moto = moto;
this.amount = amount;
this.description = description;
this.reference = reference;
this.govUkPayPaymentId = govUkPayPaymentId;
this.credentials = credentials;
this.gatewayAccount = gatewayAccount;
this.authorisationMode = authorisationMode;
this.savePaymentInstrumentToAgreement = savePaymentInstrumentToAgreement;
this.agreement = Optional.ofNullable(agreement);
}

public String getEmail() {
return email;
}

public boolean isMoto() {
return moto;
}

public SupportedLanguage getLanguage() {
return language;
}

public Optional<String> getTransactionId() {
return Optional.ofNullable(gatewayTransactionId);
}

public String getAmount() {
return amount;
}

public String getDescription() {
return description;
}

public ServicePaymentReference getReference() {
return reference;
}

public String getGovUkPayPaymentId() {
return govUkPayPaymentId;
}

@Override
public GatewayCredentials getGatewayCredentials() {
return credentials;
}

@Override
public GatewayAccountEntity getGatewayAccount() {
return gatewayAccount;
}

@Override
public GatewayOperation getRequestType() {
return GatewayOperation.AUTHORISE;
}

@Override
public AuthorisationMode getAuthorisationMode() {
return authorisationMode;
}

public boolean isSavePaymentInstrumentToAgreement() {
return savePaymentInstrumentToAgreement;
}

public Optional<AgreementEntity> getAgreement() {
return agreement;
}

@Override
public boolean isForRecurringPayment() {
return agreement.isPresent();
}
public interface AuthorisationGatewayRequest extends GatewayRequest {
public String email();
public boolean isMoto();
public SupportedLanguage language();
public Optional<String> transactionId();
public String amount();
public String description();
public ServicePaymentReference reference();
public String govUkPayPaymentId();
public boolean isSavePaymentInstrumentToAgreement();
public Optional<AgreementEntity> agreement();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,40 @@
import uk.gov.pay.connector.gatewayaccount.model.GatewayCredentials;
import uk.gov.service.payments.commons.model.AuthorisationMode;

public class CancelGatewayRequest implements GatewayRequest {

private ChargeEntity charge;

private CancelGatewayRequest(ChargeEntity charge) {
this.charge = charge;
}
import java.util.Optional;

public record CancelGatewayRequest (
ChargeEntity charge
) implements GatewayRequest {
public static CancelGatewayRequest valueOf(ChargeEntity charge) {
return new CancelGatewayRequest(charge);
}

public String getTransactionId() {
public String transactionId() {
return charge.getGatewayTransactionId();
}

@Override
public GatewayAccountEntity getGatewayAccount() {
public GatewayAccountEntity gatewayAccount() {
return charge.getGatewayAccount();
}

@Override
public GatewayOperation getRequestType() {
public GatewayOperation requestType() {
return GatewayOperation.CANCEL;
}

@Override
public GatewayCredentials getGatewayCredentials() {
public GatewayCredentials gatewayCredentials() {
return charge.getGatewayAccountCredentialsEntity().getCredentialsObject();
}

@Override
public AuthorisationMode getAuthorisationMode() {
public AuthorisationMode authorisationMode() {
return charge.getAuthorisationMode();
}

public String getExternalChargeId() {
public String externalChargeId() {
return charge.getExternalId();
}

Expand Down
Loading
Loading