summaryrefslogtreecommitdiff
path: root/talerbank/app
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-18 20:05:54 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-18 20:05:54 +0100
commite5bd57111f89d218af1874db990f776ceefc1a83 (patch)
treef670350d36f3c3195704b43e3fb2013c71ddfa0c /talerbank/app
parent55ae8249beaebee46a1be6f1a8453bd6681a6f46 (diff)
downloadbank-e5bd57111f89d218af1874db990f776ceefc1a83.tar.gz
bank-e5bd57111f89d218af1874db990f776ceefc1a83.tar.bz2
bank-e5bd57111f89d218af1874db990f776ceefc1a83.zip
add top-up command
Diffstat (limited to 'talerbank/app')
-rw-r--r--talerbank/app/management/commands/add_bank_account.py6
-rw-r--r--talerbank/app/management/commands/top_up.py76
2 files changed, 81 insertions, 1 deletions
diff --git a/talerbank/app/management/commands/add_bank_account.py b/talerbank/app/management/commands/add_bank_account.py
index 39b2519..5e16eb8 100644
--- a/talerbank/app/management/commands/add_bank_account.py
+++ b/talerbank/app/management/commands/add_bank_account.py
@@ -30,6 +30,7 @@ from ...models import BankAccount
from ...views import wire_transfer
from taler.util.amount import Amount
import getpass
+import uuid
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.INFO)
@@ -40,6 +41,7 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("accountname", nargs="1", type=str)
+ parser.add_argument('--public', action='store_true')
##
# Django-specific definition to invoke the account creator
@@ -54,7 +56,9 @@ class Command(BaseCommand):
print("Error: Passwords do not match")
return
BankAccount(
- user=User.objects.create_user(username=accountname, password=pw),
+ user=User.objects.create_user(
+ username=accountname,
+ password=str(uuid.uuid4()))
is_public=False,
).save()
print("Created new bank account.")
diff --git a/talerbank/app/management/commands/top_up.py b/talerbank/app/management/commands/top_up.py
new file mode 100644
index 0000000..36713f1
--- /dev/null
+++ b/talerbank/app/management/commands/top_up.py
@@ -0,0 +1,76 @@
+##
+# This file is part of TALER
+# (C) 2014, 2015, 2106 Taler Systems SA
+#
+# 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
+# @author Florian Dold
+# @brief Create the basic accounts to make the demo bank work.
+
+import sys
+import logging
+from django.contrib.auth.models import User
+from django.db.utils import ProgrammingError, OperationalError
+from django.core.management.base import BaseCommand
+from django.conf import settings
+from ...models import BankAccount
+from ...views import wire_transfer
+from taler.util.amount import Amount
+import getpass
+import uuid
+
+LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.INFO)
+
+
+class Command(BaseCommand):
+ help = "Add bank accounts."
+
+ def add_arguments(self, parser):
+ parser.add_argument(
+ "user",
+ type=str,
+ metavar="USERNAME",
+ help="User that is getting credited with the top-up"
+ )
+ parser.add_argument(
+ "amount", type=str, metavar="AMOUNT",
+ help="Wire transfer's amount, given in the " \
+ "CURRENCY:X.Y form.")
+
+ ##
+ # Django-specific definition to invoke the account creator
+ # @a make_account; it iterates over the list of basic accounts
+ # (defined in the settings) and invoke the account creator
+ # for each one of them.
+ def handle(self, *args, **options):
+ user = User.objects.get(username=options["user"])
+ try:
+ debit_account = BankAccount.objects.get(
+ account_no=0,
+ )
+ except BankAccount.DoesNotExist:
+ LOGGER.error("Debit account (bank's own 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)