[10765] | 1 | ## $Id: browser.py 14859 2017-10-05 07:15:22Z 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 | ## |
---|
| 18 | import httplib |
---|
[12479] | 19 | import hashlib |
---|
[10765] | 20 | import grok |
---|
| 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
[11638] | 23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
[13587] | 24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
| 25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
[11638] | 26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
[10765] | 27 | ) |
---|
[14716] | 28 | from kofacustom.dspg.students.interfaces import ICustomStudentOnlinePayment |
---|
| 29 | from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 30 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
[10765] | 31 | |
---|
[14726] | 32 | PRODUCT_ID = '7269' # must be provided by Interswitch |
---|
[14749] | 33 | SITE_NAME = 'dspg.waeup.org' |
---|
[14819] | 34 | PROVIDER_ACCT = '1014261520' |
---|
| 35 | PROVIDER_BANK_ID = '117' |
---|
[10765] | 36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[14722] | 37 | INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku' |
---|
[10765] | 38 | CURRENCY = '566' |
---|
[14727] | 39 | GATEWAY_AMT = 250.0 |
---|
[10765] | 40 | |
---|
[14726] | 41 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
| 42 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
| 43 | HOST = 'webpay.interswitchng.com' |
---|
| 44 | #HOST = 'sandbox.interswitchng.com' |
---|
| 45 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
| 46 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
[14276] | 47 | |
---|
[12479] | 48 | httplib.HTTPSConnection.debuglevel = 0 |
---|
| 49 | HTTPS = True |
---|
[10765] | 50 | |
---|
[14859] | 51 | SPECIAL_PAYMENT_PARAMS = { |
---|
| 52 | 'certificate': ('111', 500.0, '1012808851', '117'), |
---|
| 53 | 'state_result': ('112', 500.0, '1012808851', '117'), |
---|
| 54 | 'transcript_local': ('113', 500.0, '1012808851', '117'), |
---|
| 55 | 'transcript_foreign': ('114', 500.0, '1012808851', '117'), |
---|
| 56 | 'ver_result': ('115', 500.0, '1012808851', '117'), |
---|
| 57 | 'change_course': ('116', 500.0, '1012808851', '117'), |
---|
| 58 | 'change_inst': ('117', 500.0, '1012808851', '117'), |
---|
| 59 | 'jamb_reject': ('118', 500.0, '1012808851', '117'), |
---|
| 60 | 'cert_of_cert': ('119', 500.0, '1012808851', '117'), |
---|
| 61 | 'ref_let': ('120', 500.0, '1012808851', '117'), |
---|
| 62 | 'proc_cert': ('121', 500.0, '1012808851', '117'), |
---|
| 63 | 'loss_idcard': ('122', 9.0, '1012808851', '117'), |
---|
| 64 | 'loss_examcard': ('123', 4.5, '1012808851', '117'), |
---|
| 65 | 'loss_result': ('124', 500.0, '1012808851', '117'), |
---|
| 66 | 'loss_receipt': ('125', 500.0, '1012808851', '117'), |
---|
| 67 | 'loss_clearance': ('126', 500.0, '1012808851', '117'), |
---|
| 68 | 'conv_brochure': ('127', 500.0, '1012808851', '117'), |
---|
| 69 | 'hnd_certificate': ('128', 500.0, '1012808851', '117'), |
---|
| 70 | 'hnd_state_result': ('129', 500.0, '1012808851', '117'), |
---|
| 71 | 'hnd_transcript_local': ('130', 500.0, '1012808851', '117'), |
---|
| 72 | 'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'), |
---|
| 73 | 'staff_loss_idcard': ('132', 9.0, '1012808851', '117'), |
---|
| 74 | 'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'), |
---|
| 75 | 'pgd_state_result': ('134', 500.0, '1012808851', '117'), |
---|
| 76 | 'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'), |
---|
| 77 | 'pgd_certificate': ('136', 500.0, '1012808851', '117'), |
---|
| 78 | 'log_book': ('137', 4.5, '1012808851', '117'), |
---|
| 79 | 'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'), |
---|
| 80 | 'pgd_transcript_local': ('139', 500.0, '1012808851', '117'), |
---|
| 81 | 'jamb_regularization': ('140', 500.0, '1012808851', '117'), |
---|
| 82 | 'utme_registration': ('142', 9.0, '1012808851', '117'), |
---|
| 83 | 'utme_cbt': ('143', 9.0, '1012808851', '117'), |
---|
| 84 | 'nysc_id_card': ('144', 9.0, '1012808851', '117'), |
---|
| 85 | 'ijmb_result': ('147', 500.0, '1012808851', '117'), |
---|
| 86 | } |
---|
| 87 | |
---|
[11638] | 88 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
[10765] | 89 | """ View which sends a POST request to the Interswitch |
---|
| 90 | CollegePAY payment gateway. |
---|
| 91 | """ |
---|
| 92 | grok.context(ICustomStudentOnlinePayment) |
---|
| 93 | action = POST_ACTION |
---|
| 94 | site_name = SITE_NAME |
---|
| 95 | currency = CURRENCY |
---|
| 96 | product_id = PRODUCT_ID |
---|
[14276] | 97 | mac = '' # must be provided by Interswitch |
---|
[10765] | 98 | |
---|
| 99 | def update(self): |
---|
[12979] | 100 | error = self.init_update() |
---|
| 101 | if error: |
---|
| 102 | self.flash(error, type='danger') |
---|
| 103 | self.redirect(self.url(self.context, '@@index')) |
---|
| 104 | return |
---|
[11647] | 105 | student = self.student |
---|
| 106 | xmldict = self.xmldict |
---|
[10765] | 107 | # Provider data |
---|
| 108 | xmldict['detail_ref'] = self.context.p_id |
---|
| 109 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 110 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 111 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 112 | # Institution data |
---|
| 113 | xmldict['institution_acct'] = '00000000' |
---|
| 114 | xmldict['institution_bank_id'] = '00' |
---|
| 115 | xmldict['institution_amt'] = '0.0' |
---|
[14810] | 116 | provider_amt = 500.0 |
---|
[14276] | 117 | self.pay_item_id = '0000' # must be provided by Interswitch |
---|
[10765] | 118 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[12511] | 119 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 120 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 121 | xmldict['institution_amt'] = 100 * ( |
---|
| 122 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
| 123 | # Interswitch amount is not part of the xml data |
---|
| 124 | if provider_amt == 0: |
---|
| 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" /> |
---|
| 128 | </item_details> |
---|
| 129 | </payment_item_detail>""" % xmldict |
---|
| 130 | else: |
---|
| 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_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" /> |
---|
| 135 | </item_details> |
---|
| 136 | </payment_item_detail>""" % xmldict |
---|
| 137 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 138 | self.context.provider_amt = provider_amt |
---|
| 139 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 140 | |
---|
| 141 | hashargs = ( |
---|
| 142 | self.context.p_id + |
---|
| 143 | PRODUCT_ID + |
---|
| 144 | self.pay_item_id + |
---|
| 145 | str(int(self.amount_auth)) + |
---|
| 146 | self.site_redirect_url + |
---|
| 147 | self.mac) |
---|
| 148 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 149 | return |
---|
| 150 | |
---|
[11638] | 151 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
[10765] | 152 | """ View which sends a POST request to the Interswitch |
---|
| 153 | CollegePAY payment gateway. |
---|
| 154 | """ |
---|
| 155 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 156 | action = POST_ACTION |
---|
| 157 | site_name = SITE_NAME |
---|
| 158 | currency = CURRENCY |
---|
[14729] | 159 | pay_item_id = '101' # must be provided by Interswitch |
---|
[10765] | 160 | product_id = PRODUCT_ID |
---|
[14730] | 161 | mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627' |
---|
[10765] | 162 | |
---|
| 163 | def update(self): |
---|
[12979] | 164 | error = self.init_update() |
---|
| 165 | if error: |
---|
| 166 | self.flash(error, type='danger') |
---|
| 167 | self.redirect(self.url(self.context, '@@index')) |
---|
| 168 | return |
---|
[10765] | 169 | xmldict = {} |
---|
[14731] | 170 | provider_amt = 500.0 |
---|
[14859] | 171 | gateway_amt = GATEWAY_AMT |
---|
[14810] | 172 | xmldict['institution_acct'] = '00000000' |
---|
| 173 | xmldict['institution_bank_id'] = '00' |
---|
| 174 | if self.applicant.__parent__.application_category in ('ndft', 'hndft'): |
---|
| 175 | xmldict['institution_acct'] = '0010761873' |
---|
[14815] | 176 | xmldict['institution_bank_id'] = '11' |
---|
[14810] | 177 | elif self.applicant.__parent__.application_category in ( |
---|
| 178 | 'ndpt', 'hndpt', 'ndwe', 'hndwe'): |
---|
| 179 | xmldict['institution_acct'] = '1015220292' |
---|
| 180 | xmldict['institution_bank_id'] = '117' |
---|
[14859] | 181 | elif self.applicant.applicant_id.startswith('special'): |
---|
| 182 | if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): |
---|
| 183 | self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] |
---|
| 184 | provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] |
---|
| 185 | xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] |
---|
| 186 | xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] |
---|
| 187 | if self.pay_item_id in ('122', '123', '132', '137', '141', |
---|
| 188 | '142', '143', '144', '146', '147',): |
---|
| 189 | gateway_amt = round(0.015 * self.context.amount_auth, 2) |
---|
[10765] | 190 | xmldict['detail_ref'] = self.context.p_id |
---|
| 191 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 192 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 193 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 194 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[14859] | 195 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - gateway_amt) |
---|
[12511] | 196 | xmldict['institution_item_name'] = self.context.category |
---|
[10765] | 197 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 198 | # Interswitch amount is not part of the xml data |
---|
| 199 | xmltext = """<payment_item_detail> |
---|
| 200 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
| 201 | <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" /> |
---|
| 202 | <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" /> |
---|
| 203 | </item_details> |
---|
| 204 | </payment_item_detail>""" % xmldict |
---|
| 205 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 206 | self.context.provider_amt = provider_amt |
---|
| 207 | self.context.gateway_amt = GATEWAY_AMT |
---|
[12479] | 208 | |
---|
| 209 | hashargs = ( |
---|
| 210 | self.context.p_id + |
---|
| 211 | PRODUCT_ID + |
---|
| 212 | self.pay_item_id + |
---|
| 213 | str(int(self.amount_auth)) + |
---|
| 214 | self.site_redirect_url + |
---|
| 215 | self.mac) |
---|
| 216 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10765] | 217 | return |
---|
| 218 | |
---|
[11638] | 219 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
[10765] | 220 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[13587] | 221 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 222 | """ |
---|
| 223 | grok.context(ICustomStudentOnlinePayment) |
---|
| 224 | product_id = PRODUCT_ID |
---|
| 225 | gateway_host = HOST |
---|
| 226 | gateway_url = URL |
---|
| 227 | |
---|
[13587] | 228 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
| 229 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
| 230 | """Payment verify view for the CollegePAY gateway |
---|
| 231 | """ |
---|
| 232 | grok.context(ICustomStudentOnlinePayment) |
---|
| 233 | product_id = PRODUCT_ID |
---|
| 234 | gateway_host = HOST |
---|
| 235 | gateway_url = URL |
---|
| 236 | |
---|
[11638] | 237 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
[10765] | 238 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
[13587] | 239 | """Request webservice view for the CollegePAY gateway |
---|
[10765] | 240 | """ |
---|
| 241 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 242 | product_id = PRODUCT_ID |
---|
| 243 | gateway_host = HOST |
---|
[12479] | 244 | gateway_url = URL |
---|
[14730] | 245 | mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627' |
---|
[13587] | 246 | |
---|
| 247 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
| 248 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
| 249 | """Payment verify view for the CollegePAY gateway |
---|
| 250 | """ |
---|
| 251 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 252 | product_id = PRODUCT_ID |
---|
| 253 | gateway_host = HOST |
---|
[14722] | 254 | gateway_url = URL |
---|
[14730] | 255 | mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627' |
---|