Ignore:
Timestamp:
20 May 2021, 10:54:17 (3 years ago)
Author:
Henrik Bettermann
Message:

A paydirect booking must be created before students can go to their bank.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/paydirectbrowser.py

    r16484 r16487  
    2121from zope.component import getUtility
    2222from zope.security import checkPermission
     23from xml.dom.minidom import parseString
    2324from waeup.kofa.interfaces import IKofaUtils
    2425from waeup.kofa.utils.helpers import to_timezone
     
    2930from waeup.kofa.students.browser import StudentBasePDFFormPage
    3031from waeup.kofa.applicants.browser import OnlinePaymentDisplayFormPage as OPDPApplicant
     32from waeup.kofa.applicants.browser import ApplicantBaseDisplayFormPage
    3133from 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)
    3336from kofacustom.nigeria.payments.interfaces import INigeriaOnlinePayment
    3437from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment
    3538from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment
    36 from kofacustom.nigeria.interswitch.tests import PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID
     39from kofacustom.nigeria.interswitch.tests import (
     40    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
    3741from kofacustom.nigeria.interfaces import MessageFactory as _
    3842
     
    106110        if self.context.r_company and self.context.r_company != 'interswitch':
    107111            return _("Payment ticket has been used for another payment gateway.")
    108         tz = getUtility(IKofaUtils).tzinfo
    109         time_delta = datetime.utcnow() - self.context.creation_date
    110         if time_delta.days > 7:
    111             return _("This payment ticket is too old. Please create a new ticket.")
    112112        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
    113126        return
    114127
     
    198211        return
    199212
    200 class PaymentRefNumberSlipActionButton(ManageActionButton):
    201     grok.order(1)  # This button should always be the last one.
    202     grok.context(INigeriaOnlinePayment)
     213class StudentPaymentRefNumberSlipActionButton(ManageActionButton):
     214    grok.order(1)
     215    grok.context(INigeriaStudentOnlinePayment)
    203216    grok.view(PAYDirectPageStudent)
    204217    grok.require('waeup.viewStudent')
     
    213226        return self.view.url(self.view.context, self.target)
    214227
    215 class RefNumberSlipStudent(UtilityView, grok.View):
     228class ApplicantPaymentRefNumberSlipActionButton(StudentPaymentRefNumberSlipActionButton):
     229    grok.context(INigeriaApplicantOnlinePayment)
     230    grok.view(PAYDirectPageApplicant)
     231    grok.require('waeup.viewApplication')
     232
     233class StudentRefNumberSlip(UtilityView, grok.View):
    216234    """Deliver a PDF slip of the context.
    217235    """
    218     grok.context(INigeriaOnlinePayment)
     236    grok.context(INigeriaStudentOnlinePayment)
    219237    grok.name('refnumberslip.pdf')
    220238    grok.require('waeup.viewStudent')
     
    256274            self.context.student, studentview, note=self.note,
    257275            omit_fields=self.omit_fields)
     276
     277class 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 />
     286Go 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.