From 8035958596113d5e58a98c8487f0a4c6fb1e7467 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 16 Jan 2018 14:21:38 +0100 Subject: Adding tool to perform wire transfers manually - the Web server isn't required to run in order to have wire transfers effective. --- talerbank/app/management/commands/wire_transfer.py | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 talerbank/app/management/commands/wire_transfer.py (limited to 'talerbank/app/management') 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 +# +# +# @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) -- cgit v1.2.3