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 Authorisation classes to records #5395

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public static AuthCardDetails anAuthCardDetails() {

public static AuthCardDetails of(AuthoriseRequest authoriseRequest, ChargeEntity chargeEntity, CardInformation cardInformation) {
AuthCardDetails authCardDetails = new AuthCardDetails();
authCardDetails.setCardNo(authoriseRequest.getCardNumber());
authCardDetails.setCardHolder(authoriseRequest.getCardholderName());
authCardDetails.setEndDate(CardExpiryDate.valueOf(authoriseRequest.getExpiryDate()));
authCardDetails.setCvc(authoriseRequest.getCvc());
authCardDetails.setCardNo(authoriseRequest.cardNumber());
authCardDetails.setCardHolder(authoriseRequest.cardholderName());
authCardDetails.setEndDate(CardExpiryDate.valueOf(authoriseRequest.expiryDate()));
authCardDetails.setCvc(authoriseRequest.cvc());

authCardDetails.setCardBrand(cardInformation.getBrand());
authCardDetails.setCorporateCard(cardInformation.isCorporate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,45 @@

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class AuthoriseRequest {

public record AuthoriseRequest (
@NotBlank(message = "Missing mandatory attribute: one_time_token")
@Schema(example = "123abc123", required = true,
description = "the one time token provided in the `auth_url_post` link of the create payment API response")
private String oneTimeToken;
String oneTimeToken,

@NotBlank(message = "Missing mandatory attribute: card_number")
@Length(min = 12, max = 19, message = "Invalid attribute value: card_number. Must be between {min} and {max} characters long")
@Schema(example = "4242424242424242", minLength = 12, maxLength = 19, required = true)
private String cardNumber;
String cardNumber,

@NotBlank(message = "Missing mandatory attribute: cvc")
@Length(min = 3, max = 4, message = "Invalid attribute value: cvc. Must be between {min} and {max} characters long")
@Schema(example = "123", minLength = 3, maxLength = 4, required = true)
private String cvc;
String cvc,

@NotBlank(message = "Missing mandatory attribute: expiry_date")
@Schema(example = "01/99", minLength = 5, maxLength = 5, description = "5 character string in MM/YY format", required = true)
private String expiryDate;
String expiryDate,

@NotBlank(message = "Missing mandatory attribute: cardholder_name")
@Length(min = 1, max = 255, message = "Invalid attribute value: cardholder_name. Must be less than or equal to {max} characters length")
@Schema(example = "Joe B", maxLength = 255, description = "Cardholder name", required = true)
private String cardholderName;

public AuthoriseRequest() {
// for Jackson
}

public AuthoriseRequest(String oneTimeToken, String cardNumber, String cvc, String expiryDate, String cardholderName) {
this.oneTimeToken = oneTimeToken;
this.cardNumber = cardNumber;
this.cvc = cvc;
this.expiryDate = expiryDate;
this.cardholderName = cardholderName;
}

private boolean isMonthAndYearInTheFuture(String expiryDate) {
String cardholderName
){

// public AuthoriseRequest() {
// // for Jackson
// }

// public AuthoriseRequest(String oneTimeToken, String cardNumber, String cvc, String expiryDate, String cardholderName) {
// this.oneTimeToken = oneTimeToken;
// this.cardNumber = cardNumber;
// this.cvc = cvc;
// this.expiryDate = expiryDate;
// this.cardholderName = cardholderName;
// }

boolean isMonthAndYearInTheFuture(String expiryDate) {
final int MAX_TIMEZONE_OFFSET_BEHIND_UTC = 12;

// Validation is not bound to UTC and allows cards valid far behind UTC.
Expand Down Expand Up @@ -88,25 +88,25 @@ public void validate() {
}
}

public String getOneTimeToken() {
return oneTimeToken;
}
// public String getOneTimeToken() {
// return oneTimeToken;
// }

public String getCardNumber() {
return cardNumber;
}
// public String getCardNumber() {
// return cardNumber;
// }

public String getCvc() {
return cvc;
}
// public String getCvc() {
// return cvc;
// }

public String getExpiryDate() {
return expiryDate;
}
// public String getExpiryDate() {
// return expiryDate;
// }

public String getCardholderName() {
return cardholderName;
}
// public String getCardholderName() {
// return cardholderName;
// }

@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ public Response cancelChargeByServiceIdAndAccountType(@Parameter(example = "46eb
)
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());
MDC.put(SECURE_TOKEN, authoriseRequest.oneTimeToken());
authoriseRequest.validate();

TokenEntity tokenEntity = tokenService.validateAndMarkTokenAsUsedForMotoApi(authoriseRequest.getOneTimeToken());
TokenEntity tokenEntity = tokenService.validateAndMarkTokenAsUsedForMotoApi(authoriseRequest.oneTimeToken());
MDCUtils.addChargeAndGatewayAccountDetailsToMDC(tokenEntity.getChargeEntity());
CardInformation cardInformation = motoApiCardNumberValidationService.validateCardNumber(tokenEntity.getChargeEntity(), authoriseRequest.getCardNumber());
CardInformation cardInformation = motoApiCardNumberValidationService.validateCardNumber(tokenEntity.getChargeEntity(), authoriseRequest.cardNumber());

AuthorisationResponse response = cardAuthoriseService.doAuthoriseMotoApi(tokenEntity.getChargeEntity(), cardInformation, authoriseRequest);
return handleAuthResponseForMotoApi(response);
Expand Down
Loading