Passed
Pull Request — feature/eco-3623/dev-payu-cee-... (#37)
by Roman
13:05 queued 08:05
created

CaptureHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
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 OrderTransfer $orderTransfer
33
     * @param ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment
34
     *
35
     * @return ComputopApiCaptureResponseTransfer
36
     */
37
    protected function performRequest(
38
        OrderTransfer $orderTransfer,
39
        ComputopApiHeaderPaymentTransfer $computopApiHeaderPayment
40
    ): ComputopApiCaptureResponseTransfer
41
    {
42
        $responseTransfer = $this->computopApiFacade->performInquireRequest($orderTransfer, $computopApiHeaderPayment);
43
        if ($responseTransfer->getIsCapLast() && $responseTransfer->getAmountCap() === $responseTransfer->getAmountAuth()) {
44
            return (new ComputopApiCaptureResponseTransfer())
45
                ->setHeader($responseTransfer->getHeader())
46
                ->setAmount($responseTransfer->getAmountCap())
47
                ->setErrorText($responseTransfer->getHeader()->getCode())
48
                ->setTransactionId($responseTransfer->getHeader()->getTransId());
49
        }
50
51
        return $this
52
            ->computopApiFacade
53
            ->performCaptureRequest($orderTransfer, $computopApiHeaderPayment);
54
    }
55
}
56