Passed
Push — feature/ECO-808-scrutinizer ( 2323d6...94a2f0 )
by Andrey
02:58
created

CancelOrderTransaction::execute()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 6
nop 1
dl 0
loc 24
rs 8.5125
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\Business\Payment\Handler\Transaction;
9
10
use Generated\Shared\Transfer\AmazonpayCallTransfer;
11
use SprykerEco\Shared\Amazonpay\AmazonpayConstants;
12
13
class CancelOrderTransaction extends AbstractAmazonpayTransaction
14
{
15
16
    /**
17
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
18
     *
19
     * @return \Generated\Shared\Transfer\AmazonpayCallTransfer
20
     */
21
    public function execute(AmazonpayCallTransfer $amazonpayCallTransfer)
22
    {
23
        $amazonpayCallTransfer = parent::execute($amazonpayCallTransfer);
24
25
        if ($this->paymentEntity) {
26
            $isPartialProcessing = $this->isPartialProcessing($this->paymentEntity, $amazonpayCallTransfer);
27
28
            if (!$this->apiResponse->getHeader()->getIsSuccess()) {
29
                return $amazonpayCallTransfer;
30
            }
31
32
            if ($isPartialProcessing) {
33
                $this->paymentEntity = $this->duplicatePaymentEntity($this->paymentEntity);
34
            }
35
36
            $this->paymentEntity->setStatus(AmazonpayConstants::OMS_STATUS_CANCELLED);
37
            $this->paymentEntity->save();
38
39
            if ($isPartialProcessing) {
40
                $this->assignAmazonpayPaymentToItemsIfNew($this->paymentEntity, $amazonpayCallTransfer);
41
            }
42
        }
43
44
        return $amazonpayCallTransfer;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    protected function allowPartialProcessing()
51
    {
52
        return false;
53
    }
54
55
}
56