Passed
Branch feature/ECO-965-refactoring (c9cdee)
by Andrey
06:34 queued 01:51
created

updatePayment()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 5
nop 1
dl 0
loc 32
rs 8.439
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\AmazonPayConfig;
12
13
class UpdateOrderAuthorizationStatusTransaction extends AbstractAmazonpayTransaction
14
{
15
    /**
16
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
17
     *
18
     * @return \Generated\Shared\Transfer\AmazonpayCallTransfer
19
     */
20 View Code Duplication
    public function execute(AmazonpayCallTransfer $amazonPayCallTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        if (!$this->isAllowed($amazonPayCallTransfer)) {
23
            return $amazonPayCallTransfer;
24
        }
25
26
        $amazonPayCallTransfer = parent::execute($amazonPayCallTransfer);
27
28
        $this->updatePayment($amazonPayCallTransfer);
29
30
        return $amazonPayCallTransfer;
31
    }
32
33
    /**
34
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
35
     *
36
     * @return void
37
     */
38
    protected function updatePayment(AmazonpayCallTransfer $amazonPayCallTransfer)
39
    {
40
        if (!$this->isPaymentSuccess($amazonPayCallTransfer)) {
41
            return;
42
        }
43
44
        $amazonPayment = $amazonPayCallTransfer->getAmazonpayPayment();
45
        $status = $amazonPayment->getAuthorizationDetails()->getAuthorizationStatus();
46
47
        if ($amazonPayment->getAuthorizationDetails()->getIdList()) {
48
            $this->paymentEntity->setAmazonCaptureId(
49
                $amazonPayment->getAuthorizationDetails()->getIdList()
50
            )
51
                ->setStatus($status->getState())
52
                ->save();
53
54
            return;
55
        }
56
57
        if ($status->getState() === AmazonPayConfig::STATUS_PENDING) {
58
            return;
59
        }
60
61
        $this->paymentEntity->setStatus($status->getState());
62
        if ($this->apiResponse->getCaptureDetails() &&
63
            $this->apiResponse->getCaptureDetails()->getAmazonCaptureId()) {
64
            $this->paymentEntity->setAmazonCaptureId(
65
                $this->apiResponse->getCaptureDetails()->getAmazonCaptureId()
66
            );
67
        }
68
69
        $this->paymentEntity->save();
70
    }
71
72
    /**
73
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
74
     *
75
     * @return bool
76
     */
77
    protected function isAllowed(AmazonpayCallTransfer $amazonPayCallTransfer)
78
    {
79
        return $amazonPayCallTransfer->getAmazonpayPayment()
80
            ->getAuthorizationDetails()
81
            ->getAmazonAuthorizationId() !== null;
82
    }
83
}
84