AuthorizePlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 16
dl 0
loc 64
rs 10
c 1
b 1
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrderWithPaymentTransfer() 0 9 1
A hydrateAfterPayPayment() 0 6 1
A createAuthorizeCallTransfer() 0 7 1
A run() 0 6 1
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
     * {@inheritDoc}
27
     * - Sends payment `authorize` request to AfterPay gateway.
28
     * - Saves the transaction result in Quote for future recognition.
29
     *
30
     * @api
31
     *
32
     * @param array<\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
        $afterPayCallTransfer = $this->createAuthorizeCallTransfer($orderEntity);
41
        $this->getFacade()->authorizePayment($afterPayCallTransfer);
42
43
        return [];
44
    }
45
46
    /**
47
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
48
     *
49
     * @return \Generated\Shared\Transfer\AfterPayCallTransfer
50
     */
51
    protected function createAuthorizeCallTransfer(SpySalesOrder $orderEntity): AfterPayCallTransfer
52
    {
53
        $orderTransfer = $this->getOrderWithPaymentTransfer($orderEntity->getIdSalesOrder());
54
55
        return $this->getFactory()
56
            ->createOrderToCallConverter()
57
            ->convert($orderTransfer);
58
    }
59
60
    /**
61
     * @param int $idSalesOrder
62
     *
63
     * @return \Generated\Shared\Transfer\OrderTransfer
64
     */
65
    protected function getOrderWithPaymentTransfer(int $idSalesOrder): OrderTransfer
66
    {
67
        $orderTransfer = $this->getFactory()
68
            ->getSalesFacade()
69
            ->getOrderByIdSalesOrder($idSalesOrder);
70
71
        $orderTransfer = $this->hydrateAfterPayPayment($orderTransfer);
72
73
        return $orderTransfer;
74
    }
75
76
    /**
77
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
78
     *
79
     * @return \Generated\Shared\Transfer\OrderTransfer
80
     */
81
    protected function hydrateAfterPayPayment(OrderTransfer $orderTransfer): OrderTransfer
82
    {
83
        $paymentTransfer = $this->getFacade()->getPaymentByIdSalesOrder($orderTransfer->getIdSalesOrder());
84
        $orderTransfer->setAfterPayPayment($paymentTransfer);
85
86
        return $orderTransfer;
87
    }
88
}
89