-
Notifications
You must be signed in to change notification settings - Fork 7
/
FetchPseOrderStatus.php
101 lines (88 loc) · 2.39 KB
/
FetchPseOrderStatus.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
96
97
98
99
100
101
<?php
/**
* Copyright © MercadoPago. All rights reserved.
*
* @author Mercado Pago
* @license See LICENSE for license details.
*/
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\ConfigPse;
use MercadoPago\AdbPayment\Model\Console\Command\Notification\FetchStatus;
/**
* CronTab for fetch Pse Order Status.
*/
class FetchPseOrderStatus
{
/**
* @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 = ?', ConfigPse::METHOD);
foreach ($orders as $order) {
$orderId = $order->getEntityId();
$this->logger->debug([
'fetch' => 'Fetch Status Pse for Order Id '.$orderId,
]);
$this->fetchStatus->fetch($orderId);
}
}
}