[7894] | 1 | ## $Id: browser.py 11919 2014-10-30 21:20:11Z 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' |
---|
[9943] | 82 | if student.current_mode in ('nce_sw','prence',): |
---|
[9951] | 83 | xmldict['institution_acct'] = "1012044194" |
---|
[9613] | 84 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 85 | elif student.current_mode in ('nce_ft',) and \ |
---|
[9613] | 86 | student['studycourse'].current_verdict == 'O': |
---|
[9951] | 87 | xmldict['institution_acct'] = "1012044015" |
---|
[9613] | 88 | xmldict['institution_bank_id'] = '117' |
---|
[9943] | 89 | elif student.current_mode in ('nce_ft',): |
---|
[9951] | 90 | xmldict['institution_acct'] = "1012044015" |
---|
[9613] | 91 | xmldict['institution_bank_id'] = '117' |
---|
| 92 | elif student.current_mode in ('pd_ft',): |
---|
[9951] | 93 | xmldict['institution_acct'] = "1012415659" |
---|
[9613] | 94 | xmldict['institution_bank_id'] = '117' |
---|
[10011] | 95 | #undergraduate schoolfee added |
---|
| 96 | elif student.current_mode in ('ug_ft',): |
---|
| 97 | xmldict['institution_acct'] = "2003670143" |
---|
| 98 | xmldict['institution_bank_id'] = '8' |
---|
[9780] | 99 | xmldict['fceokene_split'] = 100 * fceokene_split_amt |
---|
[9613] | 100 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 101 | self.context.amount_auth - provider_amt - |
---|
| 102 | GATEWAY_AMT - fceokene_split_amt) |
---|
[9613] | 103 | elif 'maintenance' in self.context.p_category: |
---|
[9780] | 104 | fceokene_split_amt = 0.0 |
---|
| 105 | provider_amt = 0.0 |
---|
[9613] | 106 | self.pay_item_id = '8300' |
---|
| 107 | xmldict['institution_amt'] = 100 * ( |
---|
[9780] | 108 | self.context.amount_auth - GATEWAY_AMT) |
---|
[9613] | 109 | xmldict['institution_acct'] = "1012044132" |
---|
[9129] | 110 | xmldict['institution_bank_id'] = '117' |
---|
[9956] | 111 | elif self.context.p_category == 'clearance': |
---|
| 112 | fceokene_split_amt = 0.0 |
---|
| 113 | provider_amt = 0.0 |
---|
| 114 | self.pay_item_id = '8304' |
---|
| 115 | xmldict['institution_amt'] = 100 * ( |
---|
| 116 | self.context.amount_auth - GATEWAY_AMT) |
---|
| 117 | xmldict['institution_acct'] = "2003670143" |
---|
| 118 | xmldict['institution_bank_id'] = '8' |
---|
| 119 | |
---|
[8263] | 120 | # Interswitch amount is not part of the xml data |
---|
[11919] | 121 | if self.context.p_category in ('schoolfee', 'third_semester'): |
---|
[9613] | 122 | xmltext = """<payment_item_detail> |
---|
[8263] | 123 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 124 | <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" /> |
---|
[9951] | 125 | <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1012044039" /> |
---|
[9129] | 126 | <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] | 127 | </item_details> |
---|
| 128 | </payment_item_detail>""" % xmldict |
---|
[9613] | 129 | |
---|
[9956] | 130 | else: |
---|
[9613] | 131 | xmltext = """<payment_item_detail> |
---|
| 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" /> |
---|
| 134 | </item_details> |
---|
| 135 | </payment_item_detail>""" % xmldict |
---|
| 136 | |
---|
[8263] | 137 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 138 | self.context.provider_amt = provider_amt |
---|
| 139 | self.context.gateway_amt = GATEWAY_AMT |
---|
| 140 | self.context.thirdparty_amt = fceokene_split_amt |
---|
[7894] | 141 | return |
---|
| 142 | |
---|
[11635] | 143 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 144 | """ View which sends a POST request to the Interswitch |
---|
| 145 | CollegePAY payment gateway. |
---|
| 146 | """ |
---|
| 147 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 148 | action = POST_ACTION |
---|
| 149 | site_name = SITE_NAME |
---|
| 150 | currency = CURRENCY |
---|
[8644] | 151 | pay_item_id = '8303' |
---|
[8263] | 152 | product_id = PRODUCT_ID |
---|
[8256] | 153 | |
---|
| 154 | def update(self): |
---|
[11635] | 155 | super(CustomInterswitchPageApplicant, self).update() |
---|
[8256] | 156 | xmldict = {} |
---|
[8263] | 157 | # Provider data |
---|
[9780] | 158 | provider_amt = 500.0 |
---|
[11635] | 159 | xmldict['detail_ref'] = self.context.p_id |
---|
[9780] | 160 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 161 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 162 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 163 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 164 | # Institution data |
---|
[10528] | 165 | if getattr( |
---|
| 166 | self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'): |
---|
| 167 | xmldict['institution_acct'] = '2003670143' |
---|
| 168 | xmldict['institution_bank_id'] = '8' |
---|
| 169 | else: |
---|
| 170 | xmldict['institution_acct'] = '1012445289' |
---|
| 171 | xmldict['institution_bank_id'] = '117' |
---|
[9780] | 172 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - |
---|
| 173 | provider_amt - GATEWAY_AMT) |
---|
[8263] | 174 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 175 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 176 | # Interswitch amount is not part of the xml data |
---|
| 177 | xmltext = """<payment_item_detail> |
---|
| 178 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 179 | <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" /> |
---|
| 180 | <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" /> |
---|
| 181 | </item_details> |
---|
| 182 | </payment_item_detail>""" % xmldict |
---|
| 183 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9780] | 184 | self.context.provider_amt = provider_amt |
---|
| 185 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 186 | return |
---|
| 187 | |
---|
[7894] | 188 | |
---|
[11635] | 189 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9784] | 190 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 191 | """ Request webservice view for the CollegePAY gateway |
---|
| 192 | """ |
---|
[8255] | 193 | grok.context(ICustomStudentOnlinePayment) |
---|
[9784] | 194 | product_id = PRODUCT_ID |
---|
| 195 | gateway_host = HOST |
---|
| 196 | gateway_url = URL |
---|
[7919] | 197 | |
---|
[11635] | 198 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9784] | 199 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[8256] | 200 | """ Request webservice view for the CollegePAY gateway |
---|
| 201 | """ |
---|
| 202 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9784] | 203 | product_id = PRODUCT_ID |
---|
| 204 | gateway_host = HOST |
---|
| 205 | gateway_url = URL |
---|