-
Notifications
You must be signed in to change notification settings - Fork 7
/
FetchPaymentMethodsOffOrderStatus.php
95 lines (82 loc) · 2.33 KB
/
FetchPaymentMethodsOffOrderStatus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace MercadoPago\AdbPayment\Cron;
use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use MercadoPago\AdbPayment\Gateway\Config\ConfigPaymentMethodsOff;
use MercadoPago\AdbPayment\Model\Console\Command\Notification\FetchStatus;
/**
* CronTab for fetch Payment Methods Off Order Status.
*/
class FetchPaymentMethodsOffOrderStatus
{
/**
* @var Logger
*/
protected $logger;
/**
* @var FetchStatus
*/
protected $fetchStatus;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
/**
* @var ResourceConnection
*/
protected $resource;
/**
* Constructor.
*
* @param Logger $logger
* @param FetchStatus $fetchStatus
* @param CollectionFactory $collectionFactory
* @param ResourceConnection $resource;
*/
public function __construct(
Logger $logger,
FetchStatus $fetchStatus,
CollectionFactory $collectionFactory,
ResourceConnection $resource
) {
$this->logger = $logger;
$this->fetchStatus = $fetchStatus;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
}
/**
* Get sales_order_payment table name.
*
* @return string
*/
public function getSalesOrderPaymentTableName()
{
return $this->resource->getTableName('sales_order_payment');
}
/**
* Execute the cron.
*
* @return void
*/
public function execute()
{
$orders = $this->collectionFactory->create()
->addFieldToFilter('state', Order::STATE_NEW);
$orders->getSelect()
->join(
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
)
->where('sop.method = ?', ConfigPaymentMethodsOff::METHOD);
foreach ($orders as $order) {
$orderId = $order->getEntityId();
$this->logger->debug([
'fetch' => 'Fetch Status Payment Methods Off for Order Id '.$orderId,
]);
$this->fetchStatus->fetch($orderId);
}
}
}