diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-01-16 14:21:38 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-01-16 14:21:38 +0100 |
commit | 8035958596113d5e58a98c8487f0a4c6fb1e7467 (patch) | |
tree | d7380814ef102419969d19044744fdfdb6c5e6b8 /talerbank/app/management | |
parent | 1e1e187456d16ed03066724035caa7c1cba6b094 (diff) | |
download | bank-8035958596113d5e58a98c8487f0a4c6fb1e7467.tar.gz bank-8035958596113d5e58a98c8487f0a4c6fb1e7467.tar.bz2 bank-8035958596113d5e58a98c8487f0a4c6fb1e7467.zip |
Adding tool to perform wire transfers manually - the Web server
isn't required to run in order to have wire transfers effective.
Diffstat (limited to 'talerbank/app/management')
-rw-r--r-- | talerbank/app/management/commands/wire_transfer.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/talerbank/app/management/commands/wire_transfer.py b/talerbank/app/management/commands/wire_transfer.py new file mode 100644 index 0000000..82f18d0 --- /dev/null +++ b/talerbank/app/management/commands/wire_transfer.py @@ -0,0 +1,80 @@ +# This file is part of TALER +# (C) 2014, 2015, 2106 INRIA +# +# TALER is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; either version 3, or (at your +# option) any later version. +# +# TALER is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with TALER; see the file COPYING. If not, see +# <http://www.gnu.org/licenses/> +# +# @author Marcello Stanisci + +import sys +import logging +import json +from django.core.management.base import BaseCommand +from django.contrib.auth import authenticate +from ...amount import Amount, BadFormatAmount +from ...views import wire_transfer +from ...models import BankAccount, BankTransaction + +LOGGER = logging.getLogger(__name__) + +class Command(BaseCommand): + help = "Wire transfer money and return the transaction id." + + def add_arguments(self, parser): + parser.add_argument( + "user", type=str, metavar="USERNAME", + help="Which user is performing the wire transfer") + parser.add_argument( + "password", type=str, metavar="PASSWORD", + help="Performing user's password.") + parser.add_argument( + "credit-account", type=int, metavar="CREDIT-ACCOUNT", + help="Which account number will *receive* money.") + parser.add_argument( + "subject", type=str, metavar="SUBJECT", + help="SUBJECT will be the wire transfer subject.") + parser.add_argument( + "amount", type=str, metavar="AMOUNT", + help="Wire transfer's amount, given in the " \ + "CURRENCY:X.Y form.") + + + def handle(self, *args, **options): + + user = authenticate( + username=options["user"], password=options["password"]) + if not user: + LOGGER.error("Wrong user/password.") + sys.exit(1) + try: + amount = Amount.parse(options["amount"]) + except BadFormatAmount: + LOGGER.error("Amount's format is wrong: respect C:X.Y.") + sys.exit(1) + + try: + credit_account = BankAccount.objects.get( + account_no=options["credit-account"]) + except BankAccount.DoesNotExist: + LOGGER.error("Credit account does not exist.") + sys.exit(1) + + try: + transaction = wire_transfer( + amount, user.bankaccount, + credit_account, options["subject"]) + print("Transaction id: " + str(transaction.id)) + except Exception as exc: + LOGGER.error(exc) + sys.exit(1) |