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

Last change on this file since 17037 was 17037, checked in by Henrik Bettermann, 2 years ago

Configure provider amount.

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