Completed
Push — master ( 8f260e...cc8332 )
by Oleksandr
17s queued 14s
created

PartialRefundCommandPlugin::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 2
nop 3
dl 0
loc 16
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\PayonePartialOperationRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...perationRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
13
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
14
use Spryker\Zed\Oms\Dependency\Plugin\Command\CommandByOrderInterface;
15
16
/**
17
 * @method \SprykerEco\Zed\Payone\Communication\PayoneCommunicationFactory getFactory()
18
 * @method \SprykerEco\Zed\Payone\Business\PayoneFacadeInterface getFacade()
19
 */
20
class PartialRefundCommandPlugin extends AbstractPlugin implements CommandByOrderInterface
21
{
22
    /**
23
     * @api
24
     *
25
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
26
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
27
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
28
     *
29
     * @return array
30
     */
31
    public function run(array $orderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
32
    {
33
        $refundTransfer = $this->getFactory()->getRefundFacade()->calculateRefund($orderItems, $orderEntity);
34
        $orderTransfer = $this->getFactory()->getSalesFacade()->getOrderByIdSalesOrder($orderEntity->getIdSalesOrder());
35
36
        $payonePartialOperationTransfer = (new PayonePartialOperationRequestTransfer())
37
            ->setOrder($orderTransfer)
38
            ->setRefund($refundTransfer);
39
40
        foreach ($orderItems as $orderItem) {
41
            $payonePartialOperationTransfer->addSalesOrderItemId($orderItem->getIdSalesOrderItem());
42
        }
43
44
        $this->getFacade()->executePartialRefund($payonePartialOperationTransfer);
45
46
        return [];
47
    }
48
}
49