[IMP] payment_*: use standard fields to store tx information instead of adding specific fields for every.payment.provider

This commit is contained in:
Deep Bundela
2015-09-04 16:08:22 +02:00
committed by Damien Bouvy
parent cf394d953c
commit f76c78d598
11 changed files with 19 additions and 79 deletions
+2 -6
View File
@@ -104,10 +104,6 @@ class AcquirerAdyen(osv.Model):
class TxAdyen(osv.Model):
_inherit = 'payment.transaction'
_columns = {
'adyen_psp_reference': fields.char('Adyen PSP Reference'),
}
# --------------------------------------------------
# FORM RELATED METHODS
# --------------------------------------------------
@@ -160,7 +156,7 @@ class TxAdyen(osv.Model):
if status == 'AUTHORISED':
tx.write({
'state': 'done',
'adyen_psp_reference': data.get('pspReference'),
'acquirer_reference': data.get('pspReference'),
# 'date_validate': data.get('payment_date', fields.datetime.now()),
# 'paypal_txn_type': data.get('express_checkout')
})
@@ -168,7 +164,7 @@ class TxAdyen(osv.Model):
elif status == 'PENDING':
tx.write({
'state': 'pending',
'adyen_psp_reference': data.get('pspReference'),
'acquirer_reference': data.get('pspReference'),
})
return True
else:
@@ -18,20 +18,5 @@
</field>
</record>
<record id="transaction_form_adyen" model="ir.ui.view">
<field name="name">acquirer.transaction.form.adyen</field>
<field name="model">payment.transaction</field>
<field name="inherit_id" ref="payment.transaction_form"/>
<field name="arch" type="xml">
<xpath expr='//notebook' position='inside'>
<page string="Adyen TX Details">
<group>
<field name="adyen_psp_reference"/>
</group>
</page>
</xpath>
</field>
</record>
</data>
</openerp>
+6 -12
View File
@@ -85,8 +85,6 @@ class PaymentAcquirerAuthorize(models.Model):
class TxAuthorize(models.Model):
_inherit = 'payment.transaction'
authorize_txnid = fields.Char(string='Transaction ID')
_authorize_valid_tx_status = 1
_authorize_pending_tx_status = 4
_authorize_cancel_tx_status = 2
@@ -119,8 +117,8 @@ class TxAuthorize(models.Model):
def _authorize_form_get_invalid_parameters(self, tx, data):
invalid_parameters = []
if tx.authorize_txnid and data.get('x_trans_id') != tx.authorize_txnid:
invalid_parameters.append(('Transaction Id', data.get('x_trans_id'), tx.authorize_txnid))
if self.acquirer_reference and data.get('x_trans_id') != self.acquirer_reference:
invalid_parameters.append(('Transaction Id', data.get('x_trans_id'), self.acquirer_reference))
# check what is buyed
if float_compare(float(data.get('x_amount', '0.0')), tx.amount, 2) != 0:
invalid_parameters.append(('Amount', data.get('x_amount'), '%.2f' % tx.amount))
@@ -135,22 +133,19 @@ class TxAuthorize(models.Model):
if status_code == self._authorize_valid_tx_status:
tx.write({
'state': 'done',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
'acquirer_reference': data.get('x_trans_id'),
})
return True
elif status_code == self._authorize_pending_tx_status:
tx.write({
'state': 'pending',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
'acquirer_reference': data.get('x_trans_id'),
})
return True
elif status_code == self._authorize_cancel_tx_status:
tx.write({
'state': 'cancel',
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
'acquirer_reference': data.get('x_trans_id'),
})
return True
else:
@@ -159,7 +154,6 @@ class TxAuthorize(models.Model):
tx.write({
'state': 'error',
'state_message': error,
'authorize_txnid': data.get('x_trans_id'),
'acquirer_reference': data['x_invoice_num'],
'acquirer_reference': data.get('x_trans_id'),
})
return False
@@ -161,10 +161,10 @@ class AuthorizeForm(AuthorizeCommon):
self.payment_transaction.form_feedback(cr, uid, authorize_post_data, 'authorize', context=context)
# check state
self.assertEqual(tx.state, 'done', 'Authorize: validation did not put tx into done state')
self.assertEqual(tx.authorize_txnid, authorize_post_data.get('x_trans_id'), 'Authorize: validation did not update tx payid')
self.assertEqual(tx.acquirer_reference, authorize_post_data.get('x_trans_id'), 'Authorize: validation did not update tx payid')
# reset tx
tx.write({'state': 'draft', 'date_validate': False, 'authorize_txnid': False})
tx.write({'state': 'draft', 'date_validate': False, 'acquirer_reference': False})
# simulate an error
authorize_post_data['x_response_code'] = u'3'
@@ -15,18 +15,4 @@
</field>
</record>
<record id="transaction_form_authorize" model="ir.ui.view">
<field name="name">acquirer.transaction.form.authorize</field>
<field name="model">payment.transaction</field>
<field name="inherit_id" ref="payment.transaction_form"/>
<field name="arch" type="xml">
<xpath expr='//notebook' position='inside'>
<page string="Authorize TX Details">
<group>
<field name="authorize_txnid"/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>
+4 -8
View File
@@ -112,10 +112,6 @@ class TxBuckaroo(osv.Model):
_buckaroo_error_tx_status = [490, 491, 492]
_buckaroo_reject_tx_status = [690]
_columns = {
'buckaroo_txnid': fields.char('Transaction ID'),
}
# --------------------------------------------------
# FORM RELATED METHODS
@@ -168,19 +164,19 @@ class TxBuckaroo(osv.Model):
if status_code in self._buckaroo_valid_tx_status:
tx.write({
'state': 'done',
'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'),
'acquirer_reference': data.get('BRQ_TRANSACTIONS'),
})
return True
elif status_code in self._buckaroo_pending_tx_status:
tx.write({
'state': 'pending',
'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'),
'acquirer_reference': data.get('BRQ_TRANSACTIONS'),
})
return True
elif status_code in self._buckaroo_cancel_tx_status:
tx.write({
'state': 'cancel',
'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'),
'acquirer_reference': data.get('BRQ_TRANSACTIONS'),
})
return True
else:
@@ -189,6 +185,6 @@ class TxBuckaroo(osv.Model):
tx.write({
'state': 'error',
'state_message': error,
'buckaroo_txnid': data.get('BRQ_TRANSACTIONS'),
'acquirer_reference': data.get('BRQ_TRANSACTIONS'),
})
return False
@@ -159,10 +159,10 @@ class BuckarooForm(BuckarooCommon):
# check state
tx = self.payment_transaction.browse(cr, uid, tx_id, context=context)
self.assertEqual(tx.state, 'done', 'Buckaroo: validation did not put tx into done state')
self.assertEqual(tx.buckaroo_txnid, buckaroo_post_data.get('BRQ_TRANSACTIONS'), 'Buckaroo: validation did not update tx payid')
self.assertEqual(tx.acquirer_reference, buckaroo_post_data.get('BRQ_TRANSACTIONS'), 'Buckaroo: validation did not update tx payid')
# reset tx
tx.write({'state': 'draft', 'date_validate': False, 'buckaroo_txnid': False})
tx.write({'state': 'draft', 'date_validate': False, 'acquirer_reference': False})
# now buckaroo post is ok: try to modify the SHASIGN
buckaroo_post_data['BRQ_SIGNATURE'] = '54d928810e343acf5fb0c3ee75fd747ff159ef7a'
@@ -17,20 +17,5 @@
</field>
</record>
<record id="transaction_form_buckaroo" model="ir.ui.view">
<field name="name">acquirer.transaction.form.buckaroo</field>
<field name="model">payment.transaction</field>
<field name="inherit_id" ref="payment.transaction_form"/>
<field name="arch" type="xml">
<xpath expr='//notebook' position='inside'>
<page string="Buckaroo TX Details">
<group>
<field name="buckaroo_txnid"/>
</group>
</page>
</xpath>
</field>
</record>
</data>
</openerp>
-1
View File
@@ -175,7 +175,6 @@ class TxPaypal(osv.Model):
_inherit = 'payment.transaction'
_columns = {
'paypal_txn_id': fields.char('Transaction ID'),
'paypal_txn_type': fields.char('Transaction type'),
}
+3 -3
View File
@@ -223,13 +223,13 @@ class PaypalForm(PaypalCommon):
tx = self.payment_transaction.browse(cr, uid, tx_id, context=context)
self.assertEqual(tx.state, 'pending', 'paypal: wrong state after receiving a valid pending notification')
self.assertEqual(tx.state_message, 'multi_currency', 'paypal: wrong state message after receiving a valid pending notification')
self.assertEqual(tx.paypal_txn_id, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertEqual(tx.acquirer_reference, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertFalse(tx.date_validate, 'paypal: validation date should not be updated whenr receiving pending notification')
# update tx
self.payment_transaction.write(cr, uid, [tx_id], {
'state': 'draft',
'paypal_txn_id': False,
'acquirer_reference': False,
}, context=context)
# update notification from paypal
paypal_post_data['payment_status'] = 'Completed'
@@ -238,5 +238,5 @@ class PaypalForm(PaypalCommon):
# check
tx = self.payment_transaction.browse(cr, uid, tx_id, context=context)
self.assertEqual(tx.state, 'done', 'paypal: wrong state after receiving a valid pending notification')
self.assertEqual(tx.paypal_txn_id, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertEqual(tx.acquirer_reference, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
self.assertEqual(tx.date_validate, '2013-11-18 03:21:19', 'paypal: wrong validation date')
@@ -29,7 +29,6 @@
<xpath expr='//notebook' position='inside'>
<page string="Paypal TX Details">
<group>
<field name="paypal_txn_id"/>
<field name="paypal_txn_type"/>
</group>
</page>