source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/paypal/__init__.py @ 17316

Last change on this file since 17316 was 17316, checked in by Henrik Bettermann, 20 months ago

Adjust to base package.

File size: 2.4 KB
Line 
1## $Id$
2##
3## Copyright (C) 2022 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18# Classes that represent entitites needed when dealing with paypal.
19import datetime
20import grok
21from zope.component import queryUtility
22from kofacustom.nigeria.paypal.interfaces import IPaypalConfig
23
24
25def module_activated(session, payment):
26    #if payment is not None and not payment.p_currency in ('USD',):
27    #    return False
28    if queryUtility(IPaypalConfig) is None:
29        return False
30    if getattr(payment, 'r_company', '') and payment.r_company != 'paypal':
31        return False
32    config = grok.getSite()['configuration']
33    session_conf = config.get(str(session)) or config.get(str(
34        datetime.datetime.now().year))
35    return getattr(session_conf, "paypal_enabled", False)
36
37
38class Amount(object):
39    """Paypal Amount
40
41    A structure that represents amounts of money.
42    """
43
44    def __init__(self, value="0.00", currency_code="USD"):
45        if type(value) in (int, float):
46            value = "%.2f" % round(value, 2)
47        self.value = value
48        self.currency_code = currency_code
49
50    def json(self):
51        return dict(value=self.value, currency_code=self.currency_code)
52
53
54class PurchaseUnit(object):
55    """Paypal purchase unit.
56
57    When creating paypal orders, the single things to be paid are passed
58    formatted as `purchase units`.
59    """
60
61    def __init__(self, description="", amount=Amount(), custom_id=None):
62        self.description = description
63        self.amount = amount
64        self.custom_id = custom_id
65
66    def json(self):
67        result = dict(
68            amount=self.amount.json(),
69            description=self.description,
70        )
71        if self.custom_id is not None:
72            result["custom_id"] = self.custom_id
73        return result
Note: See TracBrowser for help on using the repository browser.