Changeset 14788


Ignore:
Timestamp:
9 Aug 2017, 14:03:33 (7 years ago)
Author:
Henrik Bettermann
Message:

The callback is a JSON response.

Do not trigger any action on students or applicants if payment was already paid.

Location:
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/helpers.py

    r14769 r14788  
    116116    payment.r_company = u'remita'
    117117    if payment.r_code not in ('00', '01'):
    118         msg = _('Unsuccessful callback: ${a}', mapping = {'a': payment.r_desc})
    119         log = 'unsuccessful callback for %s payment %s: %s' % (
     118        msg = _('Unsuccessful response: ${a}', mapping = {'a': payment.r_desc})
     119        log = 'unsuccessful response for %s payment %s: %s' % (
    120120            payment.p_category, payment.p_id, payment.r_desc)
    121121        payment.p_state = 'failed'
     
    123123        return False, msg, log
    124124    if round(payment.r_amount_approved, 0) != round(payment.amount_auth, 0):
    125         msg = _('Callback amount does not match.')
    126         log = 'wrong callback for %s payment %s: %s' % (
     125        msg = _('Response amount does not match.')
     126        log = 'wrong response for %s payment %s: %s' % (
    127127            payment.p_category, payment.p_id, str(jr))
    128128        payment.p_state = 'failed'
     
    130130        return False, msg, log
    131131    if jr['orderId'] != payment.p_id:
    132         msg = _('Callback order id does not match.')
    133         log = 'wrong callback for %s payment %s: %s' % (
     132        msg = _('Response order id does not match.')
     133        log = 'wrong response for %s payment %s: %s' % (
    134134            payment.p_category, payment.p_id, str(jr))
    135135        payment.p_state = 'failed'
     
    139139    if not verify:
    140140        payment.payment_date = datetime.utcnow()
    141     msg = _('Successful callback received')
    142     log = 'valid callback for %s payment %s: %s' % (
     141    msg = _('Successful response received')
     142    log = 'valid response for %s payment %s: %s' % (
    143143        payment.p_category, payment.p_id, str(jr))
    144144    notify(grok.ObjectModifiedEvent(payment))
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py

    r14787 r14788  
    166166        assert qr == (
    167167            False,
    168             u'Unsuccessful callback: ${a}',
    169             u'unsuccessful callback for schoolfee payment %s: Transaction Pending'
     168            u'Unsuccessful response: ${a}',
     169            u'unsuccessful response for schoolfee payment %s: Transaction Pending'
    170170            % self.payment.p_id)
    171171
     
    182182            verify=False)
    183183        assert qr[0] == True
    184         assert qr[1] == u'Successful callback received'
     184        assert qr[1] == u'Successful response received'
    185185
    186186    @external_test
     
    211211        self.payment.r_pay_reference = self.rrr
    212212        self.browser.getLink("Requery Remita Payment Status").click()
    213         self.assertTrue('Callback amount does not match.'
     213        self.assertTrue('Response amount does not match.'
    214214            in self.browser.contents)
    215215        self.payment.amount_auth = self.amount
    216216        self.browser.getLink("Requery Remita Payment Status").click()
    217         self.assertTrue('Callback order id does not match.'
     217        self.assertTrue('Response order id does not match.'
    218218            in self.browser.contents)
    219219        self.payment.p_id = self.orderId
     
    224224        self.assertEqual(self.payment.r_code, '01')
    225225        self.browser.getLink("Verify Remita Payment Status").click()
    226         self.assertTrue('Successful callback received' in self.browser.contents)
     226        self.assertTrue('Successful response received' in self.browser.contents)
    227227        return
    228228
     
    268268        self.assertTrue(
    269269            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
    270             ' - K1000000 - valid callback for schoolfee payment %s: '
     270            ' - K1000000 - valid response for schoolfee payment %s: '
    271271            % self.orderId   in logcontent)
    272272        self.assertTrue(
     
    321321        self.assertTrue(
    322322            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
    323             ' - %s - valid callback for application payment %s: '
     323            ' - %s - valid response for application payment %s: '
    324324            % (self.applicant.applicant_id, self.orderId) in logcontent)
    325325        self.assertTrue(
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/webservices.py

    r14786 r14788  
    9696                continue
    9797            ticket = results[0]
     98            if ticket.p_state == 'waived':
     99                failed += 1
     100                continue
     101            waspaid = (ticket.p_state == 'paid')
    98102            success, msg, log = query_remita(
    99103                ticket, self.merchantId, self.api_key,
     
    105109                ticket.student.writeLogMessage(self, log)
    106110                successful += 1
    107                 write_payments_log(ticket.student.student_id, ticket)
    108                 flashtype, msg, log = ticket.doAfterStudentPayment()
    109                 if log is not None:
    110                     ticket.student.writeLogMessage(self, log)
     111                if not waspaid:
     112                    write_payments_log(ticket.student.student_id, ticket)
     113                    flashtype, msg, log = ticket.doAfterStudentPayment()
     114                    if log is not None:
     115                        ticket.student.writeLogMessage(self, log)
    111116            else:
    112117                applicant = ticket.__parent__
    113118                applicant.writeLogMessage(self, log)
    114119                successful += 1
    115                 write_payments_log(applicant.applicant_id, ticket)
    116                 flashtype, msg, log = ticket.doAfterApplicantPayment()
    117                 if log is not None:
    118                     applicant.writeLogMessage(self, log)
     120                if not waspaid:
     121                    write_payments_log(applicant.applicant_id, ticket)
     122                    flashtype, msg, log = ticket.doAfterApplicantPayment()
     123                    if log is not None:
     124                        applicant.writeLogMessage(self, log)
    119125        self.output = '%s (%s)' % (successful, failed + successful)
    120126        return
Note: See TracChangeset for help on using the changeset viewer.