AbstractPayoneRequestSender   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 18
c 0
b 0
f 0
dl 0
loc 67
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaymentEntity() 0 3 1
A getPaymentMethodMapper() 0 3 1
A __construct() 0 6 1
A initializeApiLog() 0 17 4
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\Payone\Business\Payment\RequestSender;
9
10
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone 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 Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog 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\Payone\Business\Api\Request\Container\AbstractRequestContainer;
13
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
14
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
15
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
16
use SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReaderInterface;
17
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface;
18
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
19
20
abstract class AbstractPayoneRequestSender
21
{
22
    /**
23
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
24
     */
25
    protected $queryContainer;
26
27
    /**
28
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReaderInterface
29
     */
30
    protected $paymentMapperReader;
31
32
    /**
33
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
34
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReaderInterface $paymentMapperReader
35
     */
36
    public function __construct(
37
        PayoneQueryContainerInterface $queryContainer,
38
        PaymentMapperReaderInterface $paymentMapperReader
39
    ) {
40
        $this->queryContainer = $queryContainer;
41
        $this->paymentMapperReader = $paymentMapperReader;
42
    }
43
44
    /**
45
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
46
     *
47
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
48
     */
49
    protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity): PaymentMethodMapperInterface
50
    {
51
        return $this->paymentMapperReader->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod());
52
    }
53
54
    /**
55
     * @param int $orderId
56
     *
57
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
58
     */
59
    protected function getPaymentEntity(int $orderId): SpyPaymentPayone
60
    {
61
        return $this->queryContainer->createPaymentById($orderId)->findOne();
62
    }
63
64
    /**
65
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
66
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
67
     *
68
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
69
     */
70
    protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container): SpyPaymentPayoneApiLog
71
    {
72
        $entity = new SpyPaymentPayoneApiLog();
73
74
        $entity->setSpyPaymentPayone($paymentEntity);
75
        $entity->setRequest($container->getRequest());
76
        $entity->setMode($container->getMode());
77
        $entity->setMerchantId($container->getMid());
78
        $entity->setPortalId($container->getPortalid());
79
        if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) {
80
            $entity->setSequenceNumber($container->getSequenceNumber());
81
        }
82
83
        $entity->setRawRequest(json_encode($container->toArray()));
84
        $entity->save();
85
86
        return $entity;
87
    }
88
}
89