Skip to content

Commit a069662

Browse files
author
Anna Bukatar
committed
ACP2E-1155: Refunding Issue Rest API
1 parent e240887 commit a069662

File tree

3 files changed

+37
-55
lines changed

3 files changed

+37
-55
lines changed

app/code/Magento/Sales/Model/Order/Invoice/Validation/CanRefund.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@
55
*/
66
namespace Magento\Sales\Model\Order\Invoice\Validation;
77

8-
use Magento\Framework\App\Config\ScopeConfigInterface;
98
use Magento\Payment\Model\InfoInterface;
109
use Magento\Payment\Model\MethodInterface;
1110
use Magento\Sales\Api\Data\InvoiceInterface;
1211
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
1312
use Magento\Sales\Api\OrderRepositoryInterface;
1413
use Magento\Sales\Model\Order\Invoice;
1514
use Magento\Sales\Model\ValidatorInterface;
16-
use Magento\Framework\App\ObjectManager;
1715

18-
/**
19-
* Class CanRefund
20-
*/
2116
class CanRefund implements ValidatorInterface
2217
{
18+
use \Magento\Sales\Model\Order\Validation\CanRefundTrait;
19+
2320
/**
2421
* @var OrderPaymentRepositoryInterface
2522
*/
@@ -30,26 +27,18 @@ class CanRefund implements ValidatorInterface
3027
*/
3128
private $orderRepository;
3229

33-
/**
34-
* @var ScopeConfigInterface;
35-
*/
36-
private $scopeConfig;
37-
3830
/**
3931
* CanRefund constructor.
4032
*
4133
* @param OrderPaymentRepositoryInterface $paymentRepository
4234
* @param OrderRepositoryInterface $orderRepository
43-
* @param ScopeConfigInterface|null $scopeConfig
4435
*/
4536
public function __construct(
4637
OrderPaymentRepositoryInterface $paymentRepository,
47-
OrderRepositoryInterface $orderRepository,
48-
?ScopeConfigInterface $scopeConfig = null
38+
OrderRepositoryInterface $orderRepository
4939
) {
5040
$this->paymentRepository = $paymentRepository;
5141
$this->orderRepository = $orderRepository;
52-
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
5342
}
5443

5544
/**
@@ -68,6 +57,8 @@ public function validate($entity)
6857
}
6958

7059
/**
60+
* Validate if a refund is possible for the payment method
61+
*
7162
* @param InvoiceInterface $invoice
7263
* @return bool
7364
*/
@@ -86,6 +77,8 @@ private function isPaymentAllowRefund(InvoiceInterface $invoice)
8677
}
8778

8879
/**
80+
* Validate if available grand total is enough to be refunded
81+
*
8982
* @param InvoiceInterface $entity
9083
* @return bool
9184
*/
@@ -96,20 +89,8 @@ private function isGrandTotalEnoughToRefund(InvoiceInterface $entity)
9689
}
9790

9891
/**
99-
* Return Zero GrandTotal availability.
92+
* Validate if partial refund is possible
10093
*
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;
110-
}
111-
112-
/**
11394
* @param MethodInterface $method
11495
* @param InfoInterface $payment
11596
* @return bool
@@ -122,6 +103,8 @@ private function canPartialRefund(MethodInterface $method, InfoInterface $paymen
122103
}
123104

124105
/**
106+
* validate if full refund is possible
107+
*
125108
* @param InvoiceInterface $invoice
126109
* @param MethodInterface $method
127110
* @return bool

app/code/Magento/Sales/Model/Order/Validation/CanRefund.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,29 @@
55
*/
66
namespace Magento\Sales\Model\Order\Validation;
77

8-
use Magento\Framework\App\Config\ScopeConfigInterface;
98
use Magento\Framework\Pricing\PriceCurrencyInterface;
109
use Magento\Sales\Api\Data\OrderInterface;
1110
use Magento\Sales\Model\Order;
1211
use Magento\Sales\Model\ValidatorInterface;
13-
use Magento\Framework\App\ObjectManager;
1412

15-
/**
16-
* Class CanRefund
17-
*/
1813
class CanRefund implements ValidatorInterface
1914
{
15+
use \Magento\Sales\Model\Order\Validation\CanRefundTrait;
16+
2017
/**
2118
* @var PriceCurrencyInterface
2219
*/
2320
private $priceCurrency;
2421

25-
/**
26-
* @var ScopeConfigInterface;
27-
*/
28-
private $scopeConfig;
29-
3022
/**
3123
* CanRefund constructor.
3224
*
3325
* @param PriceCurrencyInterface $priceCurrency
34-
* @param ScopeConfigInterface|null $scopeConfig
3526
*/
3627
public function __construct(
37-
PriceCurrencyInterface $priceCurrency,
38-
?ScopeConfigInterface $scopeConfig = null
28+
PriceCurrencyInterface $priceCurrency
3929
) {
4030
$this->priceCurrency = $priceCurrency;
41-
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
4231
}
4332

4433
/**
@@ -77,18 +66,4 @@ private function isTotalPaidEnoughForRefund(OrderInterface $order)
7766
$order->getTotalPaid() == 0 &&
7867
$this->isAllowZeroGrandTotal();
7968
}
80-
81-
/**
82-
* Return Zero GrandTotal availability.
83-
*
84-
* @return bool
85-
*/
86-
private function isAllowZeroGrandTotal()
87-
{
88-
$isAllowed = $this->scopeConfig->getValue(
89-
'sales/zerograndtotal_creditmemo/allow_zero_grandtotal',
90-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
91-
);
92-
return $isAllowed;
93-
}
9469
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Magento\Sales\Model\Order\Validation;
4+
5+
use Magento\Framework\App\ObjectManager;
6+
use Magento\Framework\App\Config\ScopeConfigInterface;
7+
8+
trait CanRefundTrait
9+
{
10+
/**
11+
* Return Zero GrandTotal availability.
12+
*
13+
* @return bool
14+
*/
15+
private function isAllowZeroGrandTotal()
16+
{
17+
$scopeConfig = ObjectManager::getInstance()->get(ScopeConfigInterface::class);
18+
$isAllowed = $scopeConfig->getValue(
19+
'sales/zerograndtotal_creditmemo/allow_zero_grandtotal',
20+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
21+
);
22+
return $isAllowed;
23+
}
24+
}

0 commit comments

Comments
 (0)