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

UpdateSuspendedOrderCommandPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 19 3
A getAffectingRequestedAmountItemsStateFlag() 0 3 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 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...
11
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
12
use SprykerEco\Shared\AmazonPay\AmazonPayConfig;
13
14
/**
15
 * @method \SprykerEco\Zed\AmazonPay\Business\AmazonPayFacadeInterface getFacade()
16
 */
17
class UpdateSuspendedOrderCommandPlugin extends AbstractAmazonpayCommandPlugin
18
{
19
    /**
20
     * @param array $salesOrderItems
21
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
22
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
23
     *
24
     * @return array
25
     */
26
    public function run(array $salesOrderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
27
    {
28
        $amazonpayCallTransfers = $this->groupSalesOrderItemsByAuthId($salesOrderItems);
29
30
        foreach ($amazonpayCallTransfers as $amazonpayCallTransfer) {
31
            $amazonpayCallTransfer->setRequestedAmount(
32
                $this->getRequestedAmountByOrderAndItems($orderEntity, $amazonpayCallTransfer->getItems())
33
            );
34
35
            if ($amazonpayCallTransfer->getAmazonpayPayment()->getStatus()
36
                === AmazonPayConfig::STATUS_PAYMENT_METHOD_CHANGED
37
            ) {
38
                $this->getFacade()->reauthorizeSuspendedOrder($amazonpayCallTransfer);
39
            }
40
41
            $this->getFacade()->captureOrder($amazonpayCallTransfer);
42
        }
43
44
        return [];
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    protected function getAffectingRequestedAmountItemsStateFlag()
51
    {
52
        return AmazonPayConfig::OMS_FLAG_NOT_AUTH;
53
    }
54
}
55