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

Last change on this file since 17237 was 17237, checked in by Henrik Bettermann, 21 months ago

Fix bug.

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