1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © O2TI. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See COPYING.txt for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\SplitExampleMagento\Plugin\Getnet\PaymentMagento\Gateway\Request; |
10
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\Config; |
12
|
|
|
use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory; |
|
|
|
|
13
|
|
|
use Getnet\PaymentMagento\Gateway\Request\BoletoPaymentDataRequest; |
14
|
|
|
use Getnet\PaymentMagento\Gateway\SubjectReader; |
15
|
|
|
use Getnet\SplitExampleMagento\Helper\Data as SplitHelper; |
16
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Addtional Data Boleto Payment Data Request - add marketplace data in Transaction. |
20
|
|
|
*/ |
21
|
|
|
class AddtionalDataBoletoPaymentDataRequest |
22
|
|
|
{ |
23
|
|
|
public const GUARANTOR_DOCUMENT_TYPE = 'guarantor_document_type'; |
24
|
|
|
public const GUARANTOR_DOCUMENT_NUMBER = 'guarantor_document_number'; |
25
|
|
|
public const GUARANTOR_NAME = 'guarantor_name'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var SubjectReader |
29
|
|
|
*/ |
30
|
|
|
protected $subjectReader; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var OrderAdapterFactory |
34
|
|
|
*/ |
35
|
|
|
protected $orderAdapterFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Config |
39
|
|
|
*/ |
40
|
|
|
protected $config; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var SplitHelper; |
44
|
|
|
*/ |
45
|
|
|
protected $splitHelper; |
46
|
|
|
/** |
47
|
|
|
* @var ScopeConfigInterface |
48
|
|
|
*/ |
49
|
|
|
protected $scopeConfig; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param SubjectReader $subjectReader |
53
|
|
|
* @param OrderAdapterFactory $orderAdapterFactory |
54
|
|
|
* @param Config $config |
55
|
|
|
* @param SplitHelper $splitHelper |
56
|
|
|
* @param ScopeConfigInterface $scopeConfig |
57
|
|
|
*/ |
58
|
|
|
public function __construct( |
59
|
|
|
SubjectReader $subjectReader, |
60
|
|
|
OrderAdapterFactory $orderAdapterFactory, |
61
|
|
|
Config $config, |
62
|
|
|
SplitHelper $splitHelper, |
63
|
|
|
ScopeConfigInterface $scopeConfig |
64
|
|
|
) { |
65
|
|
|
$this->subjectReader = $subjectReader; |
66
|
|
|
$this->orderAdapterFactory = $orderAdapterFactory; |
67
|
|
|
$this->config = $config; |
68
|
|
|
$this->splitHelper = $splitHelper; |
69
|
|
|
$this->scopeConfig = $scopeConfig; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Around method Build. |
74
|
|
|
* |
75
|
|
|
* @param BoletoPaymentDataRequest $subject |
76
|
|
|
* @param \Closure $proceed |
77
|
|
|
* @param array $buildSubject |
78
|
|
|
* |
79
|
|
|
* @return mixin |
|
|
|
|
80
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
81
|
|
|
*/ |
82
|
|
|
public function aroundBuild( |
83
|
|
|
BoletoPaymentDataRequest $subject, |
|
|
|
|
84
|
|
|
\Closure $proceed, |
85
|
|
|
$buildSubject |
86
|
|
|
) { |
87
|
|
|
$result = $proceed($buildSubject); |
88
|
|
|
|
89
|
|
|
$paymentDO = $this->subjectReader->readPayment($buildSubject); |
90
|
|
|
|
91
|
|
|
$order = $paymentDO->getOrder(); |
92
|
|
|
|
93
|
|
|
$storeId = $order->getStoreId(); |
94
|
|
|
|
95
|
|
|
$items = $order->getItems(); |
96
|
|
|
|
97
|
|
|
$availlable = false; |
98
|
|
|
|
99
|
|
|
foreach ($items as $item) { |
100
|
|
|
if ($item->getProduct()->getGetnetSubSellerId()) { |
101
|
|
|
$availlable = true; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if (!$availlable) { |
106
|
|
|
return $result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$typeDocument = 'CPF'; |
110
|
|
|
|
111
|
|
|
$name = $this->splitHelper->getAdditionalGuarantorName($storeId); |
112
|
|
|
|
113
|
|
|
$document = $this->splitHelper->getAdditionalGuarantorNumber($storeId); |
114
|
|
|
|
115
|
|
|
$document = preg_replace('/[^0-9]/', '', $document); |
116
|
|
|
|
117
|
|
|
if (strlen($document) === 14) { |
118
|
|
|
$typeDocument = 'CNPJ'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$addtionalData = [ |
122
|
|
|
self::GUARANTOR_DOCUMENT_TYPE => $typeDocument, |
123
|
|
|
self::GUARANTOR_DOCUMENT_NUMBER => $document, |
124
|
|
|
self::GUARANTOR_NAME => $name, |
125
|
|
|
]; |
126
|
|
|
|
127
|
|
|
$result[BoletoPaymentDataRequest::METHOD] = array_merge( |
128
|
|
|
$result[BoletoPaymentDataRequest::METHOD], |
129
|
|
|
$addtionalData |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
return $result; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
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