Completed
Pull Request — master (#4)
by Andrey
16:33 queued 06:52
created

CancelOrderTransaction::execute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 5
nop 1
dl 0
loc 21
rs 9.0534
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
        $isPartialProcessing = $this->isPartialProcessing($this->paymentEntity, $amazonpayCallTransfer);
25
26
        if (!$this->apiResponse->getHeader()->getIsSuccess()) {
27
            return $amazonpayCallTransfer;
28
        }
29
30
        if ($isPartialProcessing) {
31
            $this->paymentEntity = $this->duplicatePaymentEntity($this->paymentEntity);
32
        }
33
34
        $this->paymentEntity->setStatus(AmazonpayConstants::OMS_STATUS_CANCELLED);
35
        $this->paymentEntity->save();
36
37
        if ($isPartialProcessing) {
38
            $this->assignAmazonpayPaymentToItemsIfNew($this->paymentEntity, $amazonpayCallTransfer);
39
        }
40
41
        return $amazonpayCallTransfer;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    protected function allowPartialProcessing()
48
    {
49
        return false;
50
    }
51
52
}
53