BaseTransaction   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaymentMethod() 0 3 1
A logInfo() 0 28 3
A getPaymentMethodByOrderId() 0 5 1
A fixResponseTransferTransactionId() 0 4 3
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\Ratepay\Business\Request\Payment\Handler\Transaction;
9
10
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...
11
use Generated\Shared\Transfer\RatepayResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RatepayResponseTransfer 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\Zed\Ratepay\Business\Request\TransactionHandlerAbstract;
13
14
abstract class BaseTransaction extends TransactionHandlerAbstract
15
{
16
    /**
17
     * @param int $orderId
18
     *
19
     * @return \Orm\Zed\Ratepay\Persistence\SpyPaymentRatepay
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Ratepay\Persistence\SpyPaymentRatepay 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...
20
     */
21
    protected function getPaymentMethodByOrderId($orderId)
22
    {
23
        return $this->queryContainer
24
            ->queryPayments()
25
            ->findByFkSalesOrder($orderId)->getFirst();
26
    }
27
28
    /**
29
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
30
     *
31
     * @return \Orm\Zed\Ratepay\Persistence\SpyPaymentRatepay
32
     */
33
    protected function getPaymentMethod(OrderTransfer $orderTransfer)
34
    {
35
        return $this->getPaymentMethodByOrderId($orderTransfer->requireIdSalesOrder()->getIdSalesOrder());
36
    }
37
38
    /**
39
     * According to the documentation the transaction ID is always returned, if it was sent, but it is not the fact for
40
     * error cases, therefore we have to set transaction ID, so it is not lost after each error.
41
     *
42
     * @param \Generated\Shared\Transfer\RatepayResponseTransfer $responseTransfer
43
     * @param string $transId
44
     * @param string $transShortId
45
     *
46
     * @return void
47
     */
48
    protected function fixResponseTransferTransactionId(RatepayResponseTransfer $responseTransfer, $transId, $transShortId)
49
    {
50
        if ($responseTransfer->getTransactionId() === '' && $transId !== '') {
51
            $responseTransfer->setTransactionId($transId)->setTransactionShortId($transShortId);
52
        }
53
    }
54
55
    /**
56
     * @param \SprykerEco\Zed\Ratepay\Business\Api\Model\Base $request
57
     * @param \SprykerEco\Zed\Ratepay\Business\Api\Model\Response\ResponseInterface $response
58
     * @param string $method
59
     * @param int|null $entityId
60
     * @param array $orderItems
61
     *
62
     * @return void
63
     */
64
    protected function logInfo($request, $response, $method, $entityId = null, $orderItems = [])
65
    {
66
        $headData = $request->getHead()->buildData();
67
68
        $context = [
69
            'order_id' => $entityId,
70
71
            'payment_method' => $method,
72
            'request_type' => static::TRANSACTION_TYPE,
73
            'request_transaction_id' => (isset($headData['transaction-id'])) ? $headData['transaction-id'] : null,
74
            'request_transaction_short_id' => (isset($headData['transaction-short-id'])) ? $headData['transaction-short-id'] : null,
75
            'request_body' => (string)$request,
76
77
            'response_type' => $response->getResponseType(),
78
            'response_result_code' => $response->getResultCode(),
79
            'response_result_text' => $response->getResultText(),
80
            'response_transaction_id' => $response->getTransactionId(),
81
            'response_transaction_short_id' => $response->getTransactionShortId(),
82
            'response_reason_code' => $response->getReasonCode(),
83
            'response_reason_text' => $response->getReasonText(),
84
            'response_status_code' => $response->getStatusCode(),
85
            'response_status_text' => $response->getStatusText(),
86
            'response_customer_message' => $response->getCustomerMessage(),
87
88
            'item_count' => count($orderItems),
89
        ];
90
91
        $this->getLogger()->info(static::TRANSACTION_TYPE, $context);
92
    }
93
}
94