40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package me.teridax.jcash.gui.transfer;
|
|
|
|
import me.teridax.jcash.banking.BankingManagementSystem;
|
|
import me.teridax.jcash.decode.StringDecoder;
|
|
|
|
public class TransferData {
|
|
|
|
private final BankingManagementSystem bms;
|
|
|
|
public TransferData(BankingManagementSystem bms) {
|
|
this.bms = bms;
|
|
}
|
|
|
|
/**
|
|
* Transfers a certain amount of money to the specified account of the specified bank
|
|
* @param amount the amount to transfer
|
|
* @param blz the bank that manages the account
|
|
* @param ibanString the internal bank account number to transfer money to
|
|
* @throws IllegalArgumentException if the bank or the account do not exist
|
|
*/
|
|
public void transferValue(double amount, String blz, String ibanString) throws IllegalArgumentException {
|
|
var bank = bms.getBank(blz);
|
|
if (bank.isEmpty())
|
|
throw new IllegalArgumentException("Bank not found: " + blz);
|
|
|
|
var iban = 0;
|
|
try {
|
|
iban = StringDecoder.decodeUniqueIdentificationNumber(ibanString);
|
|
} catch (Exception ex) {
|
|
throw new IllegalArgumentException("IBAN has invalid format: " + ibanString);
|
|
}
|
|
|
|
var account = bank.get().getAccount(iban);
|
|
if (account.isEmpty())
|
|
throw new IllegalArgumentException("Account not found: " + iban);
|
|
|
|
account.get().getPrimaryAccount().deposit(amount);
|
|
}
|
|
}
|