Passed
Pull Request — master (#41)
by Roman
08:34
created

CaptureHandler::performRequest()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 16
rs 9.9332
cc 3
nc 2
nop 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace;
9
10
use Generated\Shared\Transfer\ComputopApiCaptureResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...CaptureResponseTransfer 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 Generated\Shared\Transfer\ComputopApiHeaderPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...piHeaderPaymentTransfer 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...
12
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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...
13
14
class CaptureHandler extends AbstractHandler
15
{
16
    /**
17
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
18
     * @param \Generated\Shared\Transfer\ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment
19
     *
20
     * @return \Generated\Shared\Transfer\ComputopApiCaptureResponseTransfer
21
     */
22
    public function handle(OrderTransfer $orderTransfer, ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment)
23
    {
24
        $responseTransfer = $this->performRequest($orderTransfer, $computopApiHeaderPayment);
25
26
        $this->saver->save($responseTransfer, $orderTransfer);
27
28
        return $responseTransfer;
29
    }
30
31
    /**
32
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
33
     * @param \Generated\Shared\Transfer\ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment
34
     *
35
     * @return \Generated\Shared\Transfer\ComputopApiCaptureResponseTransfer
36
     */
37
    protected function performRequest(
38
        OrderTransfer $orderTransfer,
39
        ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment
40
    ): ComputopApiCaptureResponseTransfer {
41
        $responseTransfer = $this->computopApiFacade->performInquireRequest($orderTransfer, $computopApiHeaderPayment);
42
        if ($responseTransfer->getIsCapLast() && $responseTransfer->getAmountCap() === $responseTransfer->getAmountAuth()) {
43
            return (new ComputopApiCaptureResponseTransfer())
44
                ->setHeader($responseTransfer->getHeader())
45
                ->setAmount($responseTransfer->getAmountCap())
46
                ->setErrorText($responseTransfer->getHeader()->getCode())
47
                ->setTransactionId($responseTransfer->getHeader()->getTransId());
48
        }
49
50
        return $this
51
            ->computopApiFacade
52
            ->performCaptureRequest($orderTransfer, $computopApiHeaderPayment);
53
    }
54
}
55