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\ConfigGetpay; |
13
|
|
|
use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory; |
|
|
|
|
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 Getpay Payment Data Request - Payment data structure for Getpay. |
21
|
|
|
*/ |
22
|
|
|
class GetpayPaymentDataRequest implements BuilderInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Payment - Block Name. |
26
|
|
|
*/ |
27
|
|
|
public const PAYMENT = 'payment'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Payment Credit - Block Name. |
31
|
|
|
*/ |
32
|
|
|
public const PAYMENT_CREDIT = 'credit'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Payment Credit Enable - Block Name. |
36
|
|
|
*/ |
37
|
|
|
public const PAYMENT_CREDIT_ENABLE = 'enable'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Payment Credit Installments - Block Name. |
41
|
|
|
*/ |
42
|
|
|
public const PAYMENT_CREDIT_INSTALLMENTS = 'max_installments'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Payment Debit - Block Name. |
46
|
|
|
*/ |
47
|
|
|
public const PAYMENT_DEBIT = 'debit'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Payment Debit Enable - Block Name. |
51
|
|
|
*/ |
52
|
|
|
public const PAYMENT_DEBIT_ENABLE = 'enable'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Payment Debit Caixa Virtual Card - Block Name. |
56
|
|
|
*/ |
57
|
|
|
public const PAYMENT_DEBIT_CAIXA = 'caixa_virtual_card'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Payment Pix - Block Name. |
61
|
|
|
*/ |
62
|
|
|
public const PAYMENT_PIX = 'pix'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Payment Debit Enable - Block Name. |
66
|
|
|
*/ |
67
|
|
|
public const PAYMENT_PIX_ENABLE = 'enable'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Payment Qr Code - Block Name. |
71
|
|
|
*/ |
72
|
|
|
public const PAYMENT_QR_CODE = 'qr_code'; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Payment Qr Code Enable - Block Name. |
76
|
|
|
*/ |
77
|
|
|
public const PAYMENT_QR_CODE_ENABLE = 'enable'; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var SubjectReader |
81
|
|
|
*/ |
82
|
|
|
protected $subjectReader; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var Config |
86
|
|
|
*/ |
87
|
|
|
protected $config; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var ConfigGetpay |
91
|
|
|
*/ |
92
|
|
|
protected $configGetpay; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param SubjectReader $subjectReader |
96
|
|
|
* @param Config $config |
97
|
|
|
* @param ConfigGetpay $configGetpay |
98
|
|
|
*/ |
99
|
|
|
public function __construct( |
100
|
|
|
SubjectReader $subjectReader, |
101
|
|
|
Config $config, |
102
|
|
|
ConfigGetpay $configGetpay |
103
|
|
|
) { |
104
|
|
|
$this->subjectReader = $subjectReader; |
105
|
|
|
$this->config = $config; |
106
|
|
|
$this->configGetpay = $configGetpay; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Build. |
111
|
|
|
* |
112
|
|
|
* @param array $buildSubject |
113
|
|
|
*/ |
114
|
|
|
public function build(array $buildSubject) |
115
|
|
|
{ |
116
|
|
|
if (!isset($buildSubject['payment']) |
117
|
|
|
|| !$buildSubject['payment'] instanceof PaymentDataObjectInterface |
118
|
|
|
) { |
119
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$paymentDO = $buildSubject['payment']; |
123
|
|
|
$order = $paymentDO->getOrder(); |
124
|
|
|
$storeId = $order->getStoreId(); |
125
|
|
|
$result = $this->getDataPaymetGetpay($storeId); |
126
|
|
|
|
127
|
|
|
return $result; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Data for Getpay. |
132
|
|
|
* |
133
|
|
|
* @param int $storeId |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function getDataPaymetGetpay($storeId) |
138
|
|
|
{ |
139
|
|
|
$instruction = []; |
140
|
|
|
|
141
|
|
|
$methods = $this->configGetpay->getAllowedMethods($storeId); |
142
|
|
|
|
143
|
|
|
$maxInstallments = $this->configGetpay->getMaxInstallments($storeId); |
144
|
|
|
|
145
|
|
|
if (in_array(self::PAYMENT_CREDIT, $methods)) { |
146
|
|
|
$instruction[self::PAYMENT][self::PAYMENT_CREDIT] = [ |
147
|
|
|
self::PAYMENT_CREDIT_ENABLE => true, |
148
|
|
|
self::PAYMENT_CREDIT_INSTALLMENTS => $maxInstallments, |
149
|
|
|
]; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
if (in_array(self::PAYMENT_DEBIT, $methods)) { |
153
|
|
|
$instruction[self::PAYMENT][self::PAYMENT_DEBIT] = [ |
154
|
|
|
self::PAYMENT_DEBIT_ENABLE => true |
155
|
|
|
]; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if (in_array(self::PAYMENT_PIX, $methods)) { |
159
|
|
|
$instruction[self::PAYMENT][self::PAYMENT_PIX] = [ |
160
|
|
|
self::PAYMENT_PIX_ENABLE => true |
161
|
|
|
]; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if (in_array(self::PAYMENT_QR_CODE, $methods)) { |
165
|
|
|
$instruction[self::PAYMENT][self::PAYMENT_QR_CODE] = [ |
166
|
|
|
self::PAYMENT_QR_CODE_ENABLE => true |
167
|
|
|
]; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return $instruction; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
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