File: test_refund_flows.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (79 lines) | stat: -rw-r--r-- 3,846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from unittest.mock import patch

from odoo.tests import tagged
from odoo.tools import mute_logger

from odoo.addons.payment_authorize.tests.common import AuthorizeCommon


@tagged('post_install', '-at_install')
class TestRefundFlows(AuthorizeCommon):

    def test_refunding_voided_tx_cancels_it(self):
        """ Test that refunding a transaction that has been voided from Authorize.net side cancels
        it on Odoo. """
        source_tx = self._create_transaction('direct', state='done')
        with patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI'
            '.get_transaction_details',
            return_value={'transaction': {'transactionStatus': 'voided'}},
        ):
            source_tx._send_refund_request(amount_to_refund=source_tx.amount)
        self.assertEqual(source_tx.state, 'cancel')

    def test_refunding_refunded_tx_creates_refund_tx(self):
        """ Test that refunding a transaction that has been refunded from Authorize.net side creates
        a refund transaction on Odoo. """
        source_tx = self._create_transaction('direct', state='done')
        with patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI'
            '.get_transaction_details',
            return_value={'transaction': {'transactionStatus': 'refundSettledSuccessfully'}},
        ):
            source_tx._send_refund_request(amount_to_refund=source_tx.amount)
        refund_tx = self.env['payment.transaction'].search(
            [('source_transaction_id', '=', source_tx.id)]
        )
        self.assertTrue(refund_tx)

    @mute_logger('odoo.addons.payment_authorize.models.payment_transaction')
    def test_refunding_authorized_tx_voids_it(self):
        """ Test that refunding a transaction that is still authorized on Authorize.net side voids
        it on Authorize.net instead of refunding it. """
        source_tx = self._create_transaction('direct', state='done')
        with patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI'
            '.get_transaction_details',
            return_value={'transaction': {'transactionStatus': 'authorizedPendingCapture'}},
        ), patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI.void'
        ) as void_mock, patch(
            'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
            '._handle_notification_data'
        ):
            source_tx._send_refund_request(amount_to_refund=source_tx.amount)
        self.assertEqual(void_mock.call_count, 1)

    @mute_logger('odoo.addons.payment_authorize.models.payment_transaction')
    def test_refunding_captured_tx_refunds_it_and_creates_refund_tx(self):
        """ Test that refunding a transaction that is captured on Authorize.net side captures it and
        create a refund transaction on Odoo. """
        source_tx = self._create_transaction('direct', state='done')
        with patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI'
            '.get_transaction_details',
            return_value={'transaction': {'transactionStatus': 'settledSuccessfully'}},
        ), patch(
            'odoo.addons.payment_authorize.models.authorize_request.AuthorizeAPI.refund'
        ) as refund_mock, patch(
            'odoo.addons.payment.models.payment_transaction.PaymentTransaction'
            '._handle_notification_data'
        ):
            source_tx._send_refund_request(amount_to_refund=source_tx.amount)
        self.assertEqual(refund_mock.call_count, 1)
        refund_tx = self.env['payment.transaction'].search(
            [('source_transaction_id', '=', source_tx.id)]
        )
        self.assertTrue(refund_tx)