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

Last change on this file since 17980 was 17977, checked in by Henrik Bettermann, 5 weeks ago

Fix lineitems.

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