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

Last change on this file since 17957 was 17955, checked in by Henrik Bettermann, 8 days ago

Revert to old account.

  • Property svn:keywords set to Id
File size: 16.1 KB
RevLine 
[14746]1## $Id: browser.py 17955 2024-11-12 12:43:10Z 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
[14767]19from kofacustom.nigeria.remita.studentsbrowser import (
[14746]20    module_activated,
[14757]21    RemitaRequestPaymentStatusPageStudent,
[14792]22    RemitaVerifyPaymentStatusPageStudent,
[14746]23    RemitaPageStudent)
[14767]24from kofacustom.nigeria.remita.applicantsbrowser import (
25    RemitaRequestPaymentStatusPageApplicant,
[14792]26    RemitaVerifyPaymentStatusPageApplicant,
[14767]27    RemitaPageApplicant)
[14746]28
[14792]29# Temporarily we can use the test portal like in kofacustom.nigeria
[16090]30MERCHANTID = '2067163382'
31HOST = 'login.remita.net'
32HTTPS = True
33API_KEY = '309418'
34SERVICETYPEID = '4430731'
[14792]35
[14757]36class CustomRemitaRequestPaymentStatusPageStudent(
37    RemitaRequestPaymentStatusPageStudent):
[14746]38    """ Request webservice view for the Remita gateway.
39    """
40
[14792]41    merchantId = MERCHANTID
42    host = HOST
43    https = HTTPS
44    api_key = API_KEY
[14746]45
[16782]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
[14792]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
[17747]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
[14746]74class CustomRemitaPageStudent(RemitaPageStudent):
75    """ View which sends a POST request to the Remita payment gateway.
76    """
77
[14792]78    merchantId = MERCHANTID
79    host = HOST
80    https = HTTPS
81    api_key = API_KEY
82
[14746]83    init_url = '/remita/ecomm/split/init.reg'
84
[14776]85    @property
[14795]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'
[17371]91            if student.current_mode in ('pg_ft', 'pgd_ft'):
[14795]92                return '2067090691'
[17374]93            if student.current_mode in ('pg_pt', 'pgd_pt', 'special_pg_pt'):
[14795]94                return '2067091011'
95            if student.current_mode == 'ug_sw':
96                return '2066967204'
[14809]97            if student.current_mode.endswith('ug_ft'):
[14795]98                return '2067091395'
99            if student.current_mode == 'ug_pt':
100                return '2067091679'
[14960]101            if student.current_mode == 'special_ft':
102                return '2750318564' # Module 2
[14902]103            if student.is_jupeb:
[14795]104                return '1946888188'
[17140]105            if student.current_mode == 'cdl':
106                return '9541632464'
[14799]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'
[14902]118            if student.is_jupeb:
[14799]119                return '1947201668'
120            if student.is_postgrad:
121                return '2067086157'
[17035]122            if student.current_mode == 'ug_pt':
123                return '2072765946'
[17140]124            if student.current_mode == 'cdl':
125                return '8242101527'
[14799]126            return '2067089446'
127        if self.context.p_category == 'jupeb':
128            return '1947198586'
[16783]129        if self.context.p_category == 'plag_test':
[16785]130            return '2051987298'
[14970]131        #if self.context.p_category == 'pharmd_1':
132        #    return '2750314820' # Clerkship
[14960]133        if self.context.p_category == 'pharmd_2':
134            return '2750174184' # Module 1
[16388]135        if self.context.p_category == 'medical_quest':
[16878]136            return '512570052'
[16877]137        if self.context.p_category == 'flc_modules':
138            return '757257557'
[14795]139        return ''
140
[14767]141    def dynamic_provider_amt(self, student):
[17953]142        if student.entry_session >= 2024:
143            return 5000.0
144        return 2000.0
[14767]145
146    @property
[16090]147    def lineitems(self):
[14960]148        inst_bankcode = "000"
149        inst_acct = "0040217361011"
[14767]150        provider_amt = 0.0
[15929]151        student_union = 0.0
[16337]152        jupeb_amt = 0.0
153        reduced_inst_amt = 0.0
154        lab_amt = 0.0
[14767]155        if self.context.p_category == 'schoolfee' and \
156            not self.context.p_item == 'Balance':
[14770]157            provider_amt = self.dynamic_provider_amt(self.context.student)
[15929]158            if self.context.student.current_mode == 'ug_ft':
[17708]159                student_union = 2500.0
[14767]160        elif self.context.p_category == 'clearance':
[17953]161            provider_amt = 5000.0
162        elif self.context.p_category == 'bed_allocation':
163            provider_amt = 1000.0
[16337]164
[15938]165        inst_amt = self.context.amount_auth - provider_amt - student_union
[16337]166
[15929]167        lineitems = (
168                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
169                      "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
170                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
171                    )
[14767]172        if provider_amt:
[15929]173            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
[17955]174                          "beneficiaryAccount":"1014261520","bankCode":"057",
[15929]175                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
176        if student_union:
177            lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"Student Union",
178                          "beneficiaryAccount":"0025636203","bankCode":"039",
179                          "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
180
[17235]181        # We overwrite linetems in case of postgrad student school fee payments
[17237]182        if self.context.student.is_postgrad and self.context.p_category == 'schoolfee':
[17235]183            microfinance_amt = 0.1 * inst_amt
184            inst_amt -= microfinance_amt
185            lineitems = (
186                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
187                          "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
188                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
189                        )
[17255]190            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"SPGS Scheme",
[17235]191                          "beneficiaryAccount":"0025636203","bankCode":"039",
192                          "beneficiaryAmount":microfinance_amt,"deductFeeFrom":"0"},
193                         {"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
[17955]194                          "beneficiaryAccount":"1014261520","bankCode":"057",
[17235]195                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
196
[16398]197        ## Disabled on 24/02/21
[17590]198        ## Reenabled on 19/09/23 (ticket #1327)
[16398]199        ## We overwrite linetems in case of JUPEB students
[17590]200        if self.context.student.is_jupeb:
201            if self.context.p_category == 'clearance':
202                provider_amt = self.dynamic_provider_amt(self.context.student)
203                reduced_inst_amt = 0.7 * inst_amt
204                jupeb_amt = 0.3 * inst_amt
205            elif self.context.p_category == 'schoolfee' and \
206                not self.context.p_item == 'Balance':
207                provider_amt = self.dynamic_provider_amt(self.context.student)
208                #if self.context.student.depcode in ('AGR_JUP','EDU_JUP','ENG_JUP',
209                #                               'LSC_JUP','MED_JUP','PSC_JUP'):
210                #    lab_amt = 10000
211                reduced_inst_amt = 0.7 * (inst_amt - lab_amt)
212                jupeb_amt = 0.3 * (inst_amt - lab_amt) + lab_amt
213            lineitems = (
214                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
215                          "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
216                          "beneficiaryAmount":reduced_inst_amt,"deductFeeFrom":"1"},
217                        )
218            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"JUPEB",
[17592]219                          "beneficiaryAccount":"0025636203","bankCode":"039",
[17590]220                          "beneficiaryAmount":jupeb_amt,"deductFeeFrom":"0"},)
221            if provider_amt:
222                lineitems += ({"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
[17955]223                              "beneficiaryAccount":"1014261520","bankCode":"057",
[17590]224                              "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
225            if student_union:
226                lineitems += ({"lineItemsId":"itemid4","beneficiaryName":"Student Union",
227                              "beneficiaryAccount":"0025636203","bankCode":"039",
228                              "beneficiaryAmount":student_union,"deductFeeFrom":"0"},)
[16337]229
230
[14960]231        # Split pharmd school fee payments into 3 parts if students decide to pay the
232        # entire school fee at once. If the amount is less than N240000, the student
233        # has obviously paid the first installment of N80000 (pharmd_1)
[14970]234        # (disabled on 16/03/18)
235        #if self.context.p_category == 'schoolfee' \
236        #    and self.context.student.current_mode == 'special_ft' \
237        #    and self.context.amount_auth >= 240000:
238        #    pcn_amt = 80000.0
239        #    inst_amt -= pcn_amt
240        #    lineitems = (
241        #                  {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
242        #                  "beneficiaryAccount":inst_acct,"bankCode":inst_bankcode,
243        #                  "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
244        #                  {"lineItemsId":"itemid2","beneficiaryName":"PCN",
245        #                  "beneficiaryAccount":"0020197061015","bankCode":inst_bankcode,
246        #                  "beneficiaryAmount":pcn_amt,"deductFeeFrom":"0"},
247        #                  {"lineItemsId":"itemid3","beneficiaryName":"WAeAC",
[17955]248        #                  "beneficiaryAccount":"1014261520","bankCode":"057",
[14970]249        #                  "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
250        #                )
[14960]251        self.context.provider_amt = provider_amt
[15817]252        self.context.net_amt = inst_amt
[14767]253        return lineitems
254
[14746]255    def update(self):
[15828]256        if not module_activated(
257            self.context.student.current_session, self.context):
[14746]258            return
[14778]259        self.orderId = self.context.p_id
260        self.amount = str(self.context.amount_auth)
[14746]261        error = self.init_update()
262        if error:
263            self.flash(error, type='danger')
264            self.redirect(self.url(self.context, '@@index'))
265            return
[15817]266        self.context.r_company = u'remita'
[14767]267        return
268
[17753]269class CustomRemitaRequestPaymentStatusPageApplicant(
270    RemitaRequestPaymentStatusPageApplicant):
271    """ Request webservice view for the Remita gateway.
272    """
273
274    merchantId = MERCHANTID
275    host = HOST
276    https = HTTPS
277    api_key = API_KEY
278
279
[14792]280class CustomRemitaVerifyPaymentStatusPageApplicant(
281    RemitaVerifyPaymentStatusPageApplicant):
282    """ Request webservice view for the Remita gateway.
283    """
284
285    merchantId = MERCHANTID
286    host = HOST
287    https = HTTPS
288    api_key = API_KEY
289
[14767]290class CustomRemitaPageApplicant(RemitaPageApplicant):
291    """ View which sends a POST request to the Remita payment gateway.
292    """
293
[14792]294    merchantId = MERCHANTID
295    host = HOST
296    https = HTTPS
297    api_key = API_KEY
298
[14767]299    init_url = '/remita/ecomm/split/init.reg'
300
[14776]301    @property
[14795]302    def serviceTypeId(self):
[14799]303        applicant = self.context.__parent__
[14800]304        if applicant.__parent__.prefix.startswith('dp'):
[14813]305            return '2066963437'
[14832]306        if applicant.__parent__.prefix in ('spft', ):
[14813]307            return '2067086388'
[14800]308        if applicant.__parent__.prefix == 'pre':
[14813]309            return '1946882248'
[14800]310        if applicant.__parent__.prefix in ('pude','putme','cbt',
[16230]311                                           'ab','ak','akj','ase'):
[14813]312            return '2066965951'
[16230]313        if applicant.__parent__.prefix in ('tscs', 'tscf'):
314            return '698984179'
[16826]315        if applicant.__parent__.prefix == 'flc':
[17034]316            return '757257557'     
317        if applicant.__parent__.prefix in ('pt', 'ptext'):
318            return '2072815846'
319        if applicant.__parent__.prefix.startswith('pg'):
320            return '2067086388'   
321        if applicant.__parent__.prefix in ('sandwich'):
[17140]322            return '2072760654'
323        if applicant.__parent__.prefix == 'cdl':
324            return '8197875656'
[14799]325        return ''
[14795]326
327    @property
[16090]328    def demo_lineitems(self):
[14800]329        lineitems = (
[14776]330                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
331                      "beneficiaryAccount":"6020067886","bankCode":"011",
332                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
333                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
334                      "beneficiaryAccount":"0360883515","bankCode":"050",
335                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
336                    )
337        return lineitems
[14770]338
[14767]339    @property
[16090]340    def lineitems(self):
[17037]341        applicant = self.context.__parent__
342        if applicant.applicant_id.startswith('dp'):
[17034]343            inst_acct = "0040217361038"
344        else:
345            inst_acct = "0040217361011"
[15491]346        provider_amt = 1000.0
[17037]347        if applicant.__parent__.prefix == 'pre':
[16205]348            provider_amt = 2000.0
[17037]349        if applicant.__parent__.prefix.startswith('tsc'):
[17953]350            provider_amt = 2500.0
[17037]351            if applicant.order == 'c':
[17953]352                provider_amt = 2500.0
[17037]353        if applicant.__parent__.prefix.startswith('ase'):
[17953]354            provider_amt = 1000.0
[17037]355        if applicant.__parent__.prefix == 'pude':
[17953]356            provider_amt = 2000.0
[17147]357        if applicant.__parent__.prefix == 'cdl':
[17454]358            provider_amt = 0.0
[17037]359        if applicant.__parent__.prefix == 'cbt':
[16201]360            provider_amt = 300.0
[17037]361        if applicant.__parent__.prefix in ('pt', 'ptext', 'sandwich'):
362            provider_amt = 2000.0
363        if applicant.__parent__.prefix.startswith('pg'):
364            provider_amt = 2000.0
[16205]365        if self.context.p_item == 'Balance':
366            provider_amt = 0.0
[14770]367        inst_amt = self.context.amount_auth - provider_amt
[14767]368        lineitems = (
[14770]369                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
[14888]370                      "beneficiaryAccount":inst_acct,"bankCode":"000",
[14770]371                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
[14767]372                    )
[16205]373        if provider_amt:
374            lineitems += ({"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
[17955]375                          "beneficiaryAccount":"1014261520","bankCode":"057",
[16205]376                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"},)
[14960]377        self.context.provider_amt = provider_amt
[15817]378        self.context.net_amt = inst_amt
[14767]379        return lineitems
380
381    def update(self):
[15828]382        if not module_activated(
383            self.context.__parent__.__parent__.year, self.context):
[14767]384            return
[14778]385        self.orderId = self.context.p_id
386        self.amount = str(self.context.amount_auth)
[14767]387        error = self.init_update()
388        if error:
389            self.flash(error, type='danger')
390            self.redirect(self.url(self.context, '@@index'))
391            return
[15817]392        self.context.r_company = u'remita'
[14746]393        return
Note: See TracBrowser for help on using the repository browser.