Skip to content

Commit

Permalink
Enable submission of repayment requests
Browse files Browse the repository at this point in the history
  • Loading branch information
FestplattenSchnitzel committed Oct 20, 2023
1 parent 545e577 commit a036333
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pycroft/lib/finance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
process_transactions,
ImportedTransactions,
)
from .repayment.fields import (
IBANField,
)


def user_has_paid(user: User) -> bool:
Expand Down
14 changes: 14 additions & 0 deletions pycroft/lib/finance/repayment/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from marshmallow import fields, ValidationError
from schwifty import IBAN


class IBANField(fields.Field):
"""Field that serializes to a IBAN and deserializes
to a string.
"""

def _deserialize(self, value, attr, data, **kwargs) -> IBAN:

Check failure on line 10 in pycroft/lib/finance/repayment/fields.py

View workflow job for this annotation

GitHub Actions / python-lint

Error

Function is missing a type annotation for one or more arguments [no-untyped-def]
try:
return IBAN(value)
except ValueError as error:
raise ValidationError("Pin codes must contain only digits.") from error
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ sentry-sdk[Flask]~=1.29.2
-e ./deps/wtforms-widgets/
python-dotenv~=0.21.0
pydantic~=2.0.0
schwifty~=2023.9.0
24 changes: 23 additions & 1 deletion web/api/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flask import jsonify, current_app, Response
from flask.typing import ResponseReturnValue
from flask_restful import Api, Resource as FlaskRestfulResource, abort
from schwifty import IBAN
from sqlalchemy.exc import IntegrityError
from sqlalchemy import select
from sqlalchemy.orm import joinedload, selectinload, undefer, with_polymorphic
Expand All @@ -16,7 +17,7 @@

from pycroft.helpers import utc
from pycroft.helpers.i18n import Message
from pycroft.lib.finance import estimate_balance, get_last_import_date
from pycroft.lib.finance import estimate_balance, get_last_import_date, IBANField
from pycroft.lib.host import change_mac, host_create, interface_create, host_edit
from pycroft.lib.net import SubnetFullException
from pycroft.lib.swdd import get_swdd_person_id, get_relevant_tenancies, \
Expand Down Expand Up @@ -796,3 +797,24 @@ def patch(self, token: str, password: str) -> ResponseReturnValue:


api.add_resource(ResetPasswordResource, '/user/reset-password')


class RequestRepaymentResource(Resource):
def get(self, user_id: int):

Check failure on line 803 in web/api/v0/__init__.py

View workflow job for this annotation

GitHub Actions / python-lint

Error

Function is missing a return type annotation [no-untyped-def]
current_app.logger.warning("RECEIVED GET FOR REQUEST_REPAYMENT.")
return jsonify(False)

@use_kwargs(
{
"beneficiary": fields.Str(required=True),
"iban": IBANField(required=True),
"amount": fields.Decimal(required=True),
},
location="form",
)
def post(self, user_id: int, beneficiary: str, iban: str, amount: Decimal):

Check failure on line 815 in web/api/v0/__init__.py

View workflow job for this annotation

GitHub Actions / python-lint

Error

Function is missing a return type annotation [no-untyped-def]
current_app.logger.warning({beneficiary, iban, amount})
return jsonify({"success": True})


api.add_resource(RequestRepaymentResource, "/user/<int:user_id>/request-repayment")

0 comments on commit a036333

Please sign in to comment.