Skip to content

Commit

Permalink
refactor: use build pattern to avoid methods with more than 4 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tribiec committed Mar 21, 2024
1 parent 5e275f5 commit 53bed13
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 27 deletions.
15 changes: 13 additions & 2 deletions src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ public PatpassByWebpayTransactionCreateResponse create(
String expirationDate, String commerceMail, boolean ufFlag) throws IOException, TransactionCreateException {
String endpoint = String.format("%s/transactions", ApiConstants.WEBPAY_ENDPOINT);
final TransactionCreateRequest request = new TransactionCreateRequest(buyOrder, sessionId, amount, returnUrl);
request.setDetails(serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2,
cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag);
TransactionCreateRequest.Detail transactionDetails = request.new Detail();
transactionDetails.setServiceId(serviceId);
transactionDetails.setCardHolderId(cardHolderId);
transactionDetails.setCardHolderName(cardHolderName);
transactionDetails.setCardHolderLastName1(cardHolderLastName1);
transactionDetails.setCardHolderLastName2(cardHolderLastName2);
transactionDetails.setCardHolderMail(cardHolderMail);
transactionDetails.setCellphoneNumber(cellphoneNumber);
transactionDetails.setExpirationDate(expirationDate);
transactionDetails.setCommerceMail(commerceMail);
transactionDetails.setUfFlag(ufFlag);

request.setDetails(transactionDetails);
try {
return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, PatpassByWebpayTransactionCreateResponse.class);
} catch (TransbankException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,8 @@ public class TransactionCreateRequest extends WebpayApiRequest {
* @param ufFlag The UF flag.
*/

public void setDetails(
String serviceId,
String cardHolderId,
String cardHolderName,
String cardHolderLastName1,
String cardHolderLastName2,
String cardHolderMail,
String cellphoneNumber,
String expirationDate,
String commerceMail,
boolean ufFlag
) {
wpmDetail =
new Detail(
serviceId,
cardHolderId,
cardHolderName,
cardHolderLastName1,
cardHolderLastName2,
cardHolderMail,
cellphoneNumber,
expirationDate,
commerceMail,
ufFlag
);
public void setDetails(Detail detail) {
wpmDetail = detail;
}

/**
Expand All @@ -88,5 +65,85 @@ public class Detail {
private String expirationDate;
private String commerceMail;
private boolean ufFlag;

public String getServiceId() {
return serviceId;
}

public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}

public String getCardHolderId() {
return cardHolderId;
}

public void setCardHolderId(String cardHolderId) {
this.cardHolderId = cardHolderId;
}

public String getCardHolderName() {
return cardHolderName;
}

public void setCardHolderName(String cardHolderName) {
this.cardHolderName = cardHolderName;
}

public String getCardHolderLastName1() {
return cardHolderLastName1;
}

public void setCardHolderLastName1(String cardHolderLastName1) {
this.cardHolderLastName1 = cardHolderLastName1;
}

public String getCardHolderLastName2() {
return cardHolderLastName2;
}

public void setCardHolderLastName2(String cardHolderLastName2) {
this.cardHolderLastName2 = cardHolderLastName2;
}

public String getCardHolderMail() {
return cardHolderMail;
}

public void setCardHolderMail(String cardHolderMail) {
this.cardHolderMail = cardHolderMail;
}

public String getCellphoneNumber() {
return cellphoneNumber;
}

public void setCellphoneNumber(String cellphoneNumber) {
this.cellphoneNumber = cellphoneNumber;
}

public String getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}

public String getCommerceMail() {
return commerceMail;
}

public void setCommerceMail(String commerceMail) {
this.commerceMail = commerceMail;
}

public boolean isUfFlag() {
return ufFlag;
}

public void setUfFlag(boolean ufFlag) {
this.ufFlag = ufFlag;
}
}
}

0 comments on commit 53bed13

Please sign in to comment.