-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
520 additions
and
264 deletions.
There are no files selected for viewing
138 changes: 101 additions & 37 deletions
138
src/main/java/cl/transbank/model/MallTransactionCreateDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,117 @@ | ||
package cl.transbank.model; | ||
|
||
import lombok.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.*; | ||
|
||
/** | ||
* This class represents the details of the FullTransaction installment response. | ||
*/ | ||
public class MallTransactionCreateDetails { | ||
private List<MallTransactionCreateDetails.Detail> detailList = new ArrayList<>(); | ||
|
||
private MallTransactionCreateDetails() {} | ||
private List<MallTransactionCreateDetails.Detail> detailList = new ArrayList<>(); | ||
|
||
public static MallTransactionCreateDetails build() { | ||
return new MallTransactionCreateDetails(); | ||
} | ||
/** | ||
* This class represents the details of the FullTransaction installment response. | ||
*/ | ||
private MallTransactionCreateDetails() {} | ||
|
||
public static MallTransactionCreateDetails build(double amount, String commerceCode, String buyOrder) { | ||
return MallTransactionCreateDetails.build().add(amount, commerceCode, buyOrder); | ||
} | ||
/** | ||
* Builds a new MallTransactionCreateDetails instance. | ||
* @return A new MallTransactionCreateDetails instance. | ||
*/ | ||
public static MallTransactionCreateDetails build() { | ||
return new MallTransactionCreateDetails(); | ||
} | ||
|
||
public MallTransactionCreateDetails add(double amount, String commerceCode, String buyOrder) { | ||
detailList.add(new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder)); | ||
return this; | ||
} | ||
/** | ||
* Builds a new MallTransactionCreateDetails instance and adds the provided detail. | ||
* @param amount The amount of the transaction. | ||
* @param commerceCode The commerce code. | ||
* @param buyOrder The buy order. | ||
* @return A new MallTransactionCreateDetails instance with the provided detail added. | ||
*/ | ||
public static MallTransactionCreateDetails build( | ||
double amount, | ||
String commerceCode, | ||
String buyOrder | ||
) { | ||
return MallTransactionCreateDetails | ||
.build() | ||
.add(amount, commerceCode, buyOrder); | ||
} | ||
|
||
public boolean remove(double amount, String commerceCode, String buyOrder) { | ||
return getDetails().remove(new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder)); | ||
} | ||
/** | ||
* Adds a new detail to this MallTransactionCreateDetails. | ||
* @param amount The amount of the transaction. | ||
* @param commerceCode The commerce code. | ||
* @param buyOrder The buy order. | ||
* @return This MallTransactionCreateDetails instance. | ||
*/ | ||
public MallTransactionCreateDetails add( | ||
double amount, | ||
String commerceCode, | ||
String buyOrder | ||
) { | ||
detailList.add( | ||
new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder) | ||
); | ||
return this; | ||
} | ||
|
||
public List<MallTransactionCreateDetails.Detail> getDetails() { | ||
return Collections.unmodifiableList(detailList); | ||
} | ||
/** | ||
* Removes a detail from this MallTransactionCreateDetails. | ||
* @param amount The amount of the transaction. | ||
* @param commerceCode The commerce code. | ||
* @param buyOrder The buy order. | ||
* @return True if the detail was removed, false otherwise. | ||
*/ | ||
public boolean remove(double amount, String commerceCode, String buyOrder) { | ||
return getDetails() | ||
.remove( | ||
new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder) | ||
); | ||
} | ||
|
||
/** | ||
* Gets the details of this MallTransactionCreateDetails. | ||
* @return The details of this MallTransactionCreateDetails. | ||
*/ | ||
public List<MallTransactionCreateDetails.Detail> getDetails() { | ||
return Collections.unmodifiableList(detailList); | ||
} | ||
|
||
/** | ||
* Gets the details of this MallTransactionCreateDetails. | ||
* @return The details of this MallTransactionCreateDetails. | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
@ToString | ||
public class Detail { | ||
|
||
@NoArgsConstructor @AllArgsConstructor | ||
@Getter @Setter @ToString | ||
public class Detail { | ||
private double amount; | ||
private String commerceCode; | ||
private String buyOrder; | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof MallTransactionCreateDetails.Detail)) | ||
return false; | ||
|
||
MallTransactionCreateDetails.Detail another = (MallTransactionCreateDetails.Detail) obj; | ||
return getAmount() == another.getAmount() && getCommerceCode().equals(another.getBuyOrder()) && | ||
getBuyOrder().equals(another.getBuyOrder()); | ||
} | ||
private double amount; | ||
private String commerceCode; | ||
private String buyOrder; | ||
|
||
/** | ||
* Checks if this Detail is equal to another object. | ||
* @param obj The object to compare with. | ||
* @return True if the objects are equal, false otherwise. | ||
*/ | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof MallTransactionCreateDetails.Detail)) return false; | ||
|
||
MallTransactionCreateDetails.Detail another = (MallTransactionCreateDetails.Detail) obj; | ||
return ( | ||
getAmount() == another.getAmount() && | ||
getCommerceCode().equals(another.getBuyOrder()) && | ||
getBuyOrder().equals(another.getBuyOrder()) | ||
); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.