Last active
March 22, 2020 06:53
-
-
Save ashkrit/8d38cb9cced05f9cc17e9330d913f796 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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