FirstDataCaptureCommandByOrderPlugin::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 18
rs 9.9
cc 2
nc 2
nop 3
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\FirstData\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\FirstDataOmsCommandRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...sCommandRequestTransfer 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\FirstData\Business\FirstDataFacadeInterface getFacade()
18
 * @method \SprykerEco\Zed\FirstData\FirstDataConfig getConfig()
19
 * @method \SprykerEco\Zed\FirstData\Communication\FirstDataCommunicationFactory getFactory()
20
 */
21
class FirstDataCaptureCommandByOrderPlugin extends AbstractPlugin implements CommandByOrderInterface
22
{
23
    /**
24
     * {@inheritDoc}
25
     * - Makes PostAuthTransaction request to FirstData API and charges applicable items.
26
     * - Returns an error if the operation couldn't be executed successfully.
27
     * - Logs request's details to DB.
28
     * - Updates order items status into DB.
29
     *
30
     * @api
31
     *
32
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
33
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
34
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
35
     *
36
     * @return array
37
     */
38
    public function run(array $orderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data): array
39
    {
40
        $salesOrderItemIds = [];
41
        foreach ($orderItems as $salesOrderItemEntity) {
42
            $salesOrderItemIds[] = $salesOrderItemEntity->getIdSalesOrderItem();
43
        }
44
45
        $orderTransfer = $this->getFactory()
46
            ->getSalesFacade()
47
            ->getOrderByIdSalesOrder($orderEntity->getIdSalesOrder());
48
49
        $this->getFacade()->executeCaptureOmsCommand(
50
            (new FirstDataOmsCommandRequestTransfer())
51
                ->setOrder($orderTransfer)
52
                ->setSalesOrderItemIds($salesOrderItemIds)
53
        );
54
55
        return [];
56
    }
57
}
58