Completed
Pull Request — dev (#9)
by Andrey
07:05 queued 03:34
created

updateCallTransfer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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