Passed
Pull Request — feature/ECO-948-renaming-and-r... (#7)
by Andrey
04:36 queued 01:50
created

UpdateAuthorizationStatusCommandPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 20 3
A addAddresses() 0 4 1
A isOrderClosed() 0 6 1
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AmazonPay\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\AmazonpayCallTransfer;
11
use Orm\Zed\Sales\Persistence\SpySalesOrder;
1 ignored issue
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\Oms\Business\Util\ReadOnlyArrayObject;
13
use SprykerEco\Shared\AmazonPay\AmazonPayConfig;
14
15
/**
16
 * @method \SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface getQueryContainer()
17
 * @method \SprykerEco\Zed\AmazonPay\Business\AmazonPayFacade getFacade
18
 */
19
class UpdateAuthorizationStatusCommandPlugin extends AbstractAmazonpayCommandPlugin
20
{
21
    /**
22
     * @param array $salesOrderItems
23
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
24
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
25
     *
26
     * @return array
27
     */
28
    public function run(array $salesOrderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
29
    {
30
        $amazonpayCallTransfers = $this->groupSalesOrderItemsByAuthId($salesOrderItems);
31
32
        foreach ($amazonpayCallTransfers as $amazonpayCallTransfer) {
33
            $this->addAddresses($amazonpayCallTransfer, $orderEntity);
34
            $updatedStatus = $this->getFacade()->updateAuthorizationStatus($amazonpayCallTransfer);
35
36
            if ($this->isOrderClosed($updatedStatus)) {
37
                $this->getFacade()->authorizeOrderItems($amazonpayCallTransfer);
38
            }
39
40
            $this->getFacade()->triggerEventForRelatedItems(
41
                $amazonpayCallTransfer,
42
                $data->getArrayCopy(),
43
                AmazonPayConfig::OMS_EVENT_UPDATE_AUTH_STATUS
44
            );
45
        }
46
47
        return [];
48
    }
49
50
    /**
51
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $updatedStatus
52
     *
53
     * @return bool
54
     */
55
    protected function isOrderClosed(AmazonpayCallTransfer $updatedStatus)
56
    {
57
        return $updatedStatus->getAmazonpayPayment()
58
            ->getAuthorizationDetails()
59
            ->getAuthorizationStatus()
60
            ->getState() === AmazonPayConfig::STATUS_CLOSED;
61
    }
62
63
    /**
64
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
65
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
66
     *
67
     * @return void
68
     */
69
    protected function addAddresses(AmazonpayCallTransfer $amazonpayCallTransfer, SpySalesOrder $orderEntity)
70
    {
71
        $amazonpayCallTransfer->setShippingAddress($this->buildAddressTransfer($orderEntity->getShippingAddress()))
72
            ->setBillingAddress($this->buildAddressTransfer($orderEntity->getBillingAddress()));
73
    }
74
}
75