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\ConfigInterface; |
|
|
|
|
12
|
|
|
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
|
|
|
|
13
|
|
|
use Magento\Payment\Gateway\Request\BuilderInterface; |
|
|
|
|
14
|
|
|
use Moip\Magento2\Gateway\Config\Config; |
15
|
|
|
use Moip\Magento2\Model\Ui\ConfigProviderBoleto; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RefundRequest - Refund data structure. |
19
|
|
|
*/ |
20
|
|
|
class RefundRequest implements BuilderInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Moip Order Id |
24
|
|
|
*/ |
25
|
|
|
const MOIP_ORDER_ID = 'moip_order_id'; |
26
|
|
|
|
27
|
|
|
const BANK_NUMBER = 'moip_magento2_boleto_bank_number'; |
28
|
|
|
|
29
|
|
|
const AGENCY_NUMBER = 'moip_magento2_boleto_agency_number'; |
30
|
|
|
|
31
|
|
|
const AGENCY_CHECK_NUMBER = 'moip_magento2_boleto_agency_check_number'; |
32
|
|
|
|
33
|
|
|
const ACCOUNT_NUMBER = 'moip_magento2_boleto_account_number'; |
34
|
|
|
|
35
|
|
|
const ACCOUNT_CHECK_NUMBER = 'moip_magento2_boleto_account_check_number'; |
36
|
|
|
|
37
|
|
|
const HOLDER_FULLNAME = 'moip_magento2_boleto_account_holder_fullname'; |
38
|
|
|
|
39
|
|
|
const HOLDER_DOCUMENT_NUMBER = 'moip_magento2_boleto_account_holder_document_number'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ConfigInterface |
43
|
|
|
*/ |
44
|
|
|
private $config; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var Config |
48
|
|
|
*/ |
49
|
|
|
private $configPayment; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ConfigInterface $config |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
ConfigInterface $config, |
56
|
|
|
Config $configPayment |
57
|
|
|
) { |
58
|
|
|
$this->config = $config; |
59
|
|
|
$this->configPayment = $configPayment; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function build(array $buildSubject) |
66
|
|
|
{ |
67
|
|
|
if (!isset($buildSubject['payment']) |
68
|
|
|
|| !$buildSubject['payment'] instanceof PaymentDataObjectInterface |
69
|
|
|
) { |
70
|
|
|
throw new \InvalidArgumentException('Payment data object should be provided'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$result = []; |
|
|
|
|
74
|
|
|
|
75
|
|
|
$paymentDO = $buildSubject['payment']; |
76
|
|
|
|
77
|
|
|
$payment = $paymentDO->getPayment(); |
78
|
|
|
|
79
|
|
|
$order = $payment->getOrder(); |
80
|
|
|
|
81
|
|
|
$creditmemo = $payment->getCreditMemo(); |
82
|
|
|
|
83
|
|
|
$total = $creditmemo->getGrandTotal(); |
84
|
|
|
|
85
|
|
|
$result = [ |
86
|
|
|
self::MOIP_ORDER_ID => $order->getExtOrderId(), |
87
|
|
|
'send' => [ |
88
|
|
|
'amount' => $this->configPayment->formatPrice($total), |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
|
92
|
|
|
if ($order->getPayment()->getMethodInstance()->getCode() === ConfigProviderBoleto::CODE) { |
93
|
|
|
$bankNumber = $creditmemo->getData(self::BANK_NUMBER); |
94
|
|
|
$agencyNumber = $creditmemo->getData(self::AGENCY_NUMBER); |
95
|
|
|
$agencyCheckNumber = $creditmemo->getData(self::AGENCY_CHECK_NUMBER); |
96
|
|
|
$accountNumber = $creditmemo->getData(self::ACCOUNT_NUMBER); |
97
|
|
|
$accountCheckNumber = $creditmemo->getData(self::ACCOUNT_CHECK_NUMBER); |
98
|
|
|
$holderFullname = $creditmemo->getData(self::HOLDER_FULLNAME); |
99
|
|
|
$holderDocumment = $creditmemo->getData(self::HOLDER_DOCUMENT_NUMBER); |
100
|
|
|
|
101
|
|
|
$typeDocument = 'CPF'; |
102
|
|
|
$taxDocument = preg_replace('/[^0-9]/', '', $holderDocumment); |
103
|
|
|
if (strlen($taxDocument) === 14) { |
104
|
|
|
$typeDocument = 'CNPJ'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$resultBoleto = [ |
108
|
|
|
'send' => [ |
109
|
|
|
'amount' => $this->configPayment->formatPrice($total), |
110
|
|
|
'refundingInstrument' => [ |
111
|
|
|
'method' => 'BANK_ACCOUNT', |
112
|
|
|
'bankAccount' => [ |
113
|
|
|
'type' => 'CHECKING', |
114
|
|
|
'bankNumber' => $bankNumber, |
115
|
|
|
'agencyNumber' => $agencyNumber, |
116
|
|
|
'agencyCheckNumber' => $agencyCheckNumber, |
117
|
|
|
'accountNumber' => $accountNumber, |
118
|
|
|
'accountCheckNumber' => $accountCheckNumber, |
119
|
|
|
'holder' => [ |
120
|
|
|
'fullname' => $holderFullname, |
121
|
|
|
'taxDocument' => [ |
122
|
|
|
'type' => $typeDocument, |
123
|
|
|
'number' => $taxDocument, |
124
|
|
|
], |
125
|
|
|
], |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
], |
129
|
|
|
]; |
130
|
|
|
|
131
|
|
|
$result = array_merge($result, $resultBoleto); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $result; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
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