Completed
Pull Request — master (#29)
by Volodymyr
11:29 queued 04:09
created

AuthorizeOrderCommandPlugin::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 11
rs 10
c 1
b 0
f 0
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;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayCallTransfer 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;
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\Business\AmazonPayFacadeInterface getFacade()
17
 */
18
class AuthorizeOrderCommandPlugin extends AbstractAmazonpayCommandPlugin
19
{
20
    /**
21
     * {@inheritdoc}
22
     * - Uses API adapter for sending a request to Amazon for order authorization operation.
23
     *
24
     * @api
25
     *
26
     * @param array $salesOrderItems
27
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
28
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
29
     *
30
     * @return array
31
     */
32
    public function run(array $salesOrderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data): array
33
    {
34
        $amazonpayCallTransfers = $this->groupSalesOrderItemsByAuthId($salesOrderItems);
35
        $customerEmail = $orderEntity->getEmail() ?? $orderEntity->getCustomer()->getEmail();
36
37
        foreach ($amazonpayCallTransfers as $amazonpayCallTransfer) {
38
            $this->updateCallTransfer($amazonpayCallTransfer, $orderEntity, $customerEmail);
39
            $this->getFacade()->authorizeOrderItems($amazonpayCallTransfer);
40
        }
41
42
        return [];
43
    }
44
45
    /**
46
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
47
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
48
     * @param string $customerEmail
49
     *
50
     * @return \Generated\Shared\Transfer\AmazonpayCallTransfer
51
     */
52
    protected function updateCallTransfer(
53
        AmazonpayCallTransfer $amazonpayCallTransfer,
54
        SpySalesOrder $orderEntity,
55
        string $customerEmail
56
    ): AmazonpayCallTransfer {
57
        $amazonpayCallTransfer->setShippingAddress($this->buildAddressTransfer($orderEntity->getShippingAddress()))
58
            ->setBillingAddress($this->buildAddressTransfer($orderEntity->getBillingAddress()));
59
        $amazonpayCallTransfer->setEmail($customerEmail);
60
        $amazonpayCallTransfer->setRequestedAmount(
61
            $this->getRequestedAmountByOrderAndItems($orderEntity, $amazonpayCallTransfer->getItems())
62
        );
63
64
        return $amazonpayCallTransfer;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    protected function getAffectingRequestedAmountItemsStateFlag(): string
71
    {
72
        return AmazonPayConfig::OMS_FLAG_NOT_AUTH;
73
    }
74
}
75