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

Last change on this file since 14792 was 14792, checked in by Henrik Bettermann, 7 years ago

Define MERCHANTID, HOST, HTTPS, API_KEY, SERVICETYPEID in one place.

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1## $Id: browser.py 14792 2017-08-10 06:54:48Z 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 = '2547916'
31HOST = 'www.remitademo.net'
32HTTPS = False
33API_KEY = '1946'
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    serviceTypeId = SERVICETYPEID
46
47class CustomRemitaVerifyPaymentStatusPageStudent(
48    RemitaVerifyPaymentStatusPageStudent):
49    """ Request webservice view for the Remita gateway.
50    """
51
52    merchantId = MERCHANTID
53    host = HOST
54    https = HTTPS
55    api_key = API_KEY
56
57class CustomRemitaPageStudent(RemitaPageStudent):
58    """ View which sends a POST request to the Remita payment gateway.
59    """
60
61    merchantId = MERCHANTID
62    host = HOST
63    https = HTTPS
64    api_key = API_KEY
65    serviceTypeId = SERVICETYPEID
66
67    init_url = '/remita/ecomm/split/init.reg'
68    action = 'http://www.remitademo.net/remita/ecomm/finalize.reg'
69
70    @property
71    def lineitems(self):
72        ba1 = self.context.amount_auth / 2
73        ba2 = self.context.amount_auth / 2
74        lineitems = (
75                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
76                      "beneficiaryAccount":"6020067886","bankCode":"011",
77                      "beneficiaryAmount":str(ba1),"deductFeeFrom":"1"},
78                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
79                      "beneficiaryAccount":"0360883515","bankCode":"050",
80                      "beneficiaryAmount":str(ba2),"deductFeeFrom":"0"}
81                    )
82        return lineitems
83
84    def dynamic_provider_amt(self, student):
85        if student.entry_session >= 2016:
86            return 2500.0
87        return 1500.0
88
89    @property
90    def live_lineitems(self):
91        provider_amt = 0.0
92        if self.context.p_category == 'schoolfee' and \
93            not self.context.p_item == 'Balance':
94            provider_amt = self.dynamic_provider_amt(self.context.student)
95        elif self.context.p_category == 'clearance':
96            provider_amt = self.dynamic_provider_amt(self.context.student)
97        inst_amt = self.context.amount_auth - provider_amt
98        if provider_amt:
99            lineitems = (
100                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
101                          "beneficiaryAccount":"0040217361011","bankCode":"000",
102                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
103                          {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
104                          "beneficiaryAccount":"1014261520","bankCode":"057",
105                          "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
106                        )
107        else:
108            lineitems = (
109                          {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
110                          "beneficiaryAccount":"0040217361011","bankCode":"000",
111                          "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
112                        )
113        return lineitems
114
115    def update(self):
116        if not module_activated(self.context.student.current_session):
117            return
118        self.orderId = self.context.p_id
119        self.amount = str(self.context.amount_auth)
120        error = self.init_update()
121        if error:
122            self.flash(error, type='danger')
123            self.redirect(self.url(self.context, '@@index'))
124            return
125        return
126
127class CustomRemitaRequestPaymentStatusPageApplicant(
128    RemitaRequestPaymentStatusPageApplicant):
129    """ Request webservice view for the Remita gateway.
130    """
131
132    merchantId = MERCHANTID
133    host = HOST
134    https = HTTPS
135    api_key = API_KEY
136    serviceTypeId = SERVICETYPEID
137
138class CustomRemitaVerifyPaymentStatusPageApplicant(
139    RemitaVerifyPaymentStatusPageApplicant):
140    """ Request webservice view for the Remita gateway.
141    """
142
143    merchantId = MERCHANTID
144    host = HOST
145    https = HTTPS
146    api_key = API_KEY
147
148class CustomRemitaPageApplicant(RemitaPageApplicant):
149    """ View which sends a POST request to the Remita payment gateway.
150    """
151
152    merchantId = MERCHANTID
153    host = HOST
154    https = HTTPS
155    api_key = API_KEY
156    serviceTypeId = SERVICETYPEID
157
158    init_url = '/remita/ecomm/split/init.reg'
159    action = 'http://www.remitademo.net/remita/ecomm/finalize.reg'
160
161    @property
162    def lineitems(self):
163        lineitems = (
164                      {"lineItemsId":"itemid1","beneficiaryName":"Klaus Mueller",
165                      "beneficiaryAccount":"6020067886","bankCode":"011",
166                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"1"},
167                      {"lineItemsId":"itemid2","beneficiaryName":"Werner Rumm",
168                      "beneficiaryAccount":"0360883515","bankCode":"050",
169                      "beneficiaryAmount":self.context.amount_auth/2,"deductFeeFrom":"0"}
170                    )
171        return lineitems
172
173    @property
174    def live_lineitems(self):
175        provider_amt = 400.0
176        if self.context.__parent__.applicant_id.startswith('cbt'):
177            provider_amt = 200.0
178        inst_amt = self.context.amount_auth - provider_amt
179        lineitems = (
180                      {"lineItemsId":"itemid1","beneficiaryName":"Uniben",
181                      "beneficiaryAccount":"0040217361011","bankCode":"000",
182                      "beneficiaryAmount":inst_amt,"deductFeeFrom":"1"},
183                      {"lineItemsId":"itemid2","beneficiaryName":"WAeAC",
184                      "beneficiaryAccount":"1014261520","bankCode":"057",
185                      "beneficiaryAmount":provider_amt,"deductFeeFrom":"0"}
186                    )
187        return lineitems
188
189    def update(self):
190        if not module_activated(self.context.__parent__.__parent__.year):
191            return
192        self.orderId = self.context.p_id
193        self.amount = str(self.context.amount_auth)
194        error = self.init_update()
195        if error:
196            self.flash(error, type='danger')
197            self.redirect(self.url(self.context, '@@index'))
198            return
199        return
Note: See TracBrowser for help on using the repository browser.