Issues (139)

Request/CustomerBillingAddressDataRequest.php (1 issue)

Labels
Severity
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\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...
13
use Getnet\PaymentMagento\Gateway\SubjectReader;
14
use InvalidArgumentException;
15
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
16
use Magento\Payment\Gateway\Request\BuilderInterface;
17
18
/**
19
 * Class Customer Billing Address Data Builder - Customer Address structure.
20
 */
21
class CustomerBillingAddressDataRequest implements BuilderInterface
22
{
23
    /**
24
     * @var SubjectReader
25
     */
26
    protected $subjectReader;
27
28
    /**
29
     * @var OrderAdapterFactory
30
     */
31
    protected $orderAdapterFactory;
32
33
    /**
34
     * @var Config
35
     */
36
    protected $config;
37
38
    /**
39
     * @param SubjectReader       $subjectReader
40
     * @param OrderAdapterFactory $orderAdapterFactory
41
     * @param Config              $config
42
     */
43
    public function __construct(
44
        SubjectReader $subjectReader,
45
        OrderAdapterFactory $orderAdapterFactory,
46
        Config $config
47
    ) {
48
        $this->subjectReader = $subjectReader;
49
        $this->orderAdapterFactory = $orderAdapterFactory;
50
        $this->config = $config;
51
    }
52
53
    /**
54
     * Build.
55
     *
56
     * @param array $buildSubject
57
     */
58
    public function build(array $buildSubject)
59
    {
60
        if (!isset($buildSubject['payment'])
61
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
62
        ) {
63
            throw new InvalidArgumentException('Payment data object should be provided');
64
        }
65
66
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
67
        $payment = $paymentDO->getPayment();
68
69
        $result = [];
70
71
        /** @var OrderAdapterFactory $orderAdapter * */
72
        $orderAdapter = $this->orderAdapterFactory->create(
73
            ['order' => $payment->getOrder()]
74
        );
75
76
        $billingAddress = $orderAdapter->getBillingAddress();
77
        if ($billingAddress) {
78
            $result[CustomerDataRequest::CUSTOMER][AddressDataRequest::BILLING_ADDRESS] = [
79
                AddressDataRequest::POSTAL_CODE   => preg_replace('/[^0-9]/', '', $billingAddress->getPostcode()),
80
                // phpcs:ignore Generic.Files.LineLength
81
                AddressDataRequest::STREET        => $this->config->getValueForAddress($billingAddress, AddressDataRequest::STREET),
82
                // phpcs:ignore Generic.Files.LineLength
83
                AddressDataRequest::NUMBER        => $this->config->getValueForAddress($billingAddress, AddressDataRequest::NUMBER),
84
                // phpcs:ignore Generic.Files.LineLength
85
                AddressDataRequest::DISTRICT      => $this->config->getValueForAddress($billingAddress, AddressDataRequest::DISTRICT),
86
                // phpcs:ignore Generic.Files.LineLength
87
                AddressDataRequest::COMPLEMENT    => $this->config->getValueForAddress($billingAddress, AddressDataRequest::COMPLEMENT),
88
                AddressDataRequest::LOCALITY      => $billingAddress->getCity(),
89
                AddressDataRequest::STATE         => $billingAddress->getRegionCode(),
90
                AddressDataRequest::COUNTRY_CODE  => $billingAddress->getCountryId(),
91
            ];
92
        }
93
94
        return $result;
95
    }
96
}
97