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
|
|||
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 Shippings Data Builder - Shippings structure. |
||
20 | */ |
||
21 | class ShippingsDataRequest implements BuilderInterface |
||
22 | { |
||
23 | /** |
||
24 | * Shipping block name. |
||
25 | */ |
||
26 | public const SHIPPINGS = 'shippings'; |
||
27 | |||
28 | /** |
||
29 | * Address block name. |
||
30 | */ |
||
31 | public const ADDRESS = 'address'; |
||
32 | |||
33 | /** |
||
34 | * The first name value must be less than or equal to 255 characters. |
||
35 | * Required. |
||
36 | */ |
||
37 | public const FIRST_NAME = 'first_name'; |
||
38 | |||
39 | /** |
||
40 | * The full name value must be less than or equal to 255 characters. |
||
41 | * Required. |
||
42 | */ |
||
43 | public const NAME = 'name'; |
||
44 | |||
45 | /** |
||
46 | * The customer’s email address. |
||
47 | * Required. |
||
48 | */ |
||
49 | public const EMAIL = 'email'; |
||
50 | |||
51 | /** |
||
52 | * Phone Number - block name. |
||
53 | */ |
||
54 | public const PHONE_NUMBER = 'phone_number'; |
||
55 | |||
56 | /** |
||
57 | * Shipping Amount block name. |
||
58 | */ |
||
59 | public const SHIPPING_AMOUNT = 'shipping_amount'; |
||
60 | /** |
||
61 | * @var SubjectReader |
||
62 | */ |
||
63 | private $subjectReader; |
||
64 | |||
65 | /** |
||
66 | * @var OrderAdapterFactory |
||
67 | */ |
||
68 | protected $orderAdapterFactory; |
||
69 | |||
70 | /** |
||
71 | * @var Config |
||
72 | */ |
||
73 | protected $config; |
||
74 | |||
75 | /** |
||
76 | * @param SubjectReader $subjectReader |
||
77 | * @param OrderAdapterFactory $orderAdapterFactory |
||
78 | * @param Config $config |
||
79 | */ |
||
80 | public function __construct( |
||
81 | SubjectReader $subjectReader, |
||
82 | OrderAdapterFactory $orderAdapterFactory, |
||
83 | Config $config |
||
84 | ) { |
||
85 | $this->subjectReader = $subjectReader; |
||
86 | $this->orderAdapterFactory = $orderAdapterFactory; |
||
87 | $this->config = $config; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Build. |
||
92 | * |
||
93 | * @param array $buildSubject |
||
94 | */ |
||
95 | public function build(array $buildSubject) |
||
96 | { |
||
97 | if (!isset($buildSubject['payment']) |
||
98 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface |
||
99 | ) { |
||
100 | throw new InvalidArgumentException('Payment data object should be provided'); |
||
101 | } |
||
102 | |||
103 | $paymentDO = $this->subjectReader->readPayment($buildSubject); |
||
104 | $payment = $paymentDO->getPayment(); |
||
105 | |||
106 | $result = []; |
||
107 | |||
108 | /** @var OrderAdapterFactory $orderAdapter * */ |
||
109 | $orderAdapter = $this->orderAdapterFactory->create( |
||
110 | ['order' => $payment->getOrder()] |
||
111 | ); |
||
112 | |||
113 | $shippingAddress = $orderAdapter->getShippingAddress(); |
||
114 | if ($shippingAddress) { |
||
115 | $name = $shippingAddress->getFirstname().' '.$shippingAddress->getLastname(); |
||
116 | |||
117 | $result[self::SHIPPINGS][] = [ |
||
118 | self::FIRST_NAME => $shippingAddress->getFirstname(), |
||
119 | self::NAME => $name, |
||
120 | self::EMAIL => $shippingAddress->getEmail(), |
||
121 | self::PHONE_NUMBER => preg_replace('/[^0-9]/', '', $shippingAddress->getTelephone()), |
||
122 | self::SHIPPING_AMOUNT => $this->config->formatPrice( |
||
123 | $orderAdapter->getShippingAmount() |
||
124 | ), |
||
125 | self::ADDRESS => [ |
||
126 | AddressDataRequest::POSTAL_CODE => preg_replace('/[^0-9]/', '', $shippingAddress->getPostcode()), |
||
127 | // phpcs:ignore Generic.Files.LineLength |
||
128 | AddressDataRequest::STREET => $this->config->getValueForAddress($shippingAddress, AddressDataRequest::STREET), |
||
129 | // phpcs:ignore Generic.Files.LineLength |
||
130 | AddressDataRequest::NUMBER => $this->config->getValueForAddress($shippingAddress, AddressDataRequest::NUMBER), |
||
131 | // phpcs:ignore Generic.Files.LineLength |
||
132 | AddressDataRequest::DISTRICT => $this->config->getValueForAddress($shippingAddress, AddressDataRequest::DISTRICT), |
||
133 | // phpcs:ignore Generic.Files.LineLength |
||
134 | AddressDataRequest::COMPLEMENT => $this->config->getValueForAddress($shippingAddress, AddressDataRequest::COMPLEMENT), |
||
135 | AddressDataRequest::LOCALITY => $shippingAddress->getCity(), |
||
136 | AddressDataRequest::STATE => $shippingAddress->getRegionCode(), |
||
137 | AddressDataRequest::COUNTRY_CODE => $shippingAddress->getCountryId(), |
||
138 | ], |
||
139 | ]; |
||
140 | } |
||
141 | |||
142 | return $result; |
||
143 | } |
||
144 | } |
||
145 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths