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
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Getnet\PaymentMagento\Console\Command\Marketplace; |
12
|
|
|
|
13
|
|
|
use Getnet\PaymentMagento\Model\Console\Command\Marketplace\PaymentRelease; |
14
|
|
|
use Magento\Framework\App\State; |
15
|
|
|
use Symfony\Component\Console\Command\Command; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Payment Release with Getnet. |
22
|
|
|
*/ |
23
|
|
|
class Release extends Command |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @const string. |
27
|
|
|
*/ |
28
|
|
|
public const ORDER_ID = 'order-id'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @const string. |
32
|
|
|
*/ |
33
|
|
|
public const SUB_SELLER_ID = 'sub-seller-id'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @const string. |
37
|
|
|
*/ |
38
|
|
|
public const DATE = 'date'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var PaymentRelease |
42
|
|
|
*/ |
43
|
|
|
protected $paymentRelease; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var State |
47
|
|
|
*/ |
48
|
|
|
protected $state; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\DateTime |
52
|
|
|
*/ |
53
|
|
|
protected $date; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var Magento\Framework\Stdlib\DateTime\TimezoneInterface |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
protected $timezone; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param State $state |
62
|
|
|
* @param PaymentRelease $paymentRelease |
63
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date |
64
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
65
|
|
|
*/ |
66
|
|
|
public function __construct( |
67
|
|
|
State $state, |
68
|
|
|
PaymentRelease $paymentRelease, |
69
|
|
|
\Magento\Framework\Stdlib\DateTime\DateTime $date, |
70
|
|
|
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
71
|
|
|
) { |
72
|
|
|
$this->state = $state; |
73
|
|
|
$this->paymentRelease = $paymentRelease; |
74
|
|
|
$this->date = $date; |
75
|
|
|
$this->timezone = $timezone; |
|
|
|
|
76
|
|
|
parent::__construct(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Execute. |
81
|
|
|
* |
82
|
|
|
* @param InputInterface $input |
83
|
|
|
* @param OutputInterface $output |
84
|
|
|
*/ |
85
|
|
|
protected function execute( |
86
|
|
|
InputInterface $input, |
87
|
|
|
OutputInterface $output |
88
|
|
|
) { |
89
|
|
|
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); |
90
|
|
|
$this->paymentRelease->setOutput($output); |
91
|
|
|
|
92
|
|
|
$orderId = (int) $input->getArgument(self::ORDER_ID); |
93
|
|
|
|
94
|
|
|
$subSellerId = $input->getArgument(self::SUB_SELLER_ID); |
95
|
|
|
|
96
|
|
|
$date = $input->getArgument(self::DATE); |
97
|
|
|
$date = $this->convertDate($date); |
98
|
|
|
|
99
|
|
|
$this->paymentRelease->create($orderId, $date, $subSellerId); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Configure. |
104
|
|
|
* |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
|
|
protected function configure() |
108
|
|
|
{ |
109
|
|
|
$this->setName('getnet:marketplace:payment_release'); |
110
|
|
|
$this->setDescription('Release of payment to the sub-seller on Getnet'); |
111
|
|
|
$this->setDefinition( |
112
|
|
|
[ |
113
|
|
|
new InputArgument(self::ORDER_ID, InputArgument::REQUIRED, 'Order Id'), |
114
|
|
|
new InputArgument(self::DATE, InputArgument::OPTIONAL, 'Date'), |
115
|
|
|
new InputArgument(self::SUB_SELLER_ID, InputArgument::OPTIONAL, 'Sub Seller Id Getnet (id ext)'), |
116
|
|
|
] |
117
|
|
|
); |
118
|
|
|
parent::configure(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Convert Date. |
123
|
|
|
* |
124
|
|
|
* @param string|null $date |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function convertDate(string $date = null): string |
129
|
|
|
{ |
130
|
|
|
if ($date) { |
131
|
|
|
$date = str_replace('/', '-', $date); |
132
|
|
|
$defaultTimezone = $this->timezone->getDefaultTimezone(); |
133
|
|
|
$configTimezone = $this->timezone->getConfigTimezone(); |
134
|
|
|
$date = new \DateTime($date, new \DateTimeZone($configTimezone)); |
135
|
|
|
$date->setTimezone(new \DateTimeZone($defaultTimezone)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if (!$date) { |
139
|
|
|
$date = new \DateTime(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $date->format('Y-m-d\TH:i:s\Z'); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|