Exemple #1
0
        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);
        }
Exemple #2
0
 public Balance GetBalance(BankAccount account)
 {
     return(accounts.LookupBalance(account)
            ?? throw new BankException(StatusCode.FailureAccountNotFound, "Account not found"));
 }