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

Last change on this file since 16390 was 16389, checked in by Henrik Bettermann, 4 years ago

Change id again.

  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1## $Id: browser.py 16389 2021-01-27 19:32:37Z 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.endswith('pg_pt'):
76                return '2067091011'
77            if student.current_mode == 'ug_sw':
78                return '2066967204'
79            if student.current_mode.endswith('ug_ft'):
80                return '2067091395'
81            if student.current_mode == 'ug_pt':
82                return '2067091679'
83            if student.current_mode == 'special_ft':
84                return '2750318564' # Module 2
85            if student.is_jupeb:
86                return '1946888188'
87        if self.context.p_category == 'bed_allocation':
88            if student.is_postgrad:
89                return '2067086599'
90            return '2067089893'
91        if self.context.p_category == 'hostel_maintenance':
92            if student.is_postgrad:
93                return '2067089226'
94            return '2066966390'
95        if self.context.p_category == 'clearance':
96            if student.current_mode.startswith('dp_'):
97                return '2067080314'
98            if student.is_jupeb:
99                return '1947201668'
100            if student.is_postgrad:
101                return '2067086157'
102            return '2067089446'
103        if self.context.p_category == 'jupeb':
104            return '1947198586'
105        #if self.context.p_category == 'pharmd_1':
106        #    return '2750314820' # Clerkship
107        if self.context.p_category == 'pharmd_2':
108            return '2750174184' # Module 1
109        if self.context.p_category == 'medical_quest':
110            return '512570052'
111        return ''
112
113    def dynamic_provider_amt(self, student):
114        if student.entry_session >= 2016:
115            return 2500.0
116        return 1500.0
117
118    @property
119    def lineitems(self):
120        inst_bankcode = "000"
121        inst_acct = "0040217361011"
122        provider_amt = 0.0
123        student_union = 0.0
124        jupeb_amt = 0.0
125        reduced_inst_amt = 0.0
126        lab_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            if self.context.student.current_mode == 'ug_ft':
131                student_union = 1000.0
132        elif self.context.p_category == 'clearance':
133            provider_amt = self.dynamic_provider_amt(self.context.student)
134
135        inst_amt = self.context.amount_auth - provider_amt - student_union
136
137        lineitems = (
138                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
139                      "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
140                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
141                    )
142        if provider_amt:
143            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
144                          "beneficiaryAccount":"1014261520","bankCode":"057",
145                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
146        if student_union:
147            lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"Student Union",
148                          "beneficiaryAccount":"0025636203","bankCode":"039",
149                          "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
150
151        # We overwrite linetems in case of JUPEB students
152        if self.context.student.is_jupeb:
153            if self.context.p_category == 'clearance':
154                provider_amt = self.dynamic_provider_amt(self.context.student)
155                reduced_inst_amt = 0.7 * inst_amt
156                jupeb_amt = 0.3 * inst_amt
157            elif self.context.p_category == 'schoolfee' and \
158                not self.context.p_item == 'Balance':
159                provider_amt = self.dynamic_provider_amt(self.context.student)
160                if self.context.student.depcode in ('AGR_JUP','EDU_JUP','ENG_JUP',
161                                               'LSC_JUP','MED_JUP','PSC_JUP'):
162                    lab_amt = 10000
163                reduced_inst_amt = 0.7 * (inst_amt - lab_amt)
164                jupeb_amt = 0.3 * (inst_amt - lab_amt) + lab_amt
165            lineitems = (
166                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
167                          "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
168                          "beneficiaryAmount":reduced_inst_amt,"deductFeeFrom":"1"},
169                        )
170            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"JUPEB",
171                          "beneficiaryAccount":"0025636203","bankCode":"039",
172                          "beneficiaryAmount":jupeb_amt,"deductFeeFrom":"0"},)
173            if provider_amt:
174                lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
175                              "beneficiaryAccount":"1014261520","bankCode":"057",
176                              "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
177            if student_union:
178                lineitems += ({"lineItemsId":"itemid4","beneficiaryName":"Student Union",
179                              "beneficiaryAccount":"0025636203","bankCode":"039",
180                              "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
181
182
183        # Split pharmd school fee payments into 3 parts if students decide to pay the
184        # entire school fee at once. If the amount is less than N240000, the student
185        # has obviously paid the first installment of N80000 (pharmd_1)
186        # (disabled on 16/03/18)
187        #if self.context.p_category == 'schoolfee' \
188        #    and self.context.student.current_mode == 'special_ft' \
189        #    and self.context.amount_auth >= 240000:
190        #    pcn_amt = 80000.0
191        #    inst_amt -= pcn_amt
192        #    lineitems = (
193        #                  {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
194        #                  "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
195        #                  "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
196        #                  {"lineItemsId":"itemid2","beneficiaryName":"PCN",
197        #                  "beneficiaryAccount":"0020197061015","bankCode":inst_bankcode,
198        #                  "beneficiaryAmount":pcn_amt,"deductFeeFrom":"0"},
199        #                  {"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
200        #                  "beneficiaryAccount":"1014261520","bankCode":"057",
201        #                  "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
202        #                )
203        self.context.provider_amt = provider_amt
204        self.context.net_amt = inst_amt
205        return lineitems
206
207    def update(self):
208        if not module_activated(
209            self.context.student.current_session, self.context):
210            return
211        self.orderId = self.context.p_id
212        self.amount = str(self.context.amount_auth)
213        error = self.init_update()
214        if error:
215            self.flash(error, type='danger')
216            self.redirect(self.url(self.context, '@@index'))
217            return
218        self.context.r_company = u'remita'
219        return
220
221class CustomRemitaRequestPaymentStatusPageApplicant(
222    RemitaRequestPaymentStatusPageApplicant):
223    """ Request webservice view for the Remita gateway.
224    """
225
226    merchantId = MERCHANTID
227    host = HOST
228    https = HTTPS
229    api_key = API_KEY
230
231class CustomRemitaVerifyPaymentStatusPageApplicant(
232    RemitaVerifyPaymentStatusPageApplicant):
233    """ Request webservice view for the Remita gateway.
234    """
235
236    merchantId = MERCHANTID
237    host = HOST
238    https = HTTPS
239    api_key = API_KEY
240
241class CustomRemitaPageApplicant(RemitaPageApplicant):
242    """ View which sends a POST request to the Remita payment gateway.
243    """
244
245    merchantId = MERCHANTID
246    host = HOST
247    https = HTTPS
248    api_key = API_KEY
249
250    init_url = '/remita/ecomm/split/init.reg'
251
252    @property
253    def serviceTypeId(self):
254        applicant = self.context.__parent__
255        if applicant.__parent__.prefix.startswith('dp'):
256            return '2066963437'
257        if applicant.__parent__.prefix in ('spft', ):
258            return '2067086388'
259        if applicant.__parent__.prefix == 'pre':
260            return '1946882248'
261        if applicant.__parent__.prefix in ('pude','putme','cbt',
262                                           'ab','ak','akj','ase'):
263            return '2066965951'
264        if applicant.__parent__.prefix in ('tscs', 'tscf'):
265            return '698984179'
266        return ''
267
268    @property
269    def demo_lineitems(self):
270        lineitems = (
271                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
272                      "beneficiaryAccount":"6020067886","bankCode":"011",
273                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
274                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
275                      "beneficiaryAccount":"0360883515","bankCode":"050",
276                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
277                    )
278        return lineitems
279
280    @property
281    def lineitems(self):
282        provider_amt = 1000.0
283        if self.context.__parent__.applicant_id.startswith('pre'):
284            provider_amt = 2000.0
285        if self.context.__parent__.applicant_id.startswith('tsc'):
286            provider_amt = 1200.0
287        if self.context.__parent__.applicant_id.startswith('ase'):
288            provider_amt = 500.0
289        if self.context.__parent__.applicant_id.startswith('pude'):
290            provider_amt = 500.0
291        if self.context.__parent__.applicant_id.startswith('dp'):
292            inst_acct = "0040217361038"
293        else:
294            inst_acct = "0040217361011"
295        if self.context.__parent__.applicant_id.startswith('cbt'):
296            provider_amt = 300.0
297        if self.context.p_item == 'Balance':
298            provider_amt = 0.0
299        inst_amt = self.context.amount_auth - provider_amt
300        lineitems = (
301                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
302                      "beneficiaryAccount":inst_acct,"bankCode":"000",
303                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
304                    )
305        if provider_amt:
306            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
307                          "beneficiaryAccount":"1014261520","bankCode":"057",
308                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
309
310        self.context.provider_amt = provider_amt
311        self.context.net_amt = inst_amt
312        return lineitems
313
314    def update(self):
315        if not module_activated(
316            self.context.__parent__.__parent__.year, self.context):
317            return
318        self.orderId = self.context.p_id
319        self.amount = str(self.context.amount_auth)
320        error = self.init_update()
321        if error:
322            self.flash(error, type='danger')
323            self.redirect(self.url(self.context, '@@index'))
324            return
325        self.context.r_company = u'remita'
326        return
Note: See TracBrowser for help on using the repository browser.