[7894] | 1 | ## $Id: browser.py 11633 2014-05-13 07:53:40Z 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 |
---|
[9782] | 20 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 21 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11633] | 22 | InterswitchPaymentRequestWebservicePageStudent, |
---|
| 23 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[9782] | 24 | ) |
---|
[8263] | 25 | from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment |
---|
| 26 | from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
[8020] | 27 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7894] | 28 | |
---|
| 29 | PRODUCT_ID = '57' |
---|
[8263] | 30 | SITE_NAME = 'uniben-kofa.waeup.org' |
---|
[8424] | 31 | PROVIDER_ACCT = '1010764827' |
---|
| 32 | PROVIDER_BANK_ID = '117' |
---|
[8263] | 33 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
| 34 | INSTITUTION_NAME = 'Uniben' |
---|
[7894] | 35 | CURRENCY = '566' |
---|
[9775] | 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 | |
---|
[11633] | 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 |
---|
| 56 | product_id = PRODUCT_ID |
---|
| 57 | |
---|
| 58 | def update(self): |
---|
[11633] | 59 | student, certificate, xmldict = super( |
---|
| 60 | CustomInterswitchPageStudent, self).update() |
---|
[8263] | 61 | # Provider data |
---|
| 62 | xmldict['detail_ref'] = self.context.p_id |
---|
| 63 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 64 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 65 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 66 | # Institution data |
---|
[9385] | 67 | xmldict['institution_acct'] = '000000000000' |
---|
| 68 | xmldict['institution_bank_id'] = '00' |
---|
[9384] | 69 | xmldict['institution_amt'] = '0.0' |
---|
[9869] | 70 | provider_amt = 0.0 |
---|
| 71 | self.pay_item_id = '0000' |
---|
[9384] | 72 | if self.context.p_category == 'schoolfee': |
---|
[9869] | 73 | if not self.context.p_item == 'Balance': |
---|
| 74 | provider_amt = 1500.0 |
---|
[9384] | 75 | if student.current_mode.endswith('_ft'): |
---|
[9389] | 76 | self.pay_item_id = '5700' |
---|
[11478] | 77 | if student.current_mode in ('ug_ft','de_ft','ume_ft'): |
---|
[9460] | 78 | xmldict['institution_acct'] = '2017506430' |
---|
| 79 | xmldict['institution_bank_id'] = '8' |
---|
[11478] | 80 | elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'): |
---|
| 81 | xmldict['institution_acct'] = '0009598853' |
---|
[9460] | 82 | xmldict['institution_bank_id'] = '17' |
---|
| 83 | elif student.current_mode in ('pg_ft'): |
---|
[11478] | 84 | xmldict['institution_acct'] = '6230033428' |
---|
[9384] | 85 | xmldict['institution_bank_id'] = '51' |
---|
| 86 | elif student.current_mode.endswith('_pt'): |
---|
[9389] | 87 | self.pay_item_id = '5701' |
---|
[11478] | 88 | if student.current_mode in ('ug_pt','de_pt'): |
---|
[9460] | 89 | xmldict['institution_acct'] = '0122009929' |
---|
[9384] | 90 | xmldict['institution_bank_id'] = '16' |
---|
[9460] | 91 | elif student.current_mode in ('pg_pt'): |
---|
[11478] | 92 | xmldict['institution_acct'] = '1013766956' |
---|
| 93 | xmldict['institution_bank_id'] = '117' |
---|
[9384] | 94 | elif self.context.p_category == 'clearance': |
---|
[9389] | 95 | self.pay_item_id = '5702' |
---|
[9775] | 96 | provider_amt = 1500.0 |
---|
[9796] | 97 | if student.faccode == 'FCETA': |
---|
| 98 | xmldict['institution_acct'] = '5210007943' |
---|
| 99 | xmldict['institution_bank_id'] = '51' |
---|
[11478] | 100 | else: |
---|
| 101 | xmldict['institution_bank_id'] = '10' |
---|
[9742] | 102 | xmldict['institution_acct'] = '0031716047' |
---|
[9727] | 103 | elif self.context.p_category == 'gown': |
---|
[9515] | 104 | self.pay_item_id = '5704' |
---|
[11478] | 105 | xmldict['institution_bank_id'] = '16' |
---|
| 106 | xmldict['institution_acct'] = '0122011401' |
---|
[9727] | 107 | elif self.context.p_category.startswith('hostel_maintenance'): |
---|
| 108 | self.pay_item_id = '5705' |
---|
[11478] | 109 | xmldict['institution_bank_id'] = '17' |
---|
| 110 | xmldict['institution_acct'] = '0009598925' |
---|
[9384] | 111 | |
---|
| 112 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 113 | xmldict['institution_item_name'] = self.category |
---|
[8263] | 114 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9384] | 115 | xmldict['institution_amt'] = 100 * ( |
---|
[9775] | 116 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[8263] | 117 | # Interswitch amount is not part of the xml data |
---|
[9515] | 118 | if provider_amt == 0: |
---|
| 119 | xmltext = """<payment_item_detail> |
---|
[8263] | 120 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 121 | <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" /> |
---|
[9515] | 122 | </item_details> |
---|
| 123 | </payment_item_detail>""" % xmldict |
---|
| 124 | else: |
---|
| 125 | xmltext = """<payment_item_detail> |
---|
| 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" /> |
---|
[8263] | 128 | <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" /> |
---|
| 129 | </item_details> |
---|
| 130 | </payment_item_detail>""" % xmldict |
---|
| 131 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 132 | self.context.provider_amt = provider_amt |
---|
| 133 | self.context.gateway_amt = GATEWAY_AMT |
---|
[7894] | 134 | return |
---|
| 135 | |
---|
[11633] | 136 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[8256] | 137 | """ View which sends a POST request to the Interswitch |
---|
| 138 | CollegePAY payment gateway. |
---|
| 139 | """ |
---|
| 140 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 141 | action = POST_ACTION |
---|
| 142 | site_name = SITE_NAME |
---|
| 143 | currency = CURRENCY |
---|
[8274] | 144 | pay_item_id = '5703' |
---|
[8263] | 145 | product_id = PRODUCT_ID |
---|
[8256] | 146 | |
---|
| 147 | def update(self): |
---|
[11633] | 148 | super(CustomInterswitchPageApplicant, self).update() |
---|
[8256] | 149 | xmldict = {} |
---|
[9775] | 150 | provider_amt = 400.0 |
---|
[8545] | 151 | if self.applicant.applicant_id.startswith('pg'): |
---|
[8568] | 152 | xmldict['institution_acct'] = '0031716030' |
---|
| 153 | xmldict['institution_bank_id'] = '10' |
---|
[9636] | 154 | elif self.applicant.applicant_id.startswith('dp'): |
---|
| 155 | xmldict['institution_acct'] = '9201805071' |
---|
| 156 | xmldict['institution_bank_id'] = '17' |
---|
[10741] | 157 | elif self.applicant.applicant_id.startswith('pt'): |
---|
| 158 | xmldict['institution_acct'] = '9201805071' |
---|
| 159 | xmldict['institution_bank_id'] = '17' |
---|
[8545] | 160 | else: |
---|
[8568] | 161 | xmldict['institution_acct'] = '6220032503' |
---|
| 162 | xmldict['institution_bank_id'] = '51' |
---|
[8263] | 163 | xmldict['detail_ref'] = self.context.p_id |
---|
[8545] | 164 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[8263] | 165 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 166 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 167 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9775] | 168 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[8263] | 169 | xmldict['institution_item_name'] = self.context.p_category |
---|
| 170 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 171 | # Interswitch amount is not part of the xml data |
---|
| 172 | xmltext = """<payment_item_detail> |
---|
| 173 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 174 | <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" /> |
---|
| 175 | <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" /> |
---|
| 176 | </item_details> |
---|
| 177 | </payment_item_detail>""" % xmldict |
---|
| 178 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9775] | 179 | self.context.provider_amt = provider_amt |
---|
| 180 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 181 | return |
---|
| 182 | |
---|
[11633] | 183 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[9782] | 184 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 185 | """ Request webservice view for the CollegePAY gateway |
---|
| 186 | """ |
---|
[8255] | 187 | grok.context(ICustomStudentOnlinePayment) |
---|
[9782] | 188 | product_id = PRODUCT_ID |
---|
| 189 | gateway_host = HOST |
---|
| 190 | gateway_url = URL |
---|
[7919] | 191 | |
---|
[11633] | 192 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[9782] | 193 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[8256] | 194 | """ Request webservice view for the CollegePAY gateway |
---|
| 195 | """ |
---|
| 196 | grok.context(ICustomApplicantOnlinePayment) |
---|
[9782] | 197 | product_id = PRODUCT_ID |
---|
| 198 | gateway_host = HOST |
---|
[11478] | 199 | gateway_url = URL |
---|