"""Payment handlers.""" from flask.typing import ResponseReturnValue from flask_pydantic import validate from collaborator.api import app from collaborator.logic import transferwise_transaction from collaborator.schemas import BaseSchema, CommaSeparatedList, SortableRequestMixin from collaborator.utils import handlers as utils from collaborator.utils.helpers import check_vendors_authorization class GetPaymentsQuery(BaseSchema, SortableRequestMixin): """Query parameters for GET /payments.""" vendor_id: int payment_statuses: CommaSeparatedList[str] = [] limit: int = 0 offset: int = 0 @app.route("/payments", methods=["GET"]) @validate() @utils.fetch_authorized_resources def get_payments( authorized_resources, user, query: GetPaymentsQuery ) -> ResponseReturnValue: """Get payments. Args: account (Account): Account which is making the request. Returns: flask.Response """ check_vendors_authorization(authorized_resources, [query.vendor_id]) result = transferwise_transaction.get_payments( vendor_id=query.vendor_id, payment_statuses=query.payment_statuses, limit=query.limit, offset=query.offset, sort_key=query.sort_key, sort_direction=query.sort_direction, ) return result.message