From 7fbb9977321a1827aa1b9bd5301be8094f4612f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 5 Jul 2016 14:55:21 +0200 Subject: [PATCH] [MOV] payment_payumoney: file organization --- addons/payment_payumoney/__openerp__.py | 6 +- ...ney_data.xml => payment_acquirer_data.xml} | 0 addons/payment_payumoney/models/__init__.py | 3 +- .../{payment_acquirer.py => payment.py} | 81 +++++++++++++++++ .../models/payment_transaction.py | 86 ------------------- ...ey.xml => payment_payumoney_templates.xml} | 0 ...payment_acquirer.xml => payment_views.xml} | 0 7 files changed, 85 insertions(+), 91 deletions(-) rename addons/payment_payumoney/data/{payment_payumoney_data.xml => payment_acquirer_data.xml} (100%) rename addons/payment_payumoney/models/{payment_acquirer.py => payment.py} (51%) delete mode 100644 addons/payment_payumoney/models/payment_transaction.py rename addons/payment_payumoney/views/{payumoney.xml => payment_payumoney_templates.xml} (100%) rename addons/payment_payumoney/views/{payment_acquirer.xml => payment_views.xml} (100%) diff --git a/addons/payment_payumoney/__openerp__.py b/addons/payment_payumoney/__openerp__.py index 62e92bb78d8..ce4a57eb68c 100644 --- a/addons/payment_payumoney/__openerp__.py +++ b/addons/payment_payumoney/__openerp__.py @@ -12,9 +12,9 @@ """, 'depends': ['payment'], 'data': [ - 'views/payumoney.xml', - 'views/payment_acquirer.xml', - 'data/payment_payumoney_data.xml', + 'views/payment_views.xml', + 'views/payment_payumoney_templates.xml', + 'data/payment_acquirer_data.xml', ], 'license': 'OEEL-1', } diff --git a/addons/payment_payumoney/data/payment_payumoney_data.xml b/addons/payment_payumoney/data/payment_acquirer_data.xml similarity index 100% rename from addons/payment_payumoney/data/payment_payumoney_data.xml rename to addons/payment_payumoney/data/payment_acquirer_data.xml diff --git a/addons/payment_payumoney/models/__init__.py b/addons/payment_payumoney/models/__init__.py index 29abdbcb773..8ba584ff326 100644 --- a/addons/payment_payumoney/models/__init__.py +++ b/addons/payment_payumoney/models/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import payment_acquirer -import payment_transaction +import payment diff --git a/addons/payment_payumoney/models/payment_acquirer.py b/addons/payment_payumoney/models/payment.py similarity index 51% rename from addons/payment_payumoney/models/payment_acquirer.py rename to addons/payment_payumoney/models/payment.py index 0abe333e73d..98edf7a72ff 100644 --- a/addons/payment_payumoney/models/payment_acquirer.py +++ b/addons/payment_payumoney/models/payment.py @@ -5,6 +5,12 @@ import hashlib import urlparse from odoo import api, fields, models, _ +from odoo.addons.payment.models.payment_acquirer import ValidationError +from odoo.tools.float_utils import float_compare + +import logging + +_logger = logging.getLogger(__name__) class PaymentAcquirerPayumoney(models.Model): @@ -76,3 +82,78 @@ class PaymentAcquirerPayumoney(models.Model): def payumoney_get_form_action_url(self): self.ensure_one() return self._get_payumoney_urls(self.environment)['payumoney_form_url'] + + +class PaymentTransactionPayumoney(models.Model): + _inherit = 'payment.transaction' + + @api.model + def _payumoney_form_get_tx_from_data(self, data): + """ Given a data dict coming from payumoney, verify it and find the related + transaction record. """ + reference = data.get('txnid') + pay_id = data.get('mihpayid') + shasign = data.get('hash') + if not reference or not pay_id or not shasign: + raise ValidationError(_('PayUmoney: received data with missing reference (%s) or pay_id (%s) or shashign (%s)') % (reference, pay_id, shasign)) + + transaction = self.search([('reference', '=', reference)]) + + if not transaction: + error_msg = (_('PayUmoney: received data for reference %s; no order found') % (reference)) + raise ValidationError(error_msg) + elif len(transaction) > 1: + error_msg = (_('PayUmoney: received data for reference %s; multiple orders found') % (reference)) + raise ValidationError(error_msg) + + #verify shasign + shasign_check = transaction.acquirer_id._payumoney_generate_sign('out', data) + if shasign_check.upper() != shasign.upper(): + raise ValidationError(_('PayUmoney: invalid shasign, received %s, computed %s, for data %s') % (shasign, shasign_check, data)) + return transaction + + @api.multi + def _payumoney_form_get_invalid_parameters(self, data): + invalid_parameters = [] + + if self.acquirer_reference and data.get('mihpayid') != self.acquirer_reference: + invalid_parameters.append( + ('Transaction Id', data.get('mihpayid'), self.acquirer_reference)) + #check what is buyed + if float_compare(float(data.get('amount', '0.0')), self.amount, 2) != 0: + invalid_parameters.append( + ('Amount', data.get('amount'), '%.2f' % self.amount)) + + return invalid_parameters + + @api.multi + def _payumoney_form_validate(self, data): + status = data.get('status') + transaction_status = { + 'success': { + 'state': 'done', + 'acquirer_reference': data.get('payuMoneyId'), + 'date_validate': fields.Datetime.now(), + }, + 'pending': { + 'state': 'pending', + 'acquirer_reference': data.get('payuMoneyId'), + 'date_validate': fields.Datetime.now(), + }, + 'failure': { + 'state': 'cancel', + 'acquirer_reference': data.get('payuMoneyId'), + 'date_validate': fields.Datetime.now(), + }, + 'error': { + 'state': 'error', + 'state_message': data.get('error_Message') or _('PayUmoney: feedback error'), + 'acquirer_reference': data.get('payuMoneyId'), + 'date_validate': fields.Datetime.now(), + } + } + vals = transaction_status.get(status, False) + if not vals: + vals = transaction_status['error'] + _logger.info(vals['state_message']) + return self.write(vals) diff --git a/addons/payment_payumoney/models/payment_transaction.py b/addons/payment_payumoney/models/payment_transaction.py deleted file mode 100644 index e89a95511ec..00000000000 --- a/addons/payment_payumoney/models/payment_transaction.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -import logging - -from odoo import api, fields, models, _ -from odoo.addons.payment.models.payment_acquirer import ValidationError -from odoo.tools.float_utils import float_compare - - -_logger = logging.getLogger(__name__) - - -class PaymentTransactionPayumoney(models.Model): - _inherit = 'payment.transaction' - - @api.model - def _payumoney_form_get_tx_from_data(self, data): - """ Given a data dict coming from payumoney, verify it and find the related - transaction record. """ - reference = data.get('txnid') - pay_id = data.get('mihpayid') - shasign = data.get('hash') - if not reference or not pay_id or not shasign: - raise ValidationError(_('PayUmoney: received data with missing reference (%s) or pay_id (%s) or shashign (%s)') % (reference, pay_id, shasign)) - - transaction = self.search([('reference', '=', reference)]) - - if not transaction: - error_msg = (_('PayUmoney: received data for reference %s; no order found') % (reference)) - raise ValidationError(error_msg) - elif len(transaction) > 1: - error_msg = (_('PayUmoney: received data for reference %s; multiple orders found') % (reference)) - raise ValidationError(error_msg) - - #verify shasign - shasign_check = transaction.acquirer_id._payumoney_generate_sign('out', data) - if shasign_check.upper() != shasign.upper(): - raise ValidationError(_('PayUmoney: invalid shasign, received %s, computed %s, for data %s') % (shasign, shasign_check, data)) - return transaction - - @api.multi - def _payumoney_form_get_invalid_parameters(self, data): - invalid_parameters = [] - - if self.acquirer_reference and data.get('mihpayid') != self.acquirer_reference: - invalid_parameters.append( - ('Transaction Id', data.get('mihpayid'), self.acquirer_reference)) - #check what is buyed - if float_compare(float(data.get('amount', '0.0')), self.amount, 2) != 0: - invalid_parameters.append( - ('Amount', data.get('amount'), '%.2f' % self.amount)) - - return invalid_parameters - - @api.multi - def _payumoney_form_validate(self, data): - status = data.get('status') - transaction_status = { - 'success': { - 'state': 'done', - 'acquirer_reference': data.get('payuMoneyId'), - 'date_validate': fields.Datetime.now(), - }, - 'pending': { - 'state': 'pending', - 'acquirer_reference': data.get('payuMoneyId'), - 'date_validate': fields.Datetime.now(), - }, - 'failure': { - 'state': 'cancel', - 'acquirer_reference': data.get('payuMoneyId'), - 'date_validate': fields.Datetime.now(), - }, - 'error': { - 'state': 'error', - 'state_message': data.get('error_Message') or _('PayUmoney: feedback error'), - 'acquirer_reference': data.get('payuMoneyId'), - 'date_validate': fields.Datetime.now(), - } - } - vals = transaction_status.get(status, False) - if not vals: - vals = transaction_status['error'] - _logger.info(vals['state_message']) - return self.write(vals) diff --git a/addons/payment_payumoney/views/payumoney.xml b/addons/payment_payumoney/views/payment_payumoney_templates.xml similarity index 100% rename from addons/payment_payumoney/views/payumoney.xml rename to addons/payment_payumoney/views/payment_payumoney_templates.xml diff --git a/addons/payment_payumoney/views/payment_acquirer.xml b/addons/payment_payumoney/views/payment_views.xml similarity index 100% rename from addons/payment_payumoney/views/payment_acquirer.xml rename to addons/payment_payumoney/views/payment_views.xml