Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added error when invalid topup amount is entered #70

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion admin_board_view/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@


class TopUpForm(forms.Form):
amount = forms.DecimalField(min_value=0, decimal_places=2, required=True)
amount = forms.DecimalField(
min_value=0, decimal_places=2, required=True, max_value=1000
)
14 changes: 13 additions & 1 deletion admin_board_view/templates/user_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{% load static %}
{% block body %}
<main class="container mt-3">

<!-- Transaction status -->
{% if transaction %}
{% if transaction.status == PaymentStatus.PAID %}
<div class="alert alert-success">
Expand All @@ -17,6 +19,16 @@
</div>
{% endif %}
{% endif %}

<!-- Validation errors -->
{% if error %}
<div class="alert alert-danger">
{% if error == "1" %}
You entered an invalid number to the top up form, try entering an amount greater than €0 and less than €1000 with at most two decimals.
{% endif %}
</div>
{% endif %}

<h1>Welcome {{ user_info.name }}</h1>
<h5 class="mb-2">
Current balance: <b>{{ user_info.euro_balance }}</b>
Expand Down Expand Up @@ -85,7 +97,7 @@ <h5>Top up balance</h5>
<label for="amount" class="sr-only">Amount: </label>
</div>
<div class="form-group col">
<input placeholder="Amount" class="form-control" type="number" min="0" step="0.01" name="amount" />
<input placeholder="Amount" class="form-control" type="number" min="0" step="0.01" name="amount" required />
</div>
<div class="form-group col">
<button type="submit" class="btn btn-primary">Top up</button>
Expand Down
1 change: 1 addition & 0 deletions admin_board_view/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def index(request):
"transaction": transaction,
"PaymentStatus": PaymentStatus,
"TRANSACTION_FEE": settings.TRANSACTION_FEE,
"error": request.GET.get("error"),
},
)

Expand Down
2 changes: 1 addition & 1 deletion mongoose_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def topup(request):
)
return redirect(payment.checkout_url)
else:
return HttpResponse(status=400)
return redirect("/?error=1")


@csrf_exempt
Expand Down
Loading