-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTransactionsCheck.php
79 lines (74 loc) · 3.27 KB
/
TransactionsCheck.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
<?php
/**
* @copyright: Copyright © 2017 Firebear Studio. All rights reserved.
* @author : Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ShapeShift\Cron;
use Firebear\ShapeShift\Model\ResourceModel\Transactions\CollectionFactory as TransactionsCollection;
use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory;
use Magento\Sales\Model\OrderRepository;
use Firebear\ShapeShift\Model\TransactionsRepository;
use Firebear\ShapeShift\Helper\Data;
use Psr\Log\LoggerInterface;
use Magento\Sales\Model\Order;
class TransactionsCheck
{
private $transactionsCollectionFactory;
private $shapeShiftClientApiFactory;
private $transactionsRepository;
private $orderRepository;
private $helper;
private $log;
public function __construct(
TransactionsCollection $transactionsCollectionFactory,
ShapeShiftClientApiFactory $shapeShiftClientApiFactory,
OrderRepository $orderRepository,
TransactionsRepository $transactionsRepository,
Data $helper,
LoggerInterface $log
) {
$this->transactionsCollectionFactory = $transactionsCollectionFactory;
$this->shapeShiftClientApiFactory = $shapeShiftClientApiFactory;
$this->orderRepository = $orderRepository;
$this->transactionsRepository = $transactionsRepository;
$this->helper = $helper;
$this->log = $log;
}
public function execute()
{
$transactionCollection = $this->transactionsCollectionFactory->create();
$transactions = $transactionCollection->addFieldToFilter('status', 1)->getItems();
$shapeShiftClientApi = $this->shapeShiftClientApiFactory->create();
foreach ($transactions as $transaction) {
$status = $shapeShiftClientApi->getStatus($transaction->getDepositAddress());
$orderModel = $this->orderRepository->get($transaction->getOrderId());
if ($status == 'complete') {
$orderModel->setState(
$this->helper->getGeneralConfig('status_order_paid'),
true
)->setStatus($this->helper->getGeneralConfig('status_order_paid'));
$this->orderRepository->save($orderModel);
$transactionModel = $this->transactionsRepository->get($transaction->getId());
$transactionModel->setStatus(2);
$this->transactionsRepository->save($transactionModel);
}
if ($status == 'failed') {
$orderModel->setState(
Order::STATE_CANCELED,
true
)->setStatus(Order::STATE_CANCELED);
$transactionModel = $this->transactionsRepository->get($transaction->getId());
$this->orderRepository->save($orderModel);
$transactionModel->setStatus(3);
$this->transactionsRepository->save($transactionModel);
}
if ($status == 'no_deposits') {
$orderModel->setState(
Order::STATE_PENDING_PAYMENT,
true
)->setStatus(Order::STATE_PENDING_PAYMENT);
$this->orderRepository->save($orderModel);
}
}
}
}