public override string Transfer(Transfer transfer) { Balance balance = accounts .LookupBalance(transfer.Account) ?? throw new TransferException( StatusCode.FailureGeneric, "Account not found: " + transfer.Account ); if (!balance.Currency.Equals(transfer.RequestedAmountCurrency)) { throw new TransferException( StatusCode.FailureInvalidCurrency, "FX is not supported"); } if (balance.Available.CompareTo(transfer.TransactionAmount) < 0) { throw new TransferException( StatusCode.FailureInsufficientFunds, "Balance exceeded"); } AccountTransaction transaction = AccountTransaction.NewBuilder(TransactionType.Debit) .Id(string.Join(":", transfer.TokenTransferId, TransactionType.Debit.ToString())) .ReferenceId(transfer.TokenTransferId) .From(transfer.Account) .To(transfer.Destinations[0].Account) .Amount( double.Parse(transfer.TransactionAmount.ToString()), transfer.TransactionAmountCurrency) .TransferAmount( double.Parse(transfer.TransactionAmount.ToString()), transfer.TransactionAmountCurrency) .Description(transfer.Description) .Build(); accounts.CreateDebitTransaction(transaction); // A bank needs to initiate a transfer here. Leaving this part out // since it changes from scheme to scheme. return(transaction.Id); }
private IList <AccountConfig> AccountsFor(string category) { return(config.GetSection("accounts:" + category) .GetChildren() .ToList() .Select(x => { Address address = new Address(); var addressConfig = x.GetSection("address"); if (addressConfig.Value != null) { address = new Address { HouseNumber = addressConfig["house"], Street = addressConfig["street"], City = addressConfig["city"], PostCode = addressConfig["post_code"], Country = addressConfig["country"] }; } AccountTransaction transaction = null; if (category.Equals("customers")) { var transactionConfig = x.GetSection("transaction"); TransactionType type = TransactionType.InvalidType; if (transactionConfig["transaction-type"] == "DEBIT") { type = TransactionType.Debit; } else if (transactionConfig["transaction-type"] == "CREDIT") { type = TransactionType.Credit; } transaction = AccountTransaction.NewBuilder(type) .Amount(Double.Parse(transactionConfig["amount"]), transactionConfig["currency"]) .TransferAmount(Double.Parse(transactionConfig["amount"]), transactionConfig["currency"]) .Description(transactionConfig["description"]) .From(new BankAccount { Swift = new BankAccount.Types.Swift { Bic = x["bic"], Account = x["number"] } }) .To(new BankAccount { Swift = new BankAccount.Types.Swift { Bic = transactionConfig["to:bic"], Account = transactionConfig["to:number"] } }) .Id(transactionConfig["id"]) .ReferenceId(transactionConfig["id"]) .Build(); } double balance = x["balance"] != null ? double.Parse(x["balance"]) : 0; return AccountConfig.Create( x["name"], address, x["bic"], x["number"], x["currency"], balance, transaction); }).ToList()); }