Issues (139)

Gateway/Request/OrderDataRequest.php (2 issues)

1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Gateway\Request;
10
11
use Getnet\PaymentMagento\Gateway\Config\Config;
12
use Getnet\PaymentMagento\Gateway\Config\ConfigCc;
13
use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory;
0 ignored issues
show
The type Getnet\PaymentMagento\Ga...der\OrderAdapterFactory 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...
14
use Getnet\PaymentMagento\Gateway\SubjectReader;
15
use InvalidArgumentException;
16
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
17
use Magento\Payment\Gateway\Request\BuilderInterface;
18
19
/**
20
 * Class Order Data Request - Payment amount structure.
21
 */
22
class OrderDataRequest implements BuilderInterface
23
{
24
    /**
25
     * Order block name.
26
     */
27
    public const ORDER = 'order';
28
29
    /**
30
     * Order Id Block Name.
31
     */
32
    public const ORDER_ID = 'order_id';
33
34
    /**
35
     * Sales Tax Block Name.
36
     */
37
    public const SALES_TAX = 'sales_tax';
38
39
    /**
40
     * @var SubjectReader
41
     */
42
    protected $subjectReader;
43
44
    /**
45
     * @var OrderAdapterFactory
46
     */
47
    protected $orderAdapterFactory;
48
49
    /**
50
     * @var Config
51
     */
52
    protected $config;
53
54
    /**
55
     * @var ConfigCc
56
     */
57
    protected $configCc;
58
59
    /**
60
     * @param SubjectReader       $subjectReader
61
     * @param OrderAdapterFactory $orderAdapterFactory
62
     * @param Config              $config
63
     * @param ConfigCc            $configCc
64
     */
65
    public function __construct(
66
        SubjectReader $subjectReader,
67
        OrderAdapterFactory $orderAdapterFactory,
68
        Config $config,
69
        ConfigCc $configCc
70
    ) {
71
        $this->subjectReader = $subjectReader;
72
        $this->orderAdapterFactory = $orderAdapterFactory;
73
        $this->config = $config;
74
        $this->configCc = $configCc;
75
    }
76
77
    /**
78
     * Build.
79
     *
80
     * @param array $buildSubject
81
     */
82
    public function build(array $buildSubject)
83
    {
84
        if (!isset($buildSubject['payment'])
85
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
86
        ) {
87
            throw new InvalidArgumentException('Payment data object should be provided');
88
        }
89
90
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
91
        $payment = $paymentDO->getPayment();
92
93
        $result = [];
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
94
95
        /** @var OrderAdapterFactory $orderAdapter * */
96
        $orderAdapter = $this->orderAdapterFactory->create(
97
            ['order' => $payment->getOrder()]
98
        );
99
100
        $order = $paymentDO->getOrder();
101
102
        $result = [
103
            self::ORDER => [
104
                self::ORDER_ID  => $order->getOrderIncrementId(),
105
                self::SALES_TAX => $this->config->formatPrice($orderAdapter->getTaxAmount()),
106
            ],
107
        ];
108
109
        return $result;
110
    }
111
}
112