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

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

Configure serviceTypeId for application payments.

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1## $Id: browser.py 14800 2017-08-14 10:48:09Z 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    RemitaVerifyPaymentStatusPageStudent,
23    RemitaPageStudent)
24from kofacustom.nigeria.remita.applicantsbrowser import (
25    RemitaRequestPaymentStatusPageApplicant,
26    RemitaVerifyPaymentStatusPageApplicant,
27    RemitaPageApplicant)
28
29# Temporarily we can use the test portal like in kofacustom.nigeria
30MERCHANTID = '2067163382'
31HOST = 'login.remita.net'
32HTTPS = True
33API_KEY = '309418'
34SERVICETYPEID = '4430731'
35
36class CustomRemitaRequestPaymentStatusPageStudent(
37    RemitaRequestPaymentStatusPageStudent):
38    """ Request webservice view for the Remita gateway.
39    """
40
41    merchantId = MERCHANTID
42    host = HOST
43    https = HTTPS
44    api_key = API_KEY
45
46class CustomRemitaVerifyPaymentStatusPageStudent(
47    RemitaVerifyPaymentStatusPageStudent):
48    """ Request webservice view for the Remita gateway.
49    """
50
51    merchantId = MERCHANTID
52    host = HOST
53    https = HTTPS
54    api_key = API_KEY
55
56class CustomRemitaPageStudent(RemitaPageStudent):
57    """ View which sends a POST request to the Remita payment gateway.
58    """
59
60    merchantId = MERCHANTID
61    host = HOST
62    https = HTTPS
63    api_key = API_KEY
64
65    init_url = '/remita/ecomm/split/init.reg'
66
67    @property
68    def serviceTypeId(self):
69        student = self.context.student
70        if self.context.p_category == 'schoolfee':
71            if student.current_mode.startswith('dp_'):
72                return '2067090482'
73            if student.current_mode == 'pg_ft':
74                return '2067090691'
75            if student.current_mode == 'pg_pt':
76                return '2067091011'
77            if student.current_mode == 'ug_sw':
78                return '2066967204'
79            if student.current_mode == 'ug_ft':
80                return '2067091395'
81            if student.current_mode == 'ug_pt':
82                return '2067091679'
83            if student.faccode == 'JUPEB':
84                return '1946888188'
85        if self.context.p_category == 'bed_allocation':
86            if student.is_postgrad:
87                return '2067086599'
88            return '2067089893'
89        if self.context.p_category == 'hostel_maintenance':
90            if student.is_postgrad:
91                return '2067089226'
92            return '2066966390'
93        if self.context.p_category == 'clearance':
94            if student.current_mode.startswith('dp_'):
95                return '2067080314'
96            if student.faccode == 'JUPEB':
97                return '1947201668'
98            if student.is_postgrad:
99                return '2067086157'
100            return '2067089446'
101        if self.context.p_category == 'jupeb':
102            return '1947198586'
103        return ''
104
105    @property
106    def demo_lineitems(self):
107        ba1 = self.context.amount_auth / 2
108        ba2 = self.context.amount_auth / 2
109        lineitems = (
110                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
111                      "beneficiaryAccount":"6020067886","bankCode":"011",
112                      "beneficiaryAmount":str(ba1),"deductFeeFrom":"1"},
113                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
114                      "beneficiaryAccount":"0360883515","bankCode":"050",
115                      "beneficiaryAmount":str(ba2),"deductFeeFrom":"0"}
116                    )
117        return lineitems
118
119    def dynamic_provider_amt(self, student):
120        if student.entry_session >= 2016:
121            return 2500.0
122        return 1500.0
123
124    @property
125    def lineitems(self):
126        provider_amt = 0.0
127        if self.context.p_category == 'schoolfee' and \
128            not self.context.p_item == 'Balance':
129            provider_amt = self.dynamic_provider_amt(self.context.student)
130        elif self.context.p_category == 'clearance':
131            provider_amt = self.dynamic_provider_amt(self.context.student)
132        inst_amt = self.context.amount_auth - provider_amt
133        if provider_amt:
134            lineitems = (
135                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
136                          "beneficiaryAccount":"0040217361011","bankCode":"000",
137                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
138                          {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
139                          "beneficiaryAccount":"1014261520","bankCode":"057",
140                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
141                        )
142        else:
143            lineitems = (
144                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
145                          "beneficiaryAccount":"0040217361011","bankCode":"000",
146                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
147                        )
148        return lineitems
149
150    def update(self):
151        if not module_activated(self.context.student.current_session):
152            return
153        self.orderId = self.context.p_id
154        self.amount = str(self.context.amount_auth)
155        error = self.init_update()
156        if error:
157            self.flash(error, type='danger')
158            self.redirect(self.url(self.context, '@@index'))
159            return
160        return
161
162class CustomRemitaRequestPaymentStatusPageApplicant(
163    RemitaRequestPaymentStatusPageApplicant):
164    """ Request webservice view for the Remita gateway.
165    """
166
167    merchantId = MERCHANTID
168    host = HOST
169    https = HTTPS
170    api_key = API_KEY
171
172class CustomRemitaVerifyPaymentStatusPageApplicant(
173    RemitaVerifyPaymentStatusPageApplicant):
174    """ Request webservice view for the Remita gateway.
175    """
176
177    merchantId = MERCHANTID
178    host = HOST
179    https = HTTPS
180    api_key = API_KEY
181
182class CustomRemitaPageApplicant(RemitaPageApplicant):
183    """ View which sends a POST request to the Remita payment gateway.
184    """
185
186    merchantId = MERCHANTID
187    host = HOST
188    https = HTTPS
189    api_key = API_KEY
190
191    init_url = '/remita/ecomm/split/init.reg'
192
193    @property
194    def serviceTypeId(self):
195        applicant = self.context.__parent__
196        if applicant.__parent__.prefix.startswith('dp'):
197            return '2067080314'
198        if applicant.__parent__.prefix.startswith('pg'):
199            return '2067086157'
200        if applicant.__parent__.prefix == 'pre':
201            return '1947201668'
202        if applicant.__parent__.prefix in ('pude','putme','cbt',
203                                           'ab','ak','akj'):
204            return '2067089446'
205        return ''
206
207    @property
208    def demo_lineitems(self):
209        lineitems = (
210                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
211                      "beneficiaryAccount":"6020067886","bankCode":"011",
212                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
213                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
214                      "beneficiaryAccount":"0360883515","bankCode":"050",
215                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
216                    )
217        return lineitems
218
219    @property
220    def lineitems(self):
221        provider_amt = 400.0
222        if self.context.__parent__.applicant_id.startswith('cbt'):
223            provider_amt = 200.0
224        inst_amt = self.context.amount_auth - provider_amt
225        lineitems = (
226                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
227                      "beneficiaryAccount":"0040217361011","bankCode":"000",
228                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
229                      {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
230                      "beneficiaryAccount":"1014261520","bankCode":"057",
231                      "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
232                    )
233        return lineitems
234
235    def update(self):
236        if not module_activated(self.context.__parent__.__parent__.year):
237            return
238        self.orderId = self.context.p_id
239        self.amount = str(self.context.amount_auth)
240        error = self.init_update()
241        if error:
242            self.flash(error, type='danger')
243            self.redirect(self.url(self.context, '@@index'))
244            return
245        return
Note: See TracBrowser for help on using the repository browser.