Passed
Pull Request — master (#4)
by Andrey
06:53 queued 03:48
created

ReauthorizeOrderTransaction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 40 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 ReauthorizeOrderTransaction 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->getAmazonpayPayment()
24
            ->getAuthorizationDetails()
25
            ->setAuthorizationReferenceId(
26
                $this->generateOperationReferenceId($amazonpayCallTransfer)
27
            );
28
29
        $amazonpayCallTransfer = parent::execute($amazonpayCallTransfer);
30
31
        if (!$this->apiResponse->getHeader()->getIsSuccess()) {
32
            return $amazonpayCallTransfer;
33
        }
34
35
        $isPartialProcessing = $this->isPartialProcessing($this->paymentEntity, $amazonpayCallTransfer);
36
37
        if ($isPartialProcessing && $this->paymentEntity->getStatus() !== AmazonpayConstants::OMS_STATUS_AUTH_PENDING) {
38
            $this->paymentEntity = $this->duplicatePaymentEntity($this->paymentEntity);
39
        }
40
41
        $amazonpayCallTransfer->getAmazonpayPayment()->setAuthorizationDetails(
42
            $this->apiResponse->getAuthorizationDetails()
43
        );
44
45
        $this->paymentEntity->setAmazonAuthorizationId(
46
            $this->apiResponse->getAuthorizationDetails()->getAmazonAuthorizationId()
47
        );
48
49
        $this->paymentEntity->setAuthorizationReferenceId(
50
            $this->apiResponse->getAuthorizationDetails()->getAuthorizationReferenceId()
51
        );
52
53
        $this->paymentEntity->setStatus(AmazonpayConstants::OMS_STATUS_AUTH_PENDING);
54
        $this->paymentEntity->save();
55
56
        if ($isPartialProcessing) {
57
            $this->assignAmazonpayPaymentToItemsIfNew($this->paymentEntity, $amazonpayCallTransfer);
58
        }
59
60
        return $amazonpayCallTransfer;
61
    }
62
63
}
64