Completed
Pull Request — dev (#9)
by Andrey
07:12 queued 03:40
created

updatePaymentEntity()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 1
dl 0
loc 22
rs 8.9197
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 AuthorizeOrderIfRequiredTransaction extends ReauthorizeOrderTransaction
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->updatePaymentEntity($amazonPayCallTransfer);
29
30
        return $amazonPayCallTransfer;
31
    }
32
33
    /**
34
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
35
     *
36
     * @return bool
37
     */
38
    protected function isAllowed(AmazonpayCallTransfer $amazonPayCallTransfer)
39
    {
40
        if ($amazonPayCallTransfer->getAmazonpayPayment()
41
            ->getAuthorizationDetails()
42
            ->getAmazonAuthorizationId()) {
43
            return false;
44
        }
45
46
        if ($amazonPayCallTransfer->getAmazonpayPayment()->getCaptureDetails()
47
            && $amazonPayCallTransfer->getAmazonpayPayment()->getCaptureDetails()->getAmazonCaptureId()) {
48
            return false;
49
        }
50
51
        return true;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
56
     *
57
     * @return void
58
     */
59
    protected function updatePaymentEntity(AmazonpayCallTransfer $amazonPayCallTransfer)
60
    {
61
        if (!$this->isPaymentSuccess($amazonPayCallTransfer)) {
62
            return;
63
        }
64
65
        $isPartialProcessing = $this->isPartialProcessing($this->paymentEntity, $amazonPayCallTransfer);
66
67
        if ($isPartialProcessing) {
68
            $this->paymentEntity = $this->paymentProcessor->duplicatePaymentEntity($this->paymentEntity);
69
        }
70
71
        $this->paymentEntity->fromArray(
72
            $amazonPayCallTransfer->getAmazonpayPayment()
73
                ->getAuthorizationDetails()
74
                ->toArray()
75
        );
76
        $this->paymentEntity->setStatus(AmazonPayConfig::STATUS_PENDING);
77
        $this->paymentEntity->save();
78
79
        if ($isPartialProcessing) {
80
            $this->paymentProcessor->assignAmazonpayPaymentToItems($this->paymentEntity, $amazonPayCallTransfer);
81
        }
82
    }
83
}
84