Skip to content

Commit

Permalink
Format amount, remove pspReference
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Dec 5, 2023
1 parent bf0df7a commit c37fcc1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
14 changes: 0 additions & 14 deletions src/main/java/com/adyen/model/TransactionItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class TransactionItem {
private String type;
private String created;
private String amount;
private String pspReference;

public String getId() {
return id;
Expand Down Expand Up @@ -40,14 +39,6 @@ public void setAmount(String amount) {
this.amount = amount;
}

public String getPspReference() {
return pspReference;
}

public void setPspReference(String pspReference) {
this.pspReference = pspReference;
}

public String getType() {
return type;
}
Expand Down Expand Up @@ -76,11 +67,6 @@ public TransactionItem amount(String amount) {
return this;
}

public TransactionItem pspReference(String pspReference) {
this.pspReference = pspReference;
return this;
}

public TransactionItem type(String type) {
this.type = type;
return this;
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/com/adyen/util/TransactionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public TransactionItem getTransactionItem(Transaction transaction) {
return new TransactionItem()
.id(transaction.getId())
.status(transaction.getStatus().getValue())
.type(transaction.getAmount().getValue() > 0 ? "Incoming" : "Outgoing")
.type(getType(transaction.getAmount()))
.created(formatDate(transaction.getCreationDate()))
.amount(formatAmount(transaction.getAmount()))
.pspReference(transaction.getEventId());
.amount(formatAmount(transaction.getAmount()));
}

private String formatAmount(Amount amount) {
String ret = "";

if(amount != null) {
NumberFormat numberFormat = NumberFormat.getNumberInstance();
String formattedAmount = numberFormat.format(amount.getValue());
// display absolute amount and format
String formattedAmount = numberFormat.format(Math.abs(amount.getValue()));
ret = amount.getCurrency() + " " + formattedAmount;
}
return ret;
Expand All @@ -63,4 +63,25 @@ private String formatDate(OffsetDateTime offsetDateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return offsetDateTime.format(formatter);
}

/**
* Determines type of the transaction
* Incoming: positive amount, funds added
* Outgoing: negative amount, funds deducted
* @param amount
* @return
*/
private String getType(Amount amount) {
String ret = "";

if(amount != null) {
if(amount.getValue() > 0) {
ret = "Incoming";
} if(amount.getValue() < 0) {
ret = "Outgoing";
}
}

return ret;
}
}

0 comments on commit c37fcc1

Please sign in to comment.