1 | <?php |
||
2 | /** |
||
3 | * Copyright © Wirecard Brasil. All rights reserved. |
||
4 | * |
||
5 | * @author Bruno Elisei <[email protected]> |
||
6 | * See COPYING.txt for license details. |
||
7 | */ |
||
8 | |||
9 | namespace Moip\Magento2\Gateway\Request; |
||
10 | |||
11 | use Magento\Payment\Gateway\Request\BuilderInterface; |
||
0 ignored issues
–
show
|
|||
12 | use Moip\Magento2\Gateway\Config\Config; |
||
13 | use Moip\Magento2\Gateway\Data\Order\OrderAdapterFactory; |
||
0 ignored issues
–
show
The type
Moip\Magento2\Gateway\Da...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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
14 | use Moip\Magento2\Gateway\SubjectReader; |
||
15 | |||
16 | /** |
||
17 | * Class TaxDocumentDataRequest - Fiscal document data structure. |
||
18 | */ |
||
19 | class TaxDocumentDataRequest implements BuilderInterface |
||
20 | { |
||
21 | /** |
||
22 | * BillingAddress block name. |
||
23 | */ |
||
24 | const TAX_DOCUMENT = 'taxDocument'; |
||
25 | |||
26 | /** |
||
27 | * The street address. Maximum 255 characters |
||
28 | * Required. |
||
29 | */ |
||
30 | const TAX_DOCUMENT_TYPE = 'type'; |
||
31 | |||
32 | /** |
||
33 | * The street number. 1 or 10 alphanumeric digits |
||
34 | * Required. |
||
35 | */ |
||
36 | const TAX_DOCUMENT_NUMBER = 'number'; |
||
37 | |||
38 | /** |
||
39 | * @var SubjectReader |
||
40 | */ |
||
41 | private $subjectReader; |
||
42 | |||
43 | /** |
||
44 | * @var OrderAdapterFactory |
||
45 | */ |
||
46 | private $orderAdapterFactory; |
||
47 | |||
48 | /** |
||
49 | * @var Config |
||
50 | */ |
||
51 | private $config; |
||
52 | |||
53 | /** |
||
54 | * @param SubjectReader $subjectReader |
||
55 | * @param OrderAdapterFactory $orderAdapterFactory |
||
56 | * @param Config $config |
||
57 | */ |
||
58 | public function __construct( |
||
59 | SubjectReader $subjectReader, |
||
60 | OrderAdapterFactory $orderAdapterFactory, |
||
61 | Config $config |
||
62 | ) { |
||
63 | $this->subjectReader = $subjectReader; |
||
64 | $this->orderAdapterFactory = $orderAdapterFactory; |
||
65 | $this->config = $config; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * get Value For Tax Document. |
||
70 | * |
||
71 | * @param $orderAdapter |
||
72 | * |
||
73 | * @return value |
||
0 ignored issues
–
show
The type
Moip\Magento2\Gateway\Request\value 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
74 | */ |
||
75 | public function getValueForTaxDocument($orderAdapter) |
||
76 | { |
||
77 | $obtainTaxDocFrom = $this->config->getAddtionalValue('type_cpf'); |
||
78 | |||
79 | if ($obtainTaxDocFrom === 'customer') { |
||
80 | $taxDocument = $orderAdapter->getCustomerTaxvat(); |
||
81 | $attTaxDocCus = $this->config->getAddtionalValue('cpf_for_customer'); |
||
82 | |||
83 | if ($attTaxDocCus !== 'taxvat') { |
||
84 | $taxDocument = $orderAdapter->getData($attTaxDocCus); |
||
85 | } |
||
86 | } else { |
||
87 | $taxDocument = $orderAdapter->getBillingAddress()->getVatId(); |
||
88 | $attTaxDocAddress = $this->config->getAddtionalValue('cpf_for_address'); |
||
89 | |||
90 | if ($attTaxDocAddress !== 'vat_id') { |
||
91 | $taxDocument = $orderAdapter->getBillingAddress()->getData($attTaxDocAddress); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | // * Contigência para caso não haja o atributo informado pelo Admin busque me 2 outros campos comuns. |
||
96 | if (!$taxDocument) { |
||
97 | $taxDocument = $orderAdapter->getBillingAddress()->getVatId(); |
||
98 | |||
99 | $obtainTaxDocFrom = $this->config->getAddtionalValue('type_cpf'); |
||
0 ignored issues
–
show
|
|||
100 | |||
101 | if (!$taxDocument) { |
||
102 | $taxDocument = $orderAdapter->getCustomerTaxvat(); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | return $taxDocument; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | public function build(array $buildSubject) |
||
113 | { |
||
114 | $paymentDO = $this->subjectReader->readPayment($buildSubject); |
||
115 | $payment = $paymentDO->getPayment(); |
||
116 | $taxDocument = null; |
||
117 | $typeDocument = 'CPF'; |
||
118 | $result = []; |
||
119 | $orderAdapter = $this->orderAdapterFactory->create( |
||
120 | ['order' => $payment->getOrder()] |
||
121 | ); |
||
122 | //* sobrescreve na order o documento caso seja capturado no formulario de pagamento |
||
123 | if ($payment->getAdditionalInformation('cc_holder_tax_document')) { |
||
124 | $taxDocument = $payment->getAdditionalInformation('cc_holder_tax_document'); |
||
125 | } |
||
126 | |||
127 | if ($payment->getAdditionalInformation('boleto_payer_tax_document')) { |
||
128 | $taxDocument = $payment->getAdditionalInformation('boleto_payer_tax_document'); |
||
129 | } |
||
130 | |||
131 | if (!$taxDocument) { |
||
132 | $taxDocument = $this->getValueForTaxDocument($orderAdapter); |
||
133 | } |
||
134 | |||
135 | $taxDocument = preg_replace('/[^0-9]/', '', $taxDocument); |
||
136 | |||
137 | if (strlen($taxDocument) === 14) { |
||
138 | $typeDocument = 'CNPJ'; |
||
139 | } |
||
140 | |||
141 | if ($typeDocument) { |
||
142 | $result[CustomerDataRequest::CUSTOMER][self::TAX_DOCUMENT] = [ |
||
143 | self::TAX_DOCUMENT_TYPE => $typeDocument, |
||
144 | self::TAX_DOCUMENT_NUMBER => $taxDocument, |
||
145 | ]; |
||
146 | } |
||
147 | |||
148 | return $result; |
||
149 | } |
||
150 | } |
||
151 |
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