|
|
|
@@ -6,28 +6,27 @@ import time
|
|
|
|
|
import urlparse
|
|
|
|
|
from lxml import objectify
|
|
|
|
|
|
|
|
|
|
import openerp
|
|
|
|
|
from openerp.addons.payment.models.payment_acquirer import ValidationError
|
|
|
|
|
from openerp.addons.payment.tests.common import PaymentAcquirerCommon
|
|
|
|
|
from openerp.addons.payment_authorize.controllers.main import AuthorizeController
|
|
|
|
|
from openerp.tools import mute_logger
|
|
|
|
|
import odoo
|
|
|
|
|
from odoo.addons.payment.models.payment_acquirer import ValidationError
|
|
|
|
|
from odoo.addons.payment.tests.common import PaymentAcquirerCommon
|
|
|
|
|
from odoo.addons.payment_authorize.controllers.main import AuthorizeController
|
|
|
|
|
from odoo.tools import mute_logger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@openerp.tests.common.at_install(True)
|
|
|
|
|
@openerp.tests.common.post_install(True)
|
|
|
|
|
@odoo.tests.common.at_install(True)
|
|
|
|
|
@odoo.tests.common.post_install(True)
|
|
|
|
|
class AuthorizeCommon(PaymentAcquirerCommon):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super(AuthorizeCommon, self).setUp()
|
|
|
|
|
self.base_url = self.env['ir.config_parameter'].get_param('web.base.url')
|
|
|
|
|
# authorize only support USD in test environment
|
|
|
|
|
self.currency_usd = self.env['res.currency'].search([('name', '=', 'USD')], limit=1)[0]
|
|
|
|
|
# get the authorize account
|
|
|
|
|
model, self.authorize_id = self.env['ir.model.data'].get_object_reference('payment', 'payment_acquirer_authorize')
|
|
|
|
|
self.authorize = self.env.ref('payment.payment_acquirer_authorize')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@openerp.tests.common.at_install(True)
|
|
|
|
|
@openerp.tests.common.post_install(True)
|
|
|
|
|
@odoo.tests.common.at_install(True)
|
|
|
|
|
@odoo.tests.common.post_install(True)
|
|
|
|
|
class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
|
|
|
|
|
def _authorize_generate_hashing(self, values):
|
|
|
|
@@ -40,25 +39,25 @@ class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
return hmac.new(str(values['x_trans_key']), data, hashlib.md5).hexdigest()
|
|
|
|
|
|
|
|
|
|
def test_10_Authorize_form_render(self):
|
|
|
|
|
authorize = self.env['payment.acquirer'].browse(self.authorize_id)
|
|
|
|
|
self.assertEqual(authorize.environment, 'test', 'test without test environment')
|
|
|
|
|
self.assertEqual(self.authorize.environment, 'test', 'test without test environment')
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------
|
|
|
|
|
# Test: button direct rendering
|
|
|
|
|
# ----------------------------------------
|
|
|
|
|
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
|
|
|
|
|
form_values = {
|
|
|
|
|
'x_login': authorize.authorize_login,
|
|
|
|
|
'x_trans_key': authorize.authorize_transaction_key,
|
|
|
|
|
'x_login': self.authorize.authorize_login,
|
|
|
|
|
'x_trans_key': self.authorize.authorize_transaction_key,
|
|
|
|
|
'x_amount': '320.0',
|
|
|
|
|
'x_show_form': 'PAYMENT_FORM',
|
|
|
|
|
'x_type': 'AUTH_CAPTURE',
|
|
|
|
|
'x_method': 'CC',
|
|
|
|
|
'x_fp_sequence': '%s%s' % (authorize.id, int(time.time())),
|
|
|
|
|
'x_fp_sequence': '%s%s' % (self.authorize.id, int(time.time())),
|
|
|
|
|
'x_version': '3.1',
|
|
|
|
|
'x_relay_response': 'TRUE',
|
|
|
|
|
'x_fp_timestamp': str(int(time.time())),
|
|
|
|
|
'x_relay_url': '%s' % urlparse.urljoin(self.base_url, AuthorizeController._return_url),
|
|
|
|
|
'x_cancel_url': '%s' % urlparse.urljoin(self.base_url, AuthorizeController._cancel_url),
|
|
|
|
|
'x_relay_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._return_url),
|
|
|
|
|
'x_cancel_url': '%s' % urlparse.urljoin(base_url, AuthorizeController._cancel_url),
|
|
|
|
|
'return_url': None,
|
|
|
|
|
'x_currency_code': 'USD',
|
|
|
|
|
'x_invoice_num': 'SO004',
|
|
|
|
@@ -84,10 +83,7 @@ class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
|
|
|
|
|
form_values['x_fp_hash'] = self._authorize_generate_hashing(form_values)
|
|
|
|
|
# render the button
|
|
|
|
|
cr, uid, context = self.env.cr, self.env.uid, {}
|
|
|
|
|
res = self.payment_acquirer.render(
|
|
|
|
|
cr, uid, self.authorize_id, 'SO004', 320.0, self.currency_usd.id,
|
|
|
|
|
values=self.buyer_values, context=context)
|
|
|
|
|
res = self.authorize.render('SO004', 320.0, self.currency_usd.id, values=self.buyer_values)
|
|
|
|
|
# check form result
|
|
|
|
|
tree = objectify.fromstring(res)
|
|
|
|
|
self.assertEqual(tree.get('action'), 'https://test.authorize.net/gateway/transact.dll', 'Authorize: wrong form POST url')
|
|
|
|
@@ -101,12 +97,10 @@ class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
'Authorize: wrong value for input %s: received %s instead of %s' % (values[1], values[2], form_values[values[1]])
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@mute_logger('openerp.addons.payment_authorize.models.authorize', 'ValidationError')
|
|
|
|
|
@mute_logger('openerp.addons.payment_authorize.models.payment', 'ValidationError')
|
|
|
|
|
def test_20_authorize_form_management(self):
|
|
|
|
|
cr, uid, context = self.env.cr, self.env.uid, {}
|
|
|
|
|
# be sure not to do stupid thing
|
|
|
|
|
authorize = self.env['payment.acquirer'].browse(self.authorize_id)
|
|
|
|
|
self.assertEqual(authorize.environment, 'test', 'test without test environment')
|
|
|
|
|
self.assertEqual(self.authorize.environment, 'test', 'test without test environment')
|
|
|
|
|
|
|
|
|
|
# typical data posted by authorize after client has successfully paid
|
|
|
|
|
authorize_post_data = {
|
|
|
|
@@ -157,17 +151,17 @@ class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
|
|
|
|
|
# should raise error about unknown tx
|
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
|
self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context)
|
|
|
|
|
self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize')
|
|
|
|
|
|
|
|
|
|
tx = self.env['payment.transaction'].create({
|
|
|
|
|
'amount': 320.0,
|
|
|
|
|
'acquirer_id': self.authorize_id,
|
|
|
|
|
'acquirer_id': self.authorize.id,
|
|
|
|
|
'currency_id': self.currency_usd.id,
|
|
|
|
|
'reference': 'SO004',
|
|
|
|
|
'partner_name': 'Norbert Buyer',
|
|
|
|
|
'partner_country_id': self.country_france_id})
|
|
|
|
|
'partner_country_id': self.country_france.id})
|
|
|
|
|
# validate it
|
|
|
|
|
self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context)
|
|
|
|
|
self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize')
|
|
|
|
|
# check state
|
|
|
|
|
self.assertEqual(tx.state, 'done', 'Authorize: validation did not put tx into done state')
|
|
|
|
|
self.assertEqual(tx.acquirer_reference, authorize_post_data.get('x_trans_id'), 'Authorize: validation did not update tx payid')
|
|
|
|
@@ -177,6 +171,6 @@ class AuthorizeForm(AuthorizeCommon):
|
|
|
|
|
|
|
|
|
|
# simulate an error
|
|
|
|
|
authorize_post_data['x_response_code'] = u'3'
|
|
|
|
|
self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context)
|
|
|
|
|
self.env['payment.transaction'].form_feedback(authorize_post_data, 'authorize')
|
|
|
|
|
# check state
|
|
|
|
|
self.assertEqual(tx.state, 'error', 'Authorize: erroneous validation did not put tx into error state')
|
|
|
|
|