Passed
Push — feature/eco-574/eco-2266-check... ( 290cb9...7b9234 )
by Aleksey
05:13
created

CapturePlugin::getItemTransfers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\AfterPay\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer 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 Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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 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...
13
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
14
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
15
use Spryker\Zed\Oms\Dependency\Plugin\Command\CommandByOrderInterface;
16
17
/**
18
 * @method \SprykerEco\Zed\AfterPay\Business\AfterPayFacadeInterface getFacade()
19
 * @method \SprykerEco\Zed\AfterPay\Communication\AfterPayCommunicationFactory getFactory()
20
 * @method \SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainer getQueryContainer()
21
 * @method \SprykerEco\Zed\AfterPay\AfterPayConfig getConfig()
22
 */
23
class CapturePlugin extends AbstractPlugin implements CommandByOrderInterface
24
{
25
    /**
26
     * @api
27
     *
28
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
29
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
30
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
31
     *
32
     * @return array
33
     */
34
    public function run(array $orderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data): array
35
    {
36
        $orderTransfer = $this->getOrderTransfer($orderEntity);
37
        $afterPayCallTransfer = $this->getFactory()
38
            ->createOrderToCallConverter()
39
            ->convert($orderTransfer);
40
41
        $items = $this->getItemTransfers($orderItems);
42
43
        $this->getFacade()->capturePayment($items, $afterPayCallTransfer);
44
45
        return [];
46
    }
47
48
    /**
49
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
50
     *
51
     * @return \Generated\Shared\Transfer\ItemTransfer[]
52
     */
53
    protected function getItemTransfers(array $orderItems): array
54
    {
55
        $items = [];
56
57
        foreach ($orderItems as $orderItem) {
58
            $itemTransfer = new ItemTransfer();
59
            $itemTransfer->fromArray($orderItem->toArray(), true);
60
            $itemTransfer->setUnitGrossPrice($orderItem->getGrossPrice());
61
            $itemTransfer->setUnitNetPrice($orderItem->getNetPrice());
62
            $itemTransfer->setUnitPriceToPayAggregation($orderItem->getPriceToPayAggregation());
63
            $itemTransfer->setUnitTaxAmountFullAggregation($orderItem->getTaxAmountFullAggregation());
64
            $items[] = $itemTransfer;
65
        }
66
67
        return $items;
68
    }
69
70
    /**
71
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $order
72
     *
73
     * @return \Generated\Shared\Transfer\OrderTransfer
74
     */
75
    protected function getOrderTransfer(SpySalesOrder $order): OrderTransfer
76
    {
77
        return $this->getFactory()
78
            ->getSalesFacade()
79
            ->getOrderByIdSalesOrder($order->getIdSalesOrder());
80
    }
81
}
82