Passed
Push — feature/eco-574/eco-2266-check... ( 7e1004...8cf5ab )
by Aleksey
04:15
created

AuthorizePlugin::getOrderWithPaymentTransfer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 10
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\AfterPayCallTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AfterPayCallTransfer 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 AuthorizePlugin 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
        $afterPayCallTransfer = $this->createAuthorizeCallTransfer($orderEntity);
37
        $this->getFacade()->authorizePayment($afterPayCallTransfer);
38
39
        return [];
40
    }
41
42
    /**
43
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
44
     *
45
     * @return \Generated\Shared\Transfer\AfterPayCallTransfer
46
     */
47
    protected function createAuthorizeCallTransfer(SpySalesOrder $orderEntity): AfterPayCallTransfer
48
    {
49
        $orderTransfer = $this->getOrderWithPaymentTransfer($orderEntity->getIdSalesOrder());
50
        return $this->getFactory()
51
            ->createOrderToCallConverter()
52
            ->convert($orderTransfer);
53
    }
54
55
    /**
56
     * @param int $idSalesOrder
57
     *
58
     * @return \Generated\Shared\Transfer\OrderTransfer
59
     */
60
    protected function getOrderWithPaymentTransfer(int $idSalesOrder): OrderTransfer
61
    {
62
        $orderTransfer = $this->getFactory()
63
            ->getSalesFacade()
64
            ->getOrderByIdSalesOrder($idSalesOrder);
65
66
        $orderTransfer = $this->hydrateAfterPayPayment($orderTransfer);
67
68
        return $orderTransfer;
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
73
     *
74
     * @return \Generated\Shared\Transfer\OrderTransfer
75
     */
76
    protected function hydrateAfterPayPayment(OrderTransfer $orderTransfer): OrderTransfer
77
    {
78
        $paymentTransfer = $this->getFacade()->getPaymentByIdSalesOrder($orderTransfer->getIdSalesOrder());
79
        $orderTransfer->setAfterPayPayment($paymentTransfer);
80
81
        return $orderTransfer;
82
    }
83
}
84