Passed
Push — feature/eco-2635-amazon-psd2-a... ( 8e9b65...4e5619 )
by Volodymyr
05:08
created

getAffectingRequestedAmountItemsStateFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
     * @api
22
     *
23
     * @param array $salesOrderItems
24
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
25
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
26
     *
27
     * @return array
28
     */
29
    public function run(array $salesOrderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
30
    {
31
        $amazonpayCallTransfers = $this->groupSalesOrderItemsByAuthId($salesOrderItems);
32
        $customerEmail = $orderEntity->getEmail() ?? $orderEntity->getCustomer()->getEmail();
33
34
        foreach ($amazonpayCallTransfers as $amazonpayCallTransfer) {
35
            $this->updateCallTransfer($amazonpayCallTransfer, $orderEntity, $customerEmail);
36
            $this->getFacade()->authorizeOrderItems($amazonpayCallTransfer);
37
        }
38
39
        return [];
40
    }
41
42
    /**
43
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
44
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
45
     * @param string $customerEmail
46
     *
47
     * @return void
48
     */
49
    protected function updateCallTransfer(AmazonpayCallTransfer $amazonpayCallTransfer, SpySalesOrder $orderEntity, $customerEmail)
50
    {
51
        $amazonpayCallTransfer->setShippingAddress($this->buildAddressTransfer($orderEntity->getShippingAddress()))
52
            ->setBillingAddress($this->buildAddressTransfer($orderEntity->getBillingAddress()));
53
        $amazonpayCallTransfer->setEmail($customerEmail);
54
        $amazonpayCallTransfer->setRequestedAmount(
55
            $this->getRequestedAmountByOrderAndItems($orderEntity, $amazonpayCallTransfer->getItems())
56
        );
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    protected function getAffectingRequestedAmountItemsStateFlag()
63
    {
64
        return AmazonPayConfig::OMS_FLAG_NOT_AUTH;
65
    }
66
}
67