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 Refund classes to records #5396

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
41 changes: 12 additions & 29 deletions src/main/java/uk/gov/pay/connector/refund/model/RefundRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,29 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

public class RefundRequest {

public record RefundRequest (
@JsonProperty("amount")
@Schema(example = "3444", required = true, description = "Amount to refund in pence")
private long amount;
long amount,

@JsonProperty("refund_amount_available")
@Schema(example = "30000", required = true, description = "Total amount still available before issuing the refund")
private long amountAvailableForRefund;
long amountAvailableForRefund,

@JsonProperty("user_external_id")
@Schema(example = "3444", description = "The ID of the user who issued the refund")
private String userExternalId;
String userExternalId,

@JsonProperty("user_email")
@Schema(example = "[email protected]", description = "Email address of the user refunding payment")
private String userEmail;

public RefundRequest() {
}

String userEmail
) {
public RefundRequest(long amount, long amountAvailableForRefund, String userExternalId) {
this.amount = amount;
this.amountAvailableForRefund = amountAvailableForRefund;
this.userExternalId = userExternalId;
}

public long getAmount() {
return amount;
}

public long getAmountAvailableForRefund() {
return amountAvailableForRefund;
}

public String getUserExternalId() {
return userExternalId;
}

public String getUserEmail() {
return userEmail;
this(
amount,
amountAvailableForRefund,
userExternalId,
null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Response submitRefund(@Parameter(example = "1", description = "Gateway ac
@Parameter(example = "2c6vtn9pth38ppbmnt20d57t49", description = "Charge external ID")
@PathParam("chargeId") String chargeExternalId,
RefundRequest refundRequest, @Context UriInfo uriInfo) {
validateRefundRequest(refundRequest.getAmount());
validateRefundRequest(refundRequest.amount());

ChargeRefundResponse refundServiceResponse = chargeService.findCharge(chargeExternalId)
.map(charge -> refundService.doRefund(accountId, charge, refundRequest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public RefundEntity createRefund(Charge charge, GatewayAccountEntity gatewayAcco
charge.getGatewayTransactionId(),
gatewayAccountEntity.getId(),
availableAmount,
refundRequest.getAmount(),
refundRequest.amount(),
charge.getPaymentGatewayName(),
gatewayAccountEntity.getType(),
refundRequest.getUserExternalId());
refundRequest.userExternalId());

return refundEntity;
}
Expand Down Expand Up @@ -203,8 +203,8 @@ private RefundStatus determineRefundStatus(GatewayRefundResponse gatewayRefundRe
@Transactional
@SuppressWarnings("WeakerAccess")
public RefundEntity createRefundEntity(RefundRequest refundRequest, GatewayAccountEntity gatewayAccountEntity, Charge charge) {
RefundEntity refundEntity = new RefundEntity(refundRequest.getAmount(),
refundRequest.getUserExternalId(), refundRequest.getUserEmail(), charge.getExternalId());
RefundEntity refundEntity = new RefundEntity(refundRequest.amount(),
refundRequest.userExternalId(), refundRequest.userEmail(), charge.getExternalId());
transitionRefundState(refundEntity, gatewayAccountEntity, RefundStatus.CREATED, charge);
refundDao.persist(refundEntity);

Expand All @@ -229,15 +229,15 @@ public void transitionRefundState(RefundEntity refundEntity, GatewayAccountEntit
}

private void checkIfRefundRequestIsInConflictOrTerminate(RefundRequest refundRequest, Charge reloadedCharge, long totalAmountToBeRefunded) {
if (totalAmountToBeRefunded != refundRequest.getAmountAvailableForRefund()) {
if (totalAmountToBeRefunded != refundRequest.amountAvailableForRefund()) {
logger.info("Refund request has a mismatch on amount available for refund - charge_external_id={}, amount_actually_available_for_refund={}, refund_amount_available_in_request={}",
reloadedCharge.getExternalId(), totalAmountToBeRefunded, refundRequest.getAmountAvailableForRefund());
reloadedCharge.getExternalId(), totalAmountToBeRefunded, refundRequest.amountAvailableForRefund());
throw RefundException.refundAmountAvailableMismatchException("Refund Amount Available Mismatch");
}
}

private void checkIfRefundAmountWithinLimitOrTerminate(RefundRequest refundRequest, Charge reloadedCharge, ExternalChargeRefundAvailability refundAvailability, GatewayAccountEntity gatewayAccount, long totalAmountToBeRefunded) {
if (totalAmountToBeRefunded - refundRequest.getAmount() < 0) {
if (totalAmountToBeRefunded - refundRequest.amount() < 0) {

logger.info("Charge doesn't have sufficient amount for refund - charge_external_id={}, status={}, refund_status={}, account_id={}, operation_type=Refund, provider={}, provider_type={}, amount_available_refund={}, amount_requested_refund={}",
reloadedCharge.getExternalId(),
Expand All @@ -247,7 +247,7 @@ private void checkIfRefundAmountWithinLimitOrTerminate(RefundRequest refundReque
reloadedCharge.getPaymentGatewayName(),
gatewayAccount.getType(),
totalAmountToBeRefunded,
refundRequest.getAmount());
refundRequest.amount());

throw RefundException.notAvailableForRefundException("Not sufficient amount available for refund", NOT_SUFFICIENT_AMOUNT_AVAILABLE);
}
Expand Down
Loading