source: main/waeup.uniben/trunk/src/waeup/uniben/remita/browser.py @ 14789

Last change on this file since 14789 was 14778, checked in by Henrik Bettermann, 7 years ago

Define self.amount before init_update.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: browser.py 14778 2017-08-07 14:43:19Z henrik $
2##
3## Copyright (C) 2017 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
19from kofacustom.nigeria.remita.studentsbrowser import (
20    module_activated,
21    RemitaRequestPaymentStatusPageStudent,
22    RemitaPageStudent)
23from kofacustom.nigeria.remita.applicantsbrowser import (
24    RemitaRequestPaymentStatusPageApplicant,
25    RemitaPageApplicant)
26
27class CustomRemitaRequestPaymentStatusPageStudent(
28    RemitaRequestPaymentStatusPageStudent):
29    """ Request webservice view for the Remita gateway.
30    """
31
32    # Here we use Remita test portal data
33    merchantId = '2547916'
34    host = 'www.remitademo.net'
35    https = False
36    api_key = '1946'
37
38class CustomRemitaPageStudent(RemitaPageStudent):
39    """ View which sends a POST request to the Remita payment gateway.
40    """
41
42    # Here we use Remita test portal data
43    merchantId = '2547916'
44    serviceTypeId = '4430731'
45    api_key = '1946'
46    #orderId = '3456346346'
47    host = 'www.remitademo.net'
48    init_url = '/remita/ecomm/split/init.reg'
49    #amount='1000'
50    https = False
51
52    action = 'http://www.remitademo.net/remita/ecomm/finalize.reg'
53
54    @property
55    def lineitems(self):
56        ba1 = self.context.amount_auth / 2
57        ba2 = self.context.amount_auth / 2
58        lineitems = (
59                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
60                      "beneficiaryAccount":"6020067886","bankCode":"011",
61                      "beneficiaryAmount":str(ba1),"deductFeeFrom":"1"},
62                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
63                      "beneficiaryAccount":"0360883515","bankCode":"050",
64                      "beneficiaryAmount":str(ba2),"deductFeeFrom":"0"}
65                    )
66        return lineitems
67
68    def dynamic_provider_amt(self, student):
69        if student.entry_session >= 2016:
70            return 2500.0
71        return 1500.0
72
73    @property
74    def live_lineitems(self):
75        provider_amt = 0.0
76        if self.context.p_category == 'schoolfee' and \
77            not self.context.p_item == 'Balance':
78            provider_amt = self.dynamic_provider_amt(self.context.student)
79        elif self.context.p_category == 'clearance':
80            provider_amt = self.dynamic_provider_amt(self.context.student)
81        inst_amt = self.context.amount_auth - provider_amt
82        if provider_amt:
83            lineitems = (
84                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
85                          "beneficiaryAccount":"0040217361011","bankCode":"000",
86                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
87                          {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
88                          "beneficiaryAccount":"1014261520","bankCode":"057",
89                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
90                        )
91        else:
92            lineitems = (
93                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
94                          "beneficiaryAccount":"0040217361011","bankCode":"000",
95                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
96                        )
97        return lineitems
98
99    def update(self):
100        if not module_activated(self.context.student.current_session):
101            return
102        self.orderId = self.context.p_id
103        self.amount = str(self.context.amount_auth)
104        error = self.init_update()
105        if error:
106            self.flash(error, type='danger')
107            self.redirect(self.url(self.context, '@@index'))
108            return
109        return
110
111class CustomRemitaRequestPaymentStatusPageApplicant(
112    RemitaRequestPaymentStatusPageApplicant):
113    """ Request webservice view for the Remita gateway.
114    """
115
116    # Here we use Remita test portal data
117    merchantId = '2547916'
118    host = 'www.remitademo.net'
119    https = False
120    api_key = '1946'
121
122class CustomRemitaPageApplicant(RemitaPageApplicant):
123    """ View which sends a POST request to the Remita payment gateway.
124    """
125
126    # Here we use Remita test portal data
127    merchantId = '2547916'
128    serviceTypeId = '4430731'
129    api_key = '1946'
130    #orderId = '3456346346'
131    host = 'www.remitademo.net'
132    init_url = '/remita/ecomm/split/init.reg'
133    #amount='1000'
134    https = False
135
136    action = 'http://www.remitademo.net/remita/ecomm/finalize.reg'
137
138    @property
139    def lineitems(self):
140        lineitems = (
141                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
142                      "beneficiaryAccount":"6020067886","bankCode":"011",
143                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
144                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
145                      "beneficiaryAccount":"0360883515","bankCode":"050",
146                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
147                    )
148        return lineitems
149
150    @property
151    def live_lineitems(self):
152        provider_amt = 400.0
153        if self.context.__parent__.applicant_id.startswith('cbt'):
154            provider_amt = 200.0
155        inst_amt = self.context.amount_auth - provider_amt
156        lineitems = (
157                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
158                      "beneficiaryAccount":"0040217361011","bankCode":"000",
159                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
160                      {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
161                      "beneficiaryAccount":"1014261520","bankCode":"057",
162                      "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
163                    )
164        return lineitems
165
166    def update(self):
167        if not module_activated(self.context.__parent__.__parent__.year):
168            return
169        self.orderId = self.context.p_id
170        self.amount = str(self.context.amount_auth)
171        error = self.init_update()
172        if error:
173            self.flash(error, type='danger')
174            self.redirect(self.url(self.context, '@@index'))
175            return
176        return
Note: See TracBrowser for help on using the repository browser.