Skip to content

Commit

Permalink
payment: make amounts use processed values
Browse files Browse the repository at this point in the history
This fixes #482.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Feb 4, 2016
1 parent 6b25dcd commit d491768
Showing 1 changed file with 17 additions and 12 deletions.
Expand Up @@ -72,21 +72,26 @@ public boolean apply(final PaymentTransaction input) {

private static BigDecimal getAmountForType(final Iterable<PaymentTransaction> transactions, final TransactionType transactiontype) {
BigDecimal result = BigDecimal.ZERO;
final Iterable<PaymentTransaction> filtered = Iterables.filter(transactions, new Predicate<PaymentTransaction>() {
@Override
public boolean apply(final PaymentTransaction input) {
return input.getTransactionType() == transactiontype && TransactionStatus.SUCCESS.equals(input.getTransactionStatus());
BigDecimal processedResult = BigDecimal.ZERO;
boolean shouldUseProcessedAmount = true;

for (final PaymentTransaction transaction : transactions) {
if (transaction.getTransactionType() != transactiontype || !TransactionStatus.SUCCESS.equals(transaction.getTransactionStatus())) {
continue;
}
});
if (TransactionType.AUTHORIZE.equals(transactiontype) && filtered.iterator().hasNext()) {
// HACK - For multi-step AUTH, don't sum the individual transactions
result = filtered.iterator().next().getAmount();
} else {
for (final PaymentTransaction dpt : filtered) {
result = result.add(dpt.getAmount());

result = result.add(transaction.getAmount());

shouldUseProcessedAmount = shouldUseProcessedAmount && transaction.getCurrency().equals(transaction.getProcessedCurrency()) && transaction.getProcessedAmount() != null;
processedResult = shouldUseProcessedAmount ? processedResult.add(transaction.getProcessedAmount()) : BigDecimal.ZERO;

// For multi-step AUTH, don't sum the individual transactions
if (TransactionType.AUTHORIZE.equals(transactiontype)) {
break;
}
}
return result;

return shouldUseProcessedAmount ? processedResult : result;
}

@Override
Expand Down

1 comment on commit d491768

@sbrossie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.