Changeset 16487 for main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/paydirectbrowser.py
- Timestamp:
- 20 May 2021, 10:54:17 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/paydirectbrowser.py
r16484 r16487 21 21 from zope.component import getUtility 22 22 from zope.security import checkPermission 23 from xml.dom.minidom import parseString 23 24 from waeup.kofa.interfaces import IKofaUtils 24 25 from waeup.kofa.utils.helpers import to_timezone … … 29 30 from waeup.kofa.students.browser import StudentBasePDFFormPage 30 31 from waeup.kofa.applicants.browser import OnlinePaymentDisplayFormPage as OPDPApplicant 32 from waeup.kofa.applicants.browser import ApplicantBaseDisplayFormPage 31 33 from kofacustom.nigeria.interswitch.helpers import ( 32 query_interswitch, write_payments_log, fetch_booking_details) 34 query_interswitch, write_payments_log, 35 fetch_booking_details, create_paydirect_booking) 33 36 from kofacustom.nigeria.payments.interfaces import INigeriaOnlinePayment 34 37 from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment 35 38 from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment 36 from kofacustom.nigeria.interswitch.tests import PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID 39 from kofacustom.nigeria.interswitch.tests import ( 40 PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) 37 41 from kofacustom.nigeria.interfaces import MessageFactory as _ 38 42 … … 106 110 if self.context.r_company and self.context.r_company != 'interswitch': 107 111 return _("Payment ticket has been used for another payment gateway.") 108 tz = getUtility(IKofaUtils).tzinfo109 time_delta = datetime.utcnow() - self.context.creation_date110 if time_delta.days > 7:111 return _("This payment ticket is too old. Please create a new ticket.")112 112 self.ref_number = self.merchant_id + self.context.p_id[1:] 113 # Create a PAYDirect Booking 114 if not self.context.r_company: 115 result_xml = create_paydirect_booking( 116 self.merchant_id, self.context, self.gateway_host, 117 self.gateway_url, True) 118 if result_xml.startswith('Connection error'): 119 return result_xml 120 doc=parseString(result_xml) 121 if not doc.getElementsByTagName('ResponseCode'): 122 return _('Invalid callback from Interswitch') 123 rc = doc.getElementsByTagName('ResponseCode')[0].firstChild.data 124 if rc != '100': 125 return 'Error response code from Interswitch: %s' % rc 113 126 return 114 127 … … 198 211 return 199 212 200 class PaymentRefNumberSlipActionButton(ManageActionButton):201 grok.order(1) # This button should always be the last one.202 grok.context(INigeria OnlinePayment)213 class StudentPaymentRefNumberSlipActionButton(ManageActionButton): 214 grok.order(1) 215 grok.context(INigeriaStudentOnlinePayment) 203 216 grok.view(PAYDirectPageStudent) 204 217 grok.require('waeup.viewStudent') … … 213 226 return self.view.url(self.view.context, self.target) 214 227 215 class RefNumberSlipStudent(UtilityView, grok.View): 228 class ApplicantPaymentRefNumberSlipActionButton(StudentPaymentRefNumberSlipActionButton): 229 grok.context(INigeriaApplicantOnlinePayment) 230 grok.view(PAYDirectPageApplicant) 231 grok.require('waeup.viewApplication') 232 233 class StudentRefNumberSlip(UtilityView, grok.View): 216 234 """Deliver a PDF slip of the context. 217 235 """ 218 grok.context(INigeria OnlinePayment)236 grok.context(INigeriaStudentOnlinePayment) 219 237 grok.name('refnumberslip.pdf') 220 238 grok.require('waeup.viewStudent') … … 256 274 self.context.student, studentview, note=self.note, 257 275 omit_fields=self.omit_fields) 276 277 class ApplicantRefNumberSlip(StudentRefNumberSlip): 278 """Deliver a PDF slip of the context. 279 """ 280 grok.context(INigeriaApplicantOnlinePayment) 281 grok.require('waeup.viewApplication') 282 283 @property 284 def note(self): 285 return """<br /><br /> 286 Go to your bank and make your PAYDirect payment with the reference number <strong>%s</strong>. 287 """ % self.refnumber 288 def render(self): 289 if self.context.p_state == 'paid': 290 self.flash('Payment has already been made.') 291 self.redirect(self.url(self.context)) 292 return 293 applicantview = ApplicantBaseDisplayFormPage(self.context.__parent__, 294 self.request) 295 students_utils = getUtility(IStudentsUtils) 296 return students_utils.renderPDF(self, 'refnumberslip.pdf', 297 self.context.__parent__, applicantview, note=self.note, 298 omit_fields=self.omit_fields)
Note: See TracChangeset for help on using the changeset viewer.