Passed
Pull Request — dev (#9)
by Andrey
08:25 queued 04:31
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;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayCallTransfer 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 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
    public function execute(AmazonpayCallTransfer $amazonPayCallTransfer)
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