You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. import logging
  4. from openerp import api, fields, models, _
  5. _logger = logging.getLogger(__name__)
  6. class PaymentTransaction(models.Model):
  7. _inherit = 'payment.transaction'
  8. release_capital_request = fields.Many2one('account.invoice', string="Release Capital request")
  9. @api.model
  10. def process_online_payment_reception(self,tx):
  11. release_capital_request = tx.release_capital_request
  12. release_capital_request.subscription_request[0].state = 'paid'
  13. effective_date = datetime.now().strftime("%d/%m/%Y")
  14. release_capital_request.sudo().set_cooperator_effective(effective_date)
  15. return True
  16. @api.v7
  17. def _paypal_form_validate(self, cr, uid, tx, data, context=None):
  18. status = data.get('payment_status')
  19. res = {
  20. 'acquirer_reference': data.get('txn_id'),
  21. 'paypal_txn_type': data.get('payment_type'),
  22. }
  23. if status in ['Completed', 'Processed']:
  24. _logger.info('Validated Paypal payment for tx %s: set as done' % (tx.reference))
  25. res.update(state='done', date_validate=fields.Datetime.now())
  26. result = tx.write(res)
  27. self.process_online_payment_reception(cr, uid, tx)
  28. return result
  29. elif status in ['Pending', 'Expired']:
  30. _logger.info('Received notification for Paypal payment %s: set as pending' % (tx.reference))
  31. res.update(state='pending', state_message=data.get('pending_reason', ''))
  32. return tx.write(res)
  33. else:
  34. error = 'Received unrecognized status for Paypal payment %s: %s, set as error' % (tx.reference, status)
  35. _logger.info(error)
  36. res.update(state='error', state_message=error)
  37. return tx.write(res)