Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
#175: re-factor transactions update actions creation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-kovalenko-ct committed Jan 26, 2018
1 parent e227407 commit 2eed23f
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected ImmutableList<UpdateAction<Payment>> createPaymentUpdates(final Paymen
return actionsBuilder;
})
.orElseGet(() -> {
addPaymentUpdatesForNewAuthorizationTransaction(notification, actionsBuilder);
actionsBuilder.add(addAuthorizationTransaction(notification));
return actionsBuilder;
})
.build();
Expand All @@ -97,26 +97,22 @@ private UpdateAction<Payment> matchingChangeInteractionOrChargeTransaction(@Nonn
.orElseGet(() -> addChargePendingTransaction(notification));
}

private static void addPaymentUpdatesForNewAuthorizationTransaction(
final Notification notification,
final ImmutableList.Builder<UpdateAction<Payment>> listBuilder) {
final MonetaryAmount amount = MoneyImpl.of(notification.getPrice(), notification.getCurrency());

final TransactionState ctTransactionState = notification.getTransactionStatus().getCtTransactionState();

listBuilder.add(AddTransaction.of(TransactionDraftBuilder.of(TransactionType.AUTHORIZATION, amount)
.timestamp(toZonedDateTime(notification))
.state(ctTransactionState)
.interactionId(notification.getSequencenumber())
.build()));
private static AddTransaction addAuthorizationTransaction(final Notification notification) {
return addTransactionFromNotification(notification,
TransactionType.AUTHORIZATION, notification.getTransactionStatus().getCtTransactionState());
}

private static AddTransaction addChargePendingTransaction(final Notification notification) {
final MonetaryAmount amount = MoneyImpl.of(notification.getPrice(), notification.getCurrency());
return addTransactionFromNotification(notification, TransactionType.CHARGE, TransactionState.PENDING);
}

return AddTransaction.of(TransactionDraftBuilder.of(TransactionType.CHARGE, amount)
private static AddTransaction addTransactionFromNotification(final Notification notification,
final TransactionType transactionType,
final TransactionState transactionState) {
final MonetaryAmount amount = MoneyImpl.of(notification.getPrice(), notification.getCurrency());
return AddTransaction.of(TransactionDraftBuilder.of(transactionType, amount)
.timestamp(toZonedDateTime(notification))
.state(TransactionState.PENDING)
.state(transactionState)
.interactionId(notification.getSequencenumber())
.build());
}
Expand Down

0 comments on commit 2eed23f

Please sign in to comment.