[7894] | 1 | ## $Id: browser.py 9784 2012-12-07 08:41:19Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2012 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 | ## |
---|
[7898] | 18 | import httplib |
---|
[7894] | 19 | import grok |
---|
[8281] | 20 | from zope.component import getUtility |
---|
[9784] | 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
| 23 | InterswitchPaymentRequestWebservicePageStudent |
---|
| 24 | ) |
---|
| 25 | from waeup.kofa.browser.layout import KofaPage |
---|
[9752] | 26 | from waeup.kofa.interfaces import IKofaUtils |
---|
[8281] | 27 | from waeup.kofa.utils.helpers import to_timezone |
---|
[8460] | 28 | from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
[7894] | 31 | |
---|
[8644] | 32 | PRODUCT_ID = '83' |
---|
[8460] | 33 | SITE_NAME = 'fceokene-kofa.waeup.org' |
---|
[8641] | 34 | PROVIDER_ACCT = '0026781725' |
---|
| 35 | PROVIDER_BANK_ID = '31' |
---|
[8263] | 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[8460] | 37 | INSTITUTION_NAME = 'FCEOkene' |
---|
[7894] | 38 | CURRENCY = '566' |
---|
[9780] | 39 | GATEWAY_AMT = 150.0 |
---|
[8401] | 40 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 41 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[8385] | 42 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 43 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 44 | |
---|
[8293] | 45 | HOST = 'webpay.interswitchng.com' |
---|
| 46 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 47 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 48 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 49 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 50 | |
---|
[8256] | 51 | class InterswitchPageStudent(KofaPage): |
---|
[7894] | 52 | """ View which sends a POST request to the Interswitch |
---|
| 53 | CollegePAY payment gateway. |
---|
| 54 | """ |
---|
[8255] | 55 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 56 | grok.name('goto_interswitch') |
---|
[8256] | 57 | grok.template('student_goto_interswitch') |
---|
[7894] | 58 | grok.require('waeup.payStudent') |
---|
| 59 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 60 | submit_button = _('Submit') |
---|
| 61 | action = POST_ACTION |
---|
| 62 | site_name = SITE_NAME |
---|
| 63 | currency = CURRENCY |
---|
[9613] | 64 | pay_item_id = '' |
---|
[7894] | 65 | product_id = PRODUCT_ID |
---|
| 66 | |
---|
| 67 | def update(self): |
---|
[8256] | 68 | if self.context.p_state == 'paid': |
---|
[7894] | 69 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 70 | self.redirect(self.url(self.context, '@@index')) |
---|
| 71 | return |
---|
[8256] | 72 | |
---|
[8745] | 73 | student = self.student = self.context.student |
---|
| 74 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
[8276] | 75 | self.amount_auth = 100 * self.context.amount_auth |
---|
[7894] | 76 | xmldict = {} |
---|
| 77 | if certificate is not None: |
---|
| 78 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 79 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 80 | else: |
---|
| 81 | xmldict['department'] = None |
---|
| 82 | xmldict['faculty'] = None |
---|
[9406] | 83 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 84 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 85 | self.local_date_time = to_timezone( |
---|
| 86 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 87 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8263] | 88 | # Provider data |
---|
[9780] | 89 | provider_amt = 1600.0 |
---|
[8263] | 90 | xmldict['detail_ref'] = self.context.p_id |
---|
| 91 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 92 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 93 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9780] | 94 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 95 | # Institution data |
---|
[9780] | 96 | fceokene_split_amt = 1400.0 |
---|
[9613] | 97 | xmldict['fceokene_acct'] = "0000000000000" |
---|
| 98 | xmldict['institution_bank_id'] = '0' |
---|
| 99 | xmldict['institution_item_name'] = self.category |
---|
| 100 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 101 | if self.context.p_category == 'schoolfee': |
---|
| 102 | self.pay_item_id = '8302' |
---|
| 103 | if student.current_mode in ('ug_sw','prence',): |
---|
| 104 | xmldict['institution_acct'] = "6216801025" |
---|
| 105 | xmldict['institution_bank_id'] = '117' |
---|
| 106 | elif student.current_mode in ('ug_ft',) and \ |
---|
| 107 | student['studycourse'].current_verdict == 'O': |
---|
| 108 | xmldict['institution_acct'] = "6216801025" |
---|
| 109 | xmldict['institution_bank_id'] = '117' |
---|
| 110 | elif student.current_mode in ('ug_ft',): |
---|
| 111 | xmldict['institution_acct'] = "6216801033" |
---|
| 112 | xmldict['institution_bank_id'] = '117' |
---|
| 113 | elif student.current_mode in ('pd_ft',): |
---|
| 114 | xmldict['institution_acct'] = "6216801025" |
---|
| 115 | xmldict['institution_bank_id'] = '117' |
---|
[9780] | 116 | xmldict['fceokene_split'] = 100 * fceokene_split_amt |
---|
[9613] | 117 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 118 | self.context.amount_auth - provider_amt - |
---|
| 119 | GATEWAY_AMT - fceokene_split_amt) |
---|
[9613] | 120 | elif 'maintenance' in self.context.p_category: |
---|
[9780] | 121 | fceokene_split_amt = 0.0 |
---|
| 122 | provider_amt = 0.0 |
---|
[9613] | 123 | self.pay_item_id = '8300' |
---|
| 124 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 125 | self.context.amount_auth - GATEWAY_AMT) |
---|
[9613] | 126 | xmldict['institution_acct'] = "1012044132" |
---|
[9129] | 127 | xmldict['institution_bank_id'] = '117' |
---|
[8263] | 128 | # Interswitch amount is not part of the xml data |
---|
[9613] | 129 | |
---|
| 130 | if self.context.p_category == 'schoolfee': |
---|
| 131 | xmltext = """<payment_item_detail> |
---|
[8263] | 132 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 133 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
[9780] | 134 | <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="6216801058" /> |
---|
[9129] | 135 | <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
[8263] | 136 | </item_details> |
---|
| 137 | </payment_item_detail>""" % xmldict |
---|
[9613] | 138 | |
---|
| 139 | elif 'maintenance' in self.context.p_category: |
---|
| 140 | xmltext = """<payment_item_detail> |
---|
| 141 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 142 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
| 143 | </item_details> |
---|
| 144 | </payment_item_detail>""" % xmldict |
---|
| 145 | |
---|
[8263] | 146 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 147 | self.context.provider_amt = provider_amt |
---|
| 148 | self.context.gateway_amt = GATEWAY_AMT |
---|
| 149 | self.context.thirdparty_amt = fceokene_split_amt |
---|
[7894] | 150 | return |
---|
| 151 | |
---|
[8263] | 152 | class InterswitchPageApplicant(KofaPage): |
---|
[8256] | 153 | """ View which sends a POST request to the Interswitch |
---|
| 154 | CollegePAY payment gateway. |
---|
| 155 | """ |
---|
| 156 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 157 | grok.require('waeup.payApplicant') |
---|
| 158 | grok.template('applicant_goto_interswitch') |
---|
[8263] | 159 | grok.name('goto_interswitch') |
---|
| 160 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 161 | submit_button = _('Submit') |
---|
| 162 | action = POST_ACTION |
---|
| 163 | site_name = SITE_NAME |
---|
| 164 | currency = CURRENCY |
---|
[8644] | 165 | pay_item_id = '8303' |
---|
[8263] | 166 | product_id = PRODUCT_ID |
---|
[8256] | 167 | |
---|
| 168 | def update(self): |
---|
[8263] | 169 | if self.context.p_state != 'unpaid': |
---|
| 170 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 171 | self.redirect(self.url(self.context, '@@index')) |
---|
| 172 | return |
---|
[8831] | 173 | if self.context.__parent__.__parent__.expired \ |
---|
| 174 | and self.context.__parent__.__parent__.strict_deadline: |
---|
[8706] | 175 | self.flash(_("Payment ticket can't be send to CollegePAY. " |
---|
| 176 | "Application period has expired.")) |
---|
| 177 | self.redirect(self.url(self.context, '@@index')) |
---|
| 178 | return |
---|
[8256] | 179 | self.applicant = self.context.__parent__ |
---|
[8276] | 180 | self.amount_auth = 100 * self.context.amount_auth |
---|
[8256] | 181 | xmldict = {} |
---|
[9406] | 182 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
[8281] | 183 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 184 | self.local_date_time = to_timezone( |
---|
| 185 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 186 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8641] | 187 | xmldict['detail_ref'] = self.context.p_id |
---|
[8263] | 188 | # Provider data |
---|
[9780] | 189 | provider_amt = 500.0 |
---|
| 190 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 191 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 192 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 193 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 194 | # Institution data |
---|
[9780] | 195 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
---|
| 196 | provider_amt - GATEWAY_AMT) |
---|
[9108] | 197 | xmldict['institution_acct'] = '1012445289' |
---|
[8641] | 198 | xmldict['institution_bank_id'] = '117' |
---|
[8263] | 199 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 200 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 201 | # Interswitch amount is not part of the xml data |
---|
| 202 | xmltext = """<payment_item_detail> |
---|
| 203 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 204 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
| 205 | <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> |
---|
| 206 | </item_details> |
---|
| 207 | </payment_item_detail>""" % xmldict |
---|
| 208 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 209 | self.context.provider_amt = provider_amt |
---|
| 210 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 211 | return |
---|
| 212 | |
---|
[7894] | 213 | |
---|
[9784] | 214 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
| 215 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 216 | """ Request webservice view for the CollegePAY gateway |
---|
| 217 | """ |
---|
[8255] | 218 | grok.context(ICustomStudentOnlinePayment) |
---|
[9784] | 219 | product_id = PRODUCT_ID |
---|
| 220 | gateway_host = HOST |
---|
| 221 | gateway_url = URL |
---|
[7919] | 222 | |
---|
[9784] | 223 | class InterswitchPaymentRequestWebservicePageApplicant( |
---|
| 224 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[8256] | 225 | """ Request webservice view for the CollegePAY gateway |
---|
| 226 | """ |
---|
| 227 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9784] | 228 | product_id = PRODUCT_ID |
---|
| 229 | gateway_host = HOST |
---|
| 230 | gateway_url = URL |
---|