<commit_before># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
##
## Indico 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 of the
## License, or (at your option) any later version.
##
## Indico 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 Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.conference import ConferenceHolder
from MaKaC.epayment import TransactionPayLaterMod

from indico.core.fossils.registration import IRegFormRegistrantBasicFossil, IRegFormRegistrantFullFossil

from indico.web.http_api.hooks.base import HTTPAPIHook, DataFetcher
from indico.web.http_api.hooks.event import EventBaseHook
from indico.web.http_api.util import get_query_parameter
from indico.web.http_api.responses import HTTPAPIError

from indico.util.date_time import format_datetime, format_date
from indico.util.fossilize import fossilize


@HTTPAPIHook.register
class SetPaidHook(EventBaseHook):
    PREFIX = "api"
    RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/pay'
    NO_CACHE = True
    COMMIT = True
    HTTP_POST = True

    def _getParams(self):
        super(SetPaidHook, self)._getParams()
        self.auth_key = get_query_parameter(self._queryParams, ["auth_key"])
        self.is_paid = get_query_parameter(self._queryParams, ["is_paid"]) == "yes"
        registrant_id = self._pathParams["registrant_id"]
        self._conf = ConferenceHolder().getById(self._pathParams['event'])
        self._registrant = self._conf.getRegistrantById(registrant_id)
        self._type = "pay"
        if not self._conf.getModPay().isActivated():
            raise HTTPAPIError('E-payment is not enabled')

    def _hasAccess(self, aw):
        return (self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw)) \
            and self.auth_key == self._registrant.getRandomId()

    def api_pay(self, aw):
        if self.is_paid:
            self._registrant.setPayed(True)
            data = {}
            data["OrderTotal"] = self._registrant.getTotal()
            data["Currency"] = self._registrant.getRegistrationForm().getCurrency()
            transaction = TransactionPayLaterMod(data)
            self._registrant.setTransactionInfo(transaction)
        else:
            self._registrant.setTransactionInfo(None)
            self._registrant.setPayed(False)
        return {
            "paid": self._registrant.getPayed(),
            "pay_amount": self._registrant.getTotal()
        }


@HTTPAPIHook.register
class CheckInHook(EventBaseHook):
    PREFIX = "api"
    RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/checkin'
    NO_CACHE = True
    COMMIT = True
    HTTP_POST = True

    def _getParams(self):
        super(CheckInHook, self)._getParams()
        self._check_in = get_query_parameter(self._queryParams, ["checked_in"]) == "yes"
        self._secret = get_query_parameter(self._queryParams, ["secret"])
        registrant_id = self._pathParams["registrant_id"]
        self._conf = ConferenceHolder().getById(self._pathParams['event'])<commit_msg>SetPaid API return values renamed<commit_after># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
##
## Indico 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 of the
## License, or (at your option) any later version.
##
## Indico 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 Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.conference import ConferenceHolder
from MaKaC.epayment import TransactionPayLaterMod

from indico.core.fossils.registration import IRegFormRegistrantBasicFossil, IRegFormRegistrantFullFossil

from indico.web.http_api.hooks.base import HTTPAPIHook, DataFetcher
from indico.web.http_api.hooks.event import EventBaseHook
from indico.web.http_api.util import get_query_parameter
from indico.web.http_api.responses import HTTPAPIError

from indico.util.date_time import format_datetime, format_date
from indico.util.fossilize import fossilize


@HTTPAPIHook.register
class SetPaidHook(EventBaseHook):
    PREFIX = "api"
    RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/pay'
    NO_CACHE = True
    COMMIT = True
    HTTP_POST = True

    def _getParams(self):
        super(SetPaidHook, self)._getParams()
        self.auth_key = get_query_parameter(self._queryParams, ["auth_key"])
        self.is_paid = get_query_parameter(self._queryParams, ["is_paid"]) == "yes"
        registrant_id = self._pathParams["registrant_id"]
        self._conf = ConferenceHolder().getById(self._pathParams['event'])
        self._registrant = self._conf.getRegistrantById(registrant_id)
        self._type = "pay"
        if not self._conf.getModPay().isActivated():
            raise HTTPAPIError('E-payment is not enabled')

    def _hasAccess(self, aw):
        return (self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw)) \
            and self.auth_key == self._registrant.getRandomId()

    def api_pay(self, aw):
        if self.is_paid:
            self._registrant.setPayed(True)
            data = {}
            data["OrderTotal"] = self._registrant.getTotal()
            data["Currency"] = self._registrant.getRegistrationForm().getCurrency()
            transaction = TransactionPayLaterMod(data)
            self._registrant.setTransactionInfo(transaction)
        else:
            self._registrant.setTransactionInfo(None)
            self._registrant.setPayed(False)
        return {
            "paid": self._registrant.getPayed(),
            "amount_paid": self._registrant.getTotal()
        }


@HTTPAPIHook.register
class CheckInHook(EventBaseHook):
    PREFIX = "api"
    RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/checkin'
    NO_CACHE = True
    COMMIT = True
    HTTP_POST = True

    def _getParams(self):
        super(CheckInHook, self)._getParams()
        self._check_in = get_query_parameter(self._queryParams, ["checked_in"]) == "yes"
        self._secret = get_query_parameter(self._queryParams, ["secret"])
        registrant_id = self._pathParams["registrant_id"]
        self._conf = ConferenceHolder().getById(self._pathParams['event'])
{'fraction_non_alphanumeric': 0.11109540636042403, 'fraction_numerical': 0.0028268551236749115, 'mean_word_length': 3.574014221073045, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6634237', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2122, 'n_words': 509}