5
5
*/
6
6
namespace Magento \Sales \Model \Order \Invoice \Validation ;
7
7
8
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
8
9
use Magento \Payment \Model \InfoInterface ;
9
10
use Magento \Payment \Model \MethodInterface ;
10
11
use Magento \Sales \Api \Data \InvoiceInterface ;
11
12
use Magento \Sales \Api \OrderPaymentRepositoryInterface ;
12
13
use Magento \Sales \Api \OrderRepositoryInterface ;
13
14
use Magento \Sales \Model \Order \Invoice ;
14
15
use Magento \Sales \Model \ValidatorInterface ;
16
+ use Magento \Framework \App \ObjectManager ;
15
17
16
18
/**
17
19
* Class CanRefund
@@ -28,18 +30,26 @@ class CanRefund implements ValidatorInterface
28
30
*/
29
31
private $ orderRepository ;
30
32
33
+ /**
34
+ * @var ScopeConfigInterface;
35
+ */
36
+ private $ scopeConfig ;
37
+
31
38
/**
32
39
* CanRefund constructor.
33
40
*
34
41
* @param OrderPaymentRepositoryInterface $paymentRepository
35
42
* @param OrderRepositoryInterface $orderRepository
43
+ * @param ScopeConfigInterface|null $scopeConfig
36
44
*/
37
45
public function __construct (
38
46
OrderPaymentRepositoryInterface $ paymentRepository ,
39
- OrderRepositoryInterface $ orderRepository
47
+ OrderRepositoryInterface $ orderRepository ,
48
+ ?ScopeConfigInterface $ scopeConfig = null
40
49
) {
41
50
$ this ->paymentRepository = $ paymentRepository ;
42
51
$ this ->orderRepository = $ orderRepository ;
52
+ $ this ->scopeConfig = $ scopeConfig ?? ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
43
53
}
44
54
45
55
/**
@@ -69,7 +79,10 @@ private function isPaymentAllowRefund(InvoiceInterface $invoice)
69
79
return false ;
70
80
}
71
81
$ method = $ payment ->getMethodInstance ();
72
- return $ this ->canPartialRefund ($ method , $ payment ) || $ this ->canFullRefund ($ invoice , $ method );
82
+ if (!$ method instanceof \Magento \Payment \Model \Method \Free) {
83
+ return $ this ->canPartialRefund ($ method , $ payment ) || $ this ->canFullRefund ($ invoice , $ method );
84
+ }
85
+ return true ;
73
86
}
74
87
75
88
/**
@@ -78,7 +91,22 @@ private function isPaymentAllowRefund(InvoiceInterface $invoice)
78
91
*/
79
92
private function isGrandTotalEnoughToRefund (InvoiceInterface $ entity )
80
93
{
81
- return abs ($ entity ->getBaseGrandTotal () - $ entity ->getBaseTotalRefunded ()) >= .0001 ;
94
+ return abs ($ entity ->getBaseGrandTotal () - $ entity ->getBaseTotalRefunded ()) >= .0001 ||
95
+ $ this ->isAllowZeroGrandTotal ();
96
+ }
97
+
98
+ /**
99
+ * Return Zero GrandTotal availability.
100
+ *
101
+ * @return bool
102
+ */
103
+ private function isAllowZeroGrandTotal ()
104
+ {
105
+ $ isAllowed = $ this ->scopeConfig ->getValue (
106
+ 'sales/zerograndtotal_creditmemo/allow_zero_grandtotal ' ,
107
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
108
+ );
109
+ return $ isAllowed ;
82
110
}
83
111
84
112
/**
0 commit comments