[7894] | 1 | ## $Id: browser.py 12799 2015-03-20 11:51:24Z 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 |
---|
[9784] | 20 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 21 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11635] | 22 | InterswitchPaymentRequestWebservicePageStudent, |
---|
| 23 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[9784] | 24 | ) |
---|
[8460] | 25 | from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment |
---|
| 26 | from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 27 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
[7894] | 28 | |
---|
[8644] | 29 | PRODUCT_ID = '83' |
---|
[8460] | 30 | SITE_NAME = 'fceokene-kofa.waeup.org' |
---|
[8641] | 31 | PROVIDER_ACCT = '0026781725' |
---|
| 32 | PROVIDER_BANK_ID = '31' |
---|
[8263] | 33 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[8460] | 34 | INSTITUTION_NAME = 'FCEOkene' |
---|
[7894] | 35 | CURRENCY = '566' |
---|
[9780] | 36 | GATEWAY_AMT = 150.0 |
---|
[8401] | 37 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 38 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[8385] | 39 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 40 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 41 | |
---|
[8293] | 42 | HOST = 'webpay.interswitchng.com' |
---|
| 43 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 44 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 45 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 46 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 47 | |
---|
[11635] | 48 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[7894] | 49 | """ View which sends a POST request to the Interswitch |
---|
| 50 | CollegePAY payment gateway. |
---|
| 51 | """ |
---|
[8255] | 52 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 53 | action = POST_ACTION |
---|
| 54 | site_name = SITE_NAME |
---|
| 55 | currency = CURRENCY |
---|
[9613] | 56 | pay_item_id = '' |
---|
[7894] | 57 | product_id = PRODUCT_ID |
---|
| 58 | |
---|
| 59 | def update(self): |
---|
[11649] | 60 | error = self.init_update() |
---|
| 61 | if error: |
---|
| 62 | self.flash(error, type='danger') |
---|
| 63 | self.redirect(self.url(self.context, '@@index')) |
---|
| 64 | return |
---|
| 65 | student = self.student |
---|
| 66 | xmldict = self.xmldict |
---|
[8263] | 67 | # Provider data |
---|
[9780] | 68 | provider_amt = 1600.0 |
---|
[8263] | 69 | xmldict['detail_ref'] = self.context.p_id |
---|
| 70 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 71 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 72 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9780] | 73 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 74 | # Institution data |
---|
[9780] | 75 | fceokene_split_amt = 1400.0 |
---|
[9613] | 76 | xmldict['fceokene_acct'] = "0000000000000" |
---|
| 77 | xmldict['institution_bank_id'] = '0' |
---|
| 78 | xmldict['institution_item_name'] = self.category |
---|
| 79 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[11919] | 80 | if self.context.p_category in ('schoolfee', 'third_semester'): |
---|
[9613] | 81 | self.pay_item_id = '8302' |
---|
[12799] | 82 | if student.current_mode in ('ct_ft',): |
---|
| 83 | xmldict['institution_acct'] = "1012044039" |
---|
| 84 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 85 | if student.current_mode in ('nce_sw','prence',): |
---|
[12661] | 86 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 87 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 88 | elif student.current_mode in ('nce_ft',) and \ |
---|
[9613] | 89 | student['studycourse'].current_verdict == 'O': |
---|
[12661] | 90 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 91 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 92 | elif student.current_mode in ('nce_ft',): |
---|
[12661] | 93 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 94 | xmldict['institution_bank_id'] = '117' |
---|
| 95 | elif student.current_mode in ('pd_ft',): |
---|
[12661] | 96 | xmldict['institution_acct'] = "1013780934" |
---|
[9613] | 97 | xmldict['institution_bank_id'] = '117' |
---|
[10011] | 98 | #undergraduate schoolfee added |
---|
| 99 | elif student.current_mode in ('ug_ft',): |
---|
[12662] | 100 | xmldict['institution_acct'] = "2010952698" |
---|
[10011] | 101 | xmldict['institution_bank_id'] = '8' |
---|
[9780] | 102 | xmldict['fceokene_split'] = 100 * fceokene_split_amt |
---|
[9613] | 103 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 104 | self.context.amount_auth - provider_amt - |
---|
| 105 | GATEWAY_AMT - fceokene_split_amt) |
---|
[9613] | 106 | elif 'maintenance' in self.context.p_category: |
---|
[9780] | 107 | fceokene_split_amt = 0.0 |
---|
| 108 | provider_amt = 0.0 |
---|
[9613] | 109 | self.pay_item_id = '8300' |
---|
| 110 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 111 | self.context.amount_auth - GATEWAY_AMT) |
---|
[12661] | 112 | xmldict['institution_acct'] = "1013780934" |
---|
[9129] | 113 | xmldict['institution_bank_id'] = '117' |
---|
[9956] | 114 | elif self.context.p_category == 'clearance': |
---|
| 115 | fceokene_split_amt = 0.0 |
---|
| 116 | provider_amt = 0.0 |
---|
| 117 | self.pay_item_id = '8304' |
---|
| 118 | xmldict['institution_amt'] = 100 * ( |
---|
| 119 | self.context.amount_auth - GATEWAY_AMT) |
---|
[12662] | 120 | xmldict['institution_acct'] = "2010952698" |
---|
[9956] | 121 | xmldict['institution_bank_id'] = '8' |
---|
| 122 | |
---|
[8263] | 123 | # Interswitch amount is not part of the xml data |
---|
[11919] | 124 | if self.context.p_category in ('schoolfee', 'third_semester'): |
---|
[9613] | 125 | xmltext = """<payment_item_detail> |
---|
[8263] | 126 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 127 | <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" /> |
---|
[12661] | 128 | <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1013780934" /> |
---|
[9129] | 129 | <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] | 130 | </item_details> |
---|
| 131 | </payment_item_detail>""" % xmldict |
---|
[9613] | 132 | |
---|
[9956] | 133 | else: |
---|
[9613] | 134 | xmltext = """<payment_item_detail> |
---|
| 135 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 136 | <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" /> |
---|
| 137 | </item_details> |
---|
| 138 | </payment_item_detail>""" % xmldict |
---|
| 139 | |
---|
[8263] | 140 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 141 | self.context.provider_amt = provider_amt |
---|
| 142 | self.context.gateway_amt = GATEWAY_AMT |
---|
| 143 | self.context.thirdparty_amt = fceokene_split_amt |
---|
[7894] | 144 | return |
---|
| 145 | |
---|
[11635] | 146 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 147 | """ View which sends a POST request to the Interswitch |
---|
| 148 | CollegePAY payment gateway. |
---|
| 149 | """ |
---|
| 150 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 151 | action = POST_ACTION |
---|
| 152 | site_name = SITE_NAME |
---|
| 153 | currency = CURRENCY |
---|
[8644] | 154 | pay_item_id = '8303' |
---|
[8263] | 155 | product_id = PRODUCT_ID |
---|
[8256] | 156 | |
---|
| 157 | def update(self): |
---|
[11635] | 158 | super(CustomInterswitchPageApplicant, self).update() |
---|
[8256] | 159 | xmldict = {} |
---|
[8263] | 160 | # Provider data |
---|
[9780] | 161 | provider_amt = 500.0 |
---|
[11635] | 162 | xmldict['detail_ref'] = self.context.p_id |
---|
[9780] | 163 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 164 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 165 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 166 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 167 | # Institution data |
---|
[10528] | 168 | if getattr( |
---|
| 169 | self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'): |
---|
[12662] | 170 | xmldict['institution_acct'] = '2010952698' |
---|
[10528] | 171 | xmldict['institution_bank_id'] = '8' |
---|
| 172 | else: |
---|
[12661] | 173 | xmldict['institution_acct'] = '1013780934' |
---|
[10528] | 174 | xmldict['institution_bank_id'] = '117' |
---|
[9780] | 175 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
---|
| 176 | provider_amt - GATEWAY_AMT) |
---|
[8263] | 177 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 178 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 179 | # Interswitch amount is not part of the xml data |
---|
| 180 | xmltext = """<payment_item_detail> |
---|
| 181 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 182 | <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" /> |
---|
| 183 | <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" /> |
---|
| 184 | </item_details> |
---|
| 185 | </payment_item_detail>""" % xmldict |
---|
| 186 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 187 | self.context.provider_amt = provider_amt |
---|
| 188 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 189 | return |
---|
| 190 | |
---|
[7894] | 191 | |
---|
[11635] | 192 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9784] | 193 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 194 | """ Request webservice view for the CollegePAY gateway |
---|
| 195 | """ |
---|
[8255] | 196 | grok.context(ICustomStudentOnlinePayment) |
---|
[9784] | 197 | product_id = PRODUCT_ID |
---|
| 198 | gateway_host = HOST |
---|
| 199 | gateway_url = URL |
---|
[7919] | 200 | |
---|
[11635] | 201 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9784] | 202 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[8256] | 203 | """ Request webservice view for the CollegePAY gateway |
---|
| 204 | """ |
---|
| 205 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9784] | 206 | product_id = PRODUCT_ID |
---|
| 207 | gateway_host = HOST |
---|
| 208 | gateway_url = URL |
---|