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

Last change on this file since 17930 was 17753, checked in by Henrik Bettermann, 6 months ago

Add missing custom page.

  • Property svn:keywords set to Id
File size: 16.1 KB
Line 
1## $Id: browser.py 17753 2024-05-08 11:40:13Z 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
46    def render(self):
47        if self.context.p_category == 'plag_test'\
48            and self.context.p_state  == 'paid':
49            self.redirect(self.url(self.context, 'plagtestinfo'))
50        else:
51            self.redirect(self.url(self.context, '@@index'))
52        return
53
54class CustomRemitaVerifyPaymentStatusPageStudent(
55    RemitaVerifyPaymentStatusPageStudent):
56    """ Request webservice view for the Remita gateway.
57    """
58
59    merchantId = MERCHANTID
60    host = HOST
61    https = HTTPS
62    api_key = API_KEY
63
64    def update(self):
65        super(CustomRemitaVerifyPaymentStatusPageStudent, self).update()
66        # Repair: Uniben allows also previous session students to book a bed
67        if self.context.p_category == 'bed_allocation' and self.context.p_state == 'paid' and self.context.ac == None:
68            flashtype, msg, log = self.context.doAfterStudentPayment()
69            if log is not None:
70                self.context.student.writeLogMessage(self, log)
71            self.flash(msg, type=flashtype)
72        return
73
74class CustomRemitaPageStudent(RemitaPageStudent):
75    """ View which sends a POST request to the Remita payment gateway.
76    """
77
78    merchantId = MERCHANTID
79    host = HOST
80    https = HTTPS
81    api_key = API_KEY
82
83    init_url = '/remita/ecomm/split/init.reg'
84
85    @property
86    def serviceTypeId(self):
87        student = self.context.student
88        if self.context.p_category == 'schoolfee':
89            if student.current_mode.startswith('dp_'):
90                return '2067090482'
91            if student.current_mode in ('pg_ft', 'pgd_ft'):
92                return '2067090691'
93            if student.current_mode in ('pg_pt', 'pgd_pt', 'special_pg_pt'):
94                return '2067091011'
95            if student.current_mode == 'ug_sw':
96                return '2066967204'
97            if student.current_mode.endswith('ug_ft'):
98                return '2067091395'
99            if student.current_mode == 'ug_pt':
100                return '2067091679'
101            if student.current_mode == 'special_ft':
102                return '2750318564' # Module 2
103            if student.is_jupeb:
104                return '1946888188'
105            if student.current_mode == 'cdl':
106                return '9541632464'
107        if self.context.p_category == 'bed_allocation':
108            if student.is_postgrad:
109                return '2067086599'
110            return '2067089893'
111        if self.context.p_category == 'hostel_maintenance':
112            if student.is_postgrad:
113                return '2067089226'
114            return '2066966390'
115        if self.context.p_category == 'clearance':
116            if student.current_mode.startswith('dp_'):
117                return '2067080314'
118            if student.is_jupeb:
119                return '1947201668'
120            if student.is_postgrad:
121                return '2067086157'
122            if student.current_mode == 'ug_pt':
123                return '2072765946'
124            if student.current_mode == 'cdl':
125                return '8242101527'
126            return '2067089446'
127        if self.context.p_category == 'jupeb':
128            return '1947198586'
129        if self.context.p_category == 'plag_test':
130            return '2051987298'
131        #if self.context.p_category == 'pharmd_1':
132        #    return '2750314820' # Clerkship
133        if self.context.p_category == 'pharmd_2':
134            return '2750174184' # Module 1
135        if self.context.p_category == 'medical_quest':
136            return '512570052'
137        if self.context.p_category == 'flc_modules':
138            return '757257557'
139        return ''
140
141    def dynamic_provider_amt(self, student):
142        if student.entry_session >= 2016:
143            return 2500.0
144        return 1500.0
145
146    @property
147    def lineitems(self):
148        inst_bankcode = "000"
149        inst_acct = "0040217361011"
150        provider_amt = 0.0
151        student_union = 0.0
152        jupeb_amt = 0.0
153        reduced_inst_amt = 0.0
154        lab_amt = 0.0
155        if self.context.p_category == 'schoolfee' and \
156            not self.context.p_item == 'Balance':
157            provider_amt = self.dynamic_provider_amt(self.context.student)
158            if self.context.student.current_mode == 'ug_ft':
159                student_union = 2500.0
160        elif self.context.p_category == 'clearance':
161            provider_amt = self.dynamic_provider_amt(self.context.student)
162
163        inst_amt = self.context.amount_auth - provider_amt - student_union
164
165        lineitems = (
166                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
167                      "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
168                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
169                    )
170        if provider_amt:
171            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
172                          "beneficiaryAccount":"1014261520","bankCode":"057",
173                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
174        if student_union:
175            lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"Student Union",
176                          "beneficiaryAccount":"0025636203","bankCode":"039",
177                          "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
178
179        # We overwrite linetems in case of postgrad student school fee payments
180        if self.context.student.is_postgrad and self.context.p_category == 'schoolfee':
181            microfinance_amt = 0.1 * inst_amt
182            inst_amt -= microfinance_amt
183            lineitems = (
184                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
185                          "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
186                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
187                        )
188            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"SPGS Scheme",
189                          "beneficiaryAccount":"0025636203","bankCode":"039",
190                          "beneficiaryAmount":microfinance_amt,"deductFeeFrom":"0"},
191                         {"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
192                          "beneficiaryAccount":"1014261520","bankCode":"057",
193                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
194
195        ## Disabled on 24/02/21
196        ## Reenabled on 19/09/23 (ticket #1327)
197        ## We overwrite linetems in case of JUPEB students
198        if self.context.student.is_jupeb:
199            if self.context.p_category == 'clearance':
200                provider_amt = self.dynamic_provider_amt(self.context.student)
201                reduced_inst_amt = 0.7 * inst_amt
202                jupeb_amt = 0.3 * inst_amt
203            elif self.context.p_category == 'schoolfee' and \
204                not self.context.p_item == 'Balance':
205                provider_amt = self.dynamic_provider_amt(self.context.student)
206                #if self.context.student.depcode in ('AGR_JUP','EDU_JUP','ENG_JUP',
207                #                               'LSC_JUP','MED_JUP','PSC_JUP'):
208                #    lab_amt = 10000
209                reduced_inst_amt = 0.7 * (inst_amt - lab_amt)
210                jupeb_amt = 0.3 * (inst_amt - lab_amt) + lab_amt
211            lineitems = (
212                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
213                          "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
214                          "beneficiaryAmount":reduced_inst_amt,"deductFeeFrom":"1"},
215                        )
216            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"JUPEB",
217                          "beneficiaryAccount":"0025636203","bankCode":"039",
218                          "beneficiaryAmount":jupeb_amt,"deductFeeFrom":"0"},)
219            if provider_amt:
220                lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
221                              "beneficiaryAccount":"1014261520","bankCode":"057",
222                              "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
223            if student_union:
224                lineitems += ({"lineItemsId":"itemid4","beneficiaryName":"Student Union",
225                              "beneficiaryAccount":"0025636203","bankCode":"039",
226                              "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
227
228
229        # Split pharmd school fee payments into 3 parts if students decide to pay the
230        # entire school fee at once. If the amount is less than N240000, the student
231        # has obviously paid the first installment of N80000 (pharmd_1)
232        # (disabled on 16/03/18)
233        #if self.context.p_category == 'schoolfee' \
234        #    and self.context.student.current_mode == 'special_ft' \
235        #    and self.context.amount_auth >= 240000:
236        #    pcn_amt = 80000.0
237        #    inst_amt -= pcn_amt
238        #    lineitems = (
239        #                  {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
240        #                  "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
241        #                  "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
242        #                  {"lineItemsId":"itemid2","beneficiaryName":"PCN",
243        #                  "beneficiaryAccount":"0020197061015","bankCode":inst_bankcode,
244        #                  "beneficiaryAmount":pcn_amt,"deductFeeFrom":"0"},
245        #                  {"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
246        #                  "beneficiaryAccount":"1014261520","bankCode":"057",
247        #                  "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
248        #                )
249        self.context.provider_amt = provider_amt
250        self.context.net_amt = inst_amt
251        return lineitems
252
253    def update(self):
254        if not module_activated(
255            self.context.student.current_session, self.context):
256            return
257        self.orderId = self.context.p_id
258        self.amount = str(self.context.amount_auth)
259        error = self.init_update()
260        if error:
261            self.flash(error, type='danger')
262            self.redirect(self.url(self.context, '@@index'))
263            return
264        self.context.r_company = u'remita'
265        return
266
267class CustomRemitaRequestPaymentStatusPageApplicant(
268    RemitaRequestPaymentStatusPageApplicant):
269    """ Request webservice view for the Remita gateway.
270    """
271
272    merchantId = MERCHANTID
273    host = HOST
274    https = HTTPS
275    api_key = API_KEY
276
277
278class CustomRemitaVerifyPaymentStatusPageApplicant(
279    RemitaVerifyPaymentStatusPageApplicant):
280    """ Request webservice view for the Remita gateway.
281    """
282
283    merchantId = MERCHANTID
284    host = HOST
285    https = HTTPS
286    api_key = API_KEY
287
288class CustomRemitaPageApplicant(RemitaPageApplicant):
289    """ View which sends a POST request to the Remita payment gateway.
290    """
291
292    merchantId = MERCHANTID
293    host = HOST
294    https = HTTPS
295    api_key = API_KEY
296
297    init_url = '/remita/ecomm/split/init.reg'
298
299    @property
300    def serviceTypeId(self):
301        applicant = self.context.__parent__
302        if applicant.__parent__.prefix.startswith('dp'):
303            return '2066963437'
304        if applicant.__parent__.prefix in ('spft', ):
305            return '2067086388'
306        if applicant.__parent__.prefix == 'pre':
307            return '1946882248'
308        if applicant.__parent__.prefix in ('pude','putme','cbt',
309                                           'ab','ak','akj','ase'):
310            return '2066965951'
311        if applicant.__parent__.prefix in ('tscs', 'tscf'):
312            return '698984179'
313        if applicant.__parent__.prefix == 'flc':
314            return '757257557'     
315        if applicant.__parent__.prefix in ('pt', 'ptext'):
316            return '2072815846'
317        if applicant.__parent__.prefix.startswith('pg'):
318            return '2067086388'   
319        if applicant.__parent__.prefix in ('sandwich'):
320            return '2072760654'
321        if applicant.__parent__.prefix == 'cdl':
322            return '8197875656'
323        return ''
324
325    @property
326    def demo_lineitems(self):
327        lineitems = (
328                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
329                      "beneficiaryAccount":"6020067886","bankCode":"011",
330                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
331                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
332                      "beneficiaryAccount":"0360883515","bankCode":"050",
333                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
334                    )
335        return lineitems
336
337    @property
338    def lineitems(self):
339        applicant = self.context.__parent__
340        if applicant.applicant_id.startswith('dp'):
341            inst_acct = "0040217361038"
342        else:
343            inst_acct = "0040217361011"
344        provider_amt = 1000.0
345        if applicant.__parent__.prefix == 'pre':
346            provider_amt = 2000.0
347        if applicant.__parent__.prefix.startswith('tsc'):
348            provider_amt = 1200.0
349            if applicant.order == 'c':
350                provider_amt = 1000.0
351        if applicant.__parent__.prefix.startswith('ase'):
352            provider_amt = 500.0
353        if applicant.__parent__.prefix == 'pude':
354            provider_amt = 500.0
355        if applicant.__parent__.prefix == 'cdl':
356            provider_amt = 0.0
357        if applicant.__parent__.prefix == 'cbt':
358            provider_amt = 300.0
359        if applicant.__parent__.prefix in ('pt', 'ptext', 'sandwich'):
360            provider_amt = 2000.0
361        if applicant.__parent__.prefix.startswith('pg'):
362            provider_amt = 2000.0
363        if self.context.p_item == 'Balance':
364            provider_amt = 0.0
365        inst_amt = self.context.amount_auth - provider_amt
366        lineitems = (
367                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
368                      "beneficiaryAccount":inst_acct,"bankCode":"000",
369                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
370                    )
371        if provider_amt:
372            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
373                          "beneficiaryAccount":"1014261520","bankCode":"057",
374                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
375        self.context.provider_amt = provider_amt
376        self.context.net_amt = inst_amt
377        return lineitems
378
379    def update(self):
380        if not module_activated(
381            self.context.__parent__.__parent__.year, self.context):
382            return
383        self.orderId = self.context.p_id
384        self.amount = str(self.context.amount_auth)
385        error = self.init_update()
386        if error:
387            self.flash(error, type='danger')
388            self.redirect(self.url(self.context, '@@index'))
389            return
390        self.context.r_company = u'remita'
391        return
Note: See TracBrowser for help on using the repository browser.