Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Last active March 22, 2020 06:53
Show Gist options
  • Save ashkrit/8d38cb9cced05f9cc17e9330d913f796 to your computer and use it in GitHub Desktop.
Save ashkrit/8d38cb9cced05f9cc17e9330d913f796 to your computer and use it in GitHub Desktop.
public class FXService {
private final CurrencyConverter currencyConverter;
private final BankService bankService;
private final double commissionPer;
public String transfer(Money money, BankAccount destinationAccount, Currency target) {
String sourceCurrency = money.currency().name();
String targetCurrency = target.name();
double commissionAmount = calculateCommission(money.amount());
double fxRate = currencyConverter.convert(1, sourceCurrency, targetCurrency); // First interaction
double transferAmount = calculateTransferAmount(money, commissionAmount);
double totalAmount = applyFxRate(transferAmount, fxRate);
String transactionId = bankService.deposit(totalAmount, destinationAccount); // Second interaction
return transactionId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment