AuthorizeTransaction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A writeAuthorizeResponse() 0 8 1
A logTransaction() 0 9 1
A executeTransaction() 0 7 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\AfterPay\Business\Payment\Transaction;
9
10
use Generated\Shared\Transfer\AfterPayApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rPayApiResponseTransfer 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\AfterPayAuthorizeRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...uthorizeRequestTransfer 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 SprykerEco\Shared\AfterPay\AfterPayConfig;
13
use SprykerEco\Zed\AfterPay\Business\Api\Adapter\AdapterInterface;
14
use SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Authorize\PaymentAuthorizeWriterInterface;
15
use SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Logger\TransactionLoggerInterface;
16
17
class AuthorizeTransaction implements AuthorizeTransactionInterface
18
{
19
    public const TRANSACTION_TYPE = AfterPayConfig::TRANSACTION_TYPE_AUTHORIZE;
20
21
    /**
22
     * @var \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Logger\TransactionLoggerInterface
23
     */
24
    protected $transactionLogger;
25
26
    /**
27
     * @var \SprykerEco\Zed\AfterPay\Business\Api\Adapter\AdapterInterface
28
     */
29
    protected $apiAdapter;
30
31
    /**
32
     * @var \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Authorize\PaymentAuthorizeWriterInterface
33
     */
34
    protected $paymentAuthorizeWriter;
35
36
    /**
37
     * @param \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Logger\TransactionLoggerInterface $transactionLogger
38
     * @param \SprykerEco\Zed\AfterPay\Business\Api\Adapter\AdapterInterface $apiAdapter
39
     * @param \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\Authorize\PaymentAuthorizeWriterInterface $paymentAuthorizeWriter
40
     */
41
    public function __construct(
42
        TransactionLoggerInterface $transactionLogger,
43
        AdapterInterface $apiAdapter,
44
        PaymentAuthorizeWriterInterface $paymentAuthorizeWriter
45
    ) {
46
        $this->transactionLogger = $transactionLogger;
47
        $this->apiAdapter = $apiAdapter;
48
        $this->paymentAuthorizeWriter = $paymentAuthorizeWriter;
49
    }
50
51
    /**
52
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
53
     *
54
     * @return \Generated\Shared\Transfer\AfterPayApiResponseTransfer
55
     */
56
    public function executeTransaction(AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer): AfterPayApiResponseTransfer
57
    {
58
        $authorizeResponseTransfer = $this->apiAdapter->sendAuthorizationRequest($authorizeRequestTransfer);
59
        $this->logTransaction($authorizeRequestTransfer, $authorizeResponseTransfer);
60
        $this->writeAuthorizeResponse($authorizeRequestTransfer, $authorizeResponseTransfer);
61
62
        return $authorizeResponseTransfer;
63
    }
64
65
    /**
66
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
67
     * @param \Generated\Shared\Transfer\AfterPayApiResponseTransfer $authorizeResponseTransfer
68
     *
69
     * @return void
70
     */
71
    protected function logTransaction(
72
        AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer,
73
        AfterPayApiResponseTransfer $authorizeResponseTransfer
74
    ): void {
75
        $this->transactionLogger->logTransaction(
76
            static::TRANSACTION_TYPE,
77
            $authorizeRequestTransfer->getOrder()->getNumber(),
78
            $authorizeRequestTransfer,
79
            $authorizeResponseTransfer,
80
        );
81
    }
82
83
    /**
84
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
85
     * @param \Generated\Shared\Transfer\AfterPayApiResponseTransfer $authorizeResponseTransfer
86
     *
87
     * @return void
88
     */
89
    protected function writeAuthorizeResponse(
90
        AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer,
91
        AfterPayApiResponseTransfer $authorizeResponseTransfer
92
    ): void {
93
        $this->paymentAuthorizeWriter->save(
94
            $authorizeRequestTransfer->getOrder()->getNumber(),
95
            $authorizeResponseTransfer->getReservationId(),
96
            $authorizeResponseTransfer->getCheckoutId(),
97
        );
98
    }
99
}
100