summaryrefslogtreecommitdiff
path: root/talerbank/app/views.py
diff options
context:
space:
mode:
authorMS <ms@taler.net>2020-10-09 17:35:07 +0200
committerMS <ms@taler.net>2020-10-09 17:35:07 +0200
commit026e6e3ec43497c8dbc37a92552f2bb740550678 (patch)
tree34fb5f0cbca772ece2179666ad27941c08158349 /talerbank/app/views.py
parente693fff5308207db82a6a12252cfdded16b154d4 (diff)
downloadbank-026e6e3ec43497c8dbc37a92552f2bb740550678.tar.gz
bank-026e6e3ec43497c8dbc37a92552f2bb740550678.tar.bz2
bank-026e6e3ec43497c8dbc37a92552f2bb740550678.zip
add transfer option with payto
Diffstat (limited to 'talerbank/app/views.py')
-rw-r--r--talerbank/app/views.py70
1 files changed, 33 insertions, 37 deletions
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 044f784..f6d81ce 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -293,22 +293,11 @@ class InputDatalist(forms.TextInput):
datalist += "</datalist>"
return html + datalist
-
-class WTForm(forms.Form):
- """
- Form for sending wire transfers. It usually appears in the
- user profile page.
- """
-
- amount = forms.FloatField(
- min_value=0.1, widget=forms.NumberInput(attrs={"class": "currency-input"})
- )
- receiver = forms.IntegerField(
- min_value=1, widget=InputDatalist(predefined_accounts_list, "receiver")
- )
+class PaytoTransferForm(forms.Form):
+ amount = forms.FloatField(min_value=0.1, widget=forms.NumberInput())
+ address = forms.CharField()
subject = forms.CharField()
-
##
# This method serves the profile page, which is the main
# page where the user interacts with the bank, and also the
@@ -325,28 +314,6 @@ class WTForm(forms.Form):
# @return Django-specific HTTP response object.
@login_required
def profile_page(request):
- if request.method == "POST":
- # WTForm ~ Wire Transfer Form.
- wtf = WTForm(request.POST)
- if wtf.is_valid():
- amount_parts = (
- settings.TALER_CURRENCY,
- wtf.cleaned_data.get("amount") + 0.0,
- )
- wire_transfer(
- Amount.parse("%s:%s" % amount_parts),
- BankAccount.objects.get(user=request.user),
- BankAccount.objects.get(account_no=wtf.cleaned_data.get("receiver")),
- wtf.cleaned_data.get("subject"),
- )
-
- set_session_hint(
- request, success=True, hint="Wire transfer successful!"
- )
-
- return redirect("profile")
-
- wtf = WTForm()
is_success, hint = get_session_hint(request)
context = dict(
name=request.user.username,
@@ -356,7 +323,6 @@ def profile_page(request):
precision=settings.TALER_DIGITS,
currency=request.user.bankaccount.balance.amount.currency,
account_no=request.user.bankaccount.account_no,
- wt_form=wtf,
history=extract_history(request.user.bankaccount, -1 * (UINT64_MAX / 2 / 2)),
)
if settings.TALER_SUGGESTED_EXCHANGE:
@@ -369,6 +335,36 @@ def profile_page(request):
response.status_code = 202
return response
+@login_required
+@require_POST
+def payto_transfer(request):
+ data = PaytoTransferForm(request.POST)
+ if not data.is_valid():
+ set_session_hint(
+ request,
+ success=False,
+ hint="Bad form submitted!"
+ )
+ return redirect("profile")
+
+ amount_parts = (
+ settings.TALER_CURRENCY,
+ data.cleaned_data.get("amount") + 0.0
+ )
+ parsed_address = PaytoParse(data.cleaned_data.get("address"))
+
+ wire_transfer(
+ Amount.parse("%s:%s" % amount_parts),
+ BankAccount.objects.get(user=request.user),
+ BankAccount.objects.get(account_no=parsed_address.account),
+ data.cleaned_data.get("subject")
+ )
+ set_session_hint(
+ request,
+ success=True,
+ hint="Wire transfer successful!"
+ )
+ return redirect("profile")
##
# Helper function that hashes its input. Usually