diff --git a/addons/payment_acquirer_paypal/models/paypal.py b/addons/payment_acquirer_paypal/models/paypal.py index 8a9b9c40c19..665c9fd2a17 100644 --- a/addons/payment_acquirer_paypal/models/paypal.py +++ b/addons/payment_acquirer_paypal/models/paypal.py @@ -156,6 +156,7 @@ class TxPaypal(osv.Model): return self.browse(cr, uid, tx_ids[0], context=context) def _paypal_form_get_invalid_parameters(self, cr, uid, tx, data, context=None): + # TODO: txn_id: shoudl be false at draft, set afterwards, and verified with txn details invalid_parameters = [] if data.get('notify_version')[0] != '2.6': _logger.warning( @@ -205,6 +206,7 @@ class TxPaypal(osv.Model): _logger.info('Received notification for Paypal payment %s: set as pending' % (tx.reference)) tx.write({ 'state': 'pending', + 'state_message': data.get('pending_reason', ''), 'paypal_txn_id': data['txn_id'], 'paypal_txn_type': data.get('express_checkout'), }) diff --git a/addons/payment_acquirer_paypal/tests/test_paypal.py b/addons/payment_acquirer_paypal/tests/test_paypal.py index 77ac34c9d60..b9f2af8119e 100644 --- a/addons/payment_acquirer_paypal/tests/test_paypal.py +++ b/addons/payment_acquirer_paypal/tests/test_paypal.py @@ -185,3 +185,24 @@ class PaypalForm(PaypalCommon): ) # validate it self.payment_transaction.form_feedback(cr, uid, paypal_post_data, 'paypal', context=context) + # check + 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.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, + }, context=context) + # update notification from paypal + paypal_post_data['payment_status'] = 'Completed' + # validate it + self.payment_transaction.form_feedback(cr, uid, paypal_post_data, 'paypal', context=context) + # 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.date_validate, '2013-11-18 03:21:19', 'paypal: wrong validation date')