Changeset 16487 for main/kofacustom.nigeria/trunk
- Timestamp:
- 20 May 2021, 10:54:17 (3 years ago)
- Location:
- main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/helpers.py
r16484 r16487 26 26 from xml.dom.minidom import parseString 27 27 from zope.event import notify 28 from waeup.kofa.payments.interfaces import IPayer 28 29 from kofacustom.nigeria.interfaces import MessageFactory as _ 29 30 … … 236 237 # PAYDirect helper functions 237 238 239 def create_paydirect_booking(merchant_id, payment, host, url, https): 240 p_id = payment.p_id 241 description = payment.p_category 242 amount = int(payment.amount_auth) 243 date_booked = payment.creation_date.strftime("%Y-%m-%d") 244 date_expired = "2099-12-31" 245 firstname = IPayer(payment).display_fullname.split()[0] 246 lastname = IPayer(payment).display_fullname.split()[-1] 247 id = IPayer(payment).id 248 email = IPayer(payment).email 249 250 xml="""\ 251 <?xml version="1.0" encoding="utf-8"?> 252 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 253 <soap:Body> 254 <CreateBooking xmlns="http://interswitchng.com/bookonhold"> 255 <ReservationRequest> 256 <MerchantId>%s</MerchantId> 257 <Bookings> 258 <Booking> 259 <ReferenceNumber>%s%s</ReferenceNumber> 260 <Description>%s</Description> 261 <Amount>%s</Amount> 262 <DateBooked>%s</DateBooked> 263 <DateExpired>%s</DateExpired> 264 <FirstName>%s</FirstName> 265 <LastName>%s</LastName> 266 <Email>%s</Email> 267 <ItemCode>%s</ItemCode> 268 </Booking> 269 </Bookings> 270 </ReservationRequest> 271 </CreateBooking> 272 </soap:Body> 273 </soap:Envelope>""" % ( 274 merchant_id, merchant_id, p_id[1:], 275 description, amount, 276 date_booked, date_expired, 277 firstname, lastname, 278 email, p_id) 279 response=SOAP_post( 280 "http://interswitchng.com/bookonhold/CreateBooking", 281 xml, host, url, https) 282 if response.status!=200: 283 error = 'Connection error (%s, %s)' % (response.status, response.reason) 284 return error 285 result_xml = response.read() 286 return result_xml 287 238 288 def get_SOAP_response_paydirect(merchant_id, p_id, host, url, https): 239 289 xml="""\ -
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) -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/tests.py
r16484 r16487 17 17 ## 18 18 import os 19 import random 19 20 from datetime import datetime, timedelta, date 20 21 from zope.component import createObject, getUtility … … 28 29 from waeup.kofa.browser.tests.test_pdf import samples_dir 29 30 from kofacustom.nigeria.interswitch.helpers import ( 30 query_interswitch, get_SOAP_response_paydirect, SOAP_post) 31 query_interswitch, get_SOAP_response_paydirect, SOAP_post, 32 create_paydirect_booking 33 ) 31 34 from kofacustom.nigeria.testing import FunctionalLayer 32 35 … … 227 230 # PAYDirect tests 228 231 229 def create_booking(self, p_id):230 xml="""\231 <?xml version="1.0" encoding="utf-8"?>232 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">233 <soap:Body>234 <CreateBooking xmlns="http://interswitchng.com/bookonhold">235 <ReservationRequest>236 <MerchantId>%s</MerchantId>237 <Bookings>238 <Booking>239 <ReferenceNumber>%s%s</ReferenceNumber>240 <ResponseCode>01</ResponseCode>241 <ResponseDescription>02</ResponseDescription>242 <Description>My Description</Description>243 <Amount>1000</Amount>244 <DateBooked>2021-05-05</DateBooked>245 <DateExpired>2025-05-05</DateExpired>246 <FirstName>Dummy</FirstName>247 <LastName>Student</LastName>248 <Status>string</Status>249 <PaymentStatus>string</PaymentStatus>250 <PaymentReference>string</PaymentReference>251 <ChannelName>04</ChannelName>252 <TerminalId>05</TerminalId>253 <Location>string</Location>254 <PaymentDate>2020-05-05</PaymentDate>255 <PaymentMethod>string</PaymentMethod>256 <Email>aa@aa.aa</Email>257 <ItemCode>01</ItemCode>258 </Booking>259 </Bookings>260 </ReservationRequest>261 </CreateBooking>262 </soap:Body>263 </soap:Envelope>""" % (MERCHANT_ID, MERCHANT_ID, p_id[1:])264 265 SOAP_post("http://interswitchng.com/bookonhold/CreateBooking",xml,266 PAYDIRECT_HOST, PAYDIRECT_URL, True)267 268 232 @external_test_2 269 def test_get_SOAP_response_paydirect(self): 270 p_id = 'p6021570467807' 271 self.create_booking(p_id) 233 def test_SOAP_paydirect(self): 234 payment = createObject('waeup.StudentOnlinePayment') 235 payment.p_category = u'schoolfee' 236 payment.p_session = self.student.current_session 237 payment.p_item = u'My Certificate' 238 payment.p_id = u'p1234' 239 payment.p_id = 'p' + str(random.randint(10000000000, 90000000000)) 240 payment.amount_auth = 1000.0 241 self.student['payments'][payment.p_id] = payment 242 result_xml = create_paydirect_booking( 243 MERCHANT_ID, payment, PAYDIRECT_HOST, PAYDIRECT_URL, True) 272 244 result_xml = get_SOAP_response_paydirect( 273 MERCHANT_ID, p _id, PAYDIRECT_HOST, PAYDIRECT_URL, True)245 MERCHANT_ID, payment.p_id, PAYDIRECT_HOST, PAYDIRECT_URL, True) 274 246 doc=parseString(result_xml) 275 247 status=doc.getElementsByTagName('PaymentStatus')[0].firstChild.data … … 315 287 self.assertTrue(ref_number in self.browser.contents) 316 288 self.browser.getControl("Requery").click() 317 self.assertTrue('Your payment %s was not found.' % value in self.browser.contents)318 self.create_booking(value)319 self.browser.getLink("Pay via Interswitch PAYDirect").click()320 self.browser.getControl("Requery").click()321 289 self.assertTrue('pending' in self.browser.contents) 322 290 # Reference number has still not been saved because the element was empty 323 291 self.assertEqual(self.student['payments'][value].r_pay_reference, None) 292 324 293 # Here we have to stop testing because we cannot create completed bookings 325 294
Note: See TracChangeset for help on using the changeset viewer.