Changeset 10131 for main/waeup.kwarapoly


Ignore:
Timestamp:
30 Apr 2013, 15:41:11 (12 years ago)
Author:
Henrik Bettermann
Message:

Configure application fee payment.

Location:
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py

    r9789 r10131  
    2222from zope.component import getUtility, queryAdapter
    2323from kofacustom.nigeria.interswitch.browser import (
    24     InterswitchPaymentRequestWebservicePageStudent
     24    InterswitchPaymentRequestWebservicePageStudent,
     25    InterswitchPaymentRequestWebservicePageApplicant
    2526    )
    2627from waeup.kofa.browser.layout import KofaPage, UtilityView
     
    3233
    3334PRODUCT_ID = '3930'
    34 SITE_NAME = 'kwarapoly-kofa.waeup.org'
     35SITE_NAME = 'kwarapoly.waeup.org'
    3536PROVIDER_ACCT = '1010764827'
    3637PROVIDER_BANK_ID = '117'
     
    180181        return
    181182
     183class InterswitchPageApplicant(KofaPage):
     184    """ View which sends a POST request to the Interswitch
     185    CollegePAY payment gateway.
     186    """
     187    grok.context(ICustomApplicantOnlinePayment)
     188    grok.require('waeup.payApplicant')
     189    grok.template('applicant_goto_interswitch')
     190    grok.name('goto_interswitch')
     191    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
     192    submit_button = _('Submit')
     193    action = POST_ACTION
     194    site_name = SITE_NAME
     195    currency = CURRENCY
     196    pay_item_id = '103'
     197    product_id = PRODUCT_ID
     198    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
     199
     200    def interswitch_img_url(self):
     201        return interswitch_img_url(self)
     202
     203    def update(self):
     204        if self.context.p_state != 'unpaid':
     205            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
     206            self.redirect(self.url(self.context, '@@index'))
     207            return
     208        if self.context.__parent__.__parent__.expired \
     209            and self.context.__parent__.__parent__.strict_deadline:
     210            self.flash(_("Payment ticket can't be send to CollegePAY. "
     211                         "Application period has expired."))
     212            self.redirect(self.url(self.context, '@@index'))
     213            return
     214        self.applicant = self.context.__parent__
     215        self.amount_auth = 100 * self.context.amount_auth
     216        xmldict = {}
     217        self.category = getUtility(
     218            IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
     219        tz = getUtility(IKofaUtils).tzinfo
     220        self.local_date_time = to_timezone(
     221            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
     222        self.site_redirect_url = self.url(self.context, 'request_webservice')
     223        provider_amt = 250.0
     224        dalash_amt = 250.0
     225        if self.applicant.applicant_id.startswith('hnd'):
     226            xmldict['institution_acct'] = '7000016463'
     227            xmldict['institution_bank_id'] = '9'
     228        elif self.applicant.applicant_id.startswith('nd') \
     229            or self.applicant.applicant_id.startswith('prend'):
     230            xmldict['institution_acct'] = '2014191363'
     231            xmldict['institution_bank_id'] = '8'
     232        else:
     233            xmldict['institution_acct'] = '00000000000'
     234            xmldict['institution_bank_id'] = '00'
     235        xmldict['dalash_amt'] = 100 * dalash_amt
     236        xmldict['detail_ref'] = self.context.p_id
     237        xmldict['provider_amt'] = 100 * provider_amt
     238        xmldict['provider_acct'] = PROVIDER_ACCT
     239        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
     240        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
     241        xmldict['institution_amt'] = 100 * (
     242            self.context.amount_auth - provider_amt - GATEWAY_AMT - dalash_amt)
     243        xmldict['institution_item_name'] = self.context.p_category
     244        xmldict['institution_name'] = INSTITUTION_NAME
     245
     246        hashargs = (
     247            self.context.p_id +
     248            PRODUCT_ID +
     249            self.pay_item_id +
     250            str(int(self.amount_auth)) +
     251            self.site_redirect_url +
     252            self.mac)
     253        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
     254
     255        # Interswitch amount is not part of the xml data
     256        xmltext = """<payment_item_detail>
     257<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
     258<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" />
     259<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
     260<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
     261</item_details>
     262</payment_item_detail>""" % xmldict
     263        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     264        self.context.provider_amt = provider_amt
     265        self.context.gateway_amt = GATEWAY_AMT
     266        self.context.thirdparty_amt = dalash_amt
     267        return
     268
    182269class InterswitchPaymentRequestWebservicePageStudent(
    183270    InterswitchPaymentRequestWebservicePageStudent):
     
    188275    gateway_host = HOST
    189276    gateway_url = URL
     277
     278class InterswitchPaymentRequestWebservicePageApplicant(
     279    InterswitchPaymentRequestWebservicePageApplicant):
     280    """ Request webservice view for the CollegePAY gateway
     281    """
     282    grok.context(ICustomApplicantOnlinePayment)
     283    product_id = PRODUCT_ID
     284    gateway_host = HOST
     285    gateway_url = URL
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser_templates/applicant_goto_interswitch.pt

    r9996 r10131  
    5959  <input type="hidden" name="currency" tal:attributes="value view/currency" />
    6060  <input type="hidden" name="pay_item_id" tal:attributes="value view/pay_item_id" />
     61  <input type="hidden" name="hash" tal:attributes="value view/hashvalue" />
    6162  <input type="hidden" name="site_redirect_url" tal:attributes="value view/site_redirect_url" />
    6263  <input type="hidden" name="site_name" tal:attributes="value view/site_name" />
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py

    r9811 r10131  
    285285            '52100.0,00,1200.0,300.0,1800.0,,,\n'
    286286            in logcontent)
     287
     288
     289class InterswitchTestsApplicants(ApplicantsFullSetup):
     290    """Tests for the Interswitch payment gateway.
     291    """
     292
     293    layer = FunctionalLayer
     294
     295    def setUp(self):
     296        super(InterswitchTestsApplicants, self).setUp()
     297        # Create at least one Kwarapoly faculty
     298        self.app['faculties']['CPGS'] = Faculty(code='CPGS')
     299        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
     300        self.certificate2 = createObject('waeup.Certificate')
     301        self.certificate2.code = u'CERT2'
     302        self.certificate2.application_category = 'nd'
     303        self.certificate2.study_mode = 'nd_ft'
     304        self.certificate2.start_level = 100
     305        self.certificate2.end_level = 300
     306        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
     307            self.certificate2)
     308        self.applicantscontainer.application_category = 'nd'
     309        self.applicant.applicant_id = u'nd_anything'
     310       
     311        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     312        self.browser.open(self.manage_path)
     313        #IWorkflowState(self.student).setState('started')
     314        super(InterswitchTestsApplicants, self).fill_correct_values()
     315        self.browser.getControl(name="form.course1").value = ['CERT2']
     316        self.applicantscontainer.application_fee = 3333.0
     317        self.browser.getControl(name="form.nationality").value = ['NG']
     318        self.browser.getControl(name="transition").value = ['start']
     319        self.browser.getControl("Save").click()
     320        self.browser.getControl("Add online").click()
     321        self.assertMatches('...ticket created...',
     322                           self.browser.contents)
     323        #ctrl = self.browser.getControl(name='val_id')
     324        #value = ctrl.options[0]
     325        #self.browser.getLink(value).click()
     326        self.assertMatches('...Amount Authorized...',
     327                           self.browser.contents)
     328        self.assertMatches(
     329            '...<span>3333.0</span>...',
     330            self.browser.contents)
     331        self.payment_url = self.browser.url
     332
     333
     334    def test_interswitch_form(self):
     335
     336        # Manager can access InterswitchForm
     337        self.browser.getLink("CollegePAY", index=0).click()
     338        self.assertMatches('...Total Amount Authorized:...',
     339                           self.browser.contents)
     340        self.assertTrue(
     341            '<input type="hidden" name="amount" value="333300.0" />'
     342            in self.browser.contents)
     343        self.assertTrue(
     344            '<item_detail item_id="1" item_name="application" '
     345            'item_amt="253300" bank_id="8" acct_num="2014191363" />'
     346            in self.browser.contents)
     347
     348        # hnd fee goes to another account
     349        self.applicant.applicant_id = u'hnd_anything'
     350        self.browser.open(self.manage_path)
     351        ctrl = self.browser.getControl(name='val_id')
     352        value = ctrl.options[0]
     353        self.browser.getLink(value).click()
     354        self.browser.getLink("CollegePAY", index=0).click()
     355        self.assertTrue(
     356            '<item_detail item_id="1" item_name="application" '
     357            'item_amt="253300" bank_id="9" acct_num="7000016463" />'
     358            in self.browser.contents)
     359
Note: See TracChangeset for help on using the changeset viewer.