Passed
Push — feature/ECO-807-travis-ci ( 7b7181...a6fc91 )
by Andrey
03:17
created

CancelOrderTransaction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A allowPartialProcessing() 0 3 1
B execute() 0 24 5
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