-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOrderPaymentResolver.php
88 lines (76 loc) · 2.54 KB
/
OrderPaymentResolver.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
<?php
namespace PayU\PaymentGateway\Model;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Model\Order\Payment;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\TransactionRepositoryInterface;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use PayU\PaymentGateway\Api\OrderPaymentResolverInterface;
/**
* Class OrderPaymentResolver
* @package PayU\PaymentGateway\Api
*/
class OrderPaymentResolver implements OrderPaymentResolverInterface
{
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
/**
* @var TransactionRepositoryInterface
*/
private $transactionRepository;
/**
* @var OrderPaymentRepositoryInterface
*/
private $paymentRepository;
/**
* OrderPaymentResolver constructor.
*
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param TransactionRepositoryInterface $transactionRepository
* @param OrderPaymentRepositoryInterface $paymentRepository
*/
public function __construct(
SearchCriteriaBuilder $searchCriteriaBuilder,
TransactionRepositoryInterface $transactionRepository,
OrderPaymentRepositoryInterface $paymentRepository
) {
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->transactionRepository = $transactionRepository;
$this->paymentRepository = $paymentRepository;
}
/**
* {@inheritdoc}
*/
public function getLast($order)
{
/** @var Payment $payment */
$payment = $order->getPaymentsCollection()->getLastItem();
$order->setData(
OrderInterface::PAYMENT,
$payment
);
$payment->setOrder($order);
return $payment;
}
/**
* {@inheritdoc}
*/
public function getByTransactionTxnId($txnId)
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('txn_id', $txnId, 'eq')->create();
$transactionList = $this->transactionRepository->getList($searchCriteria)->getItems();
reset($transactionList);
/** @var \Magento\Sales\Api\Data\TransactionInterface | false $transaction */
$transaction = current($transactionList);
if ($transaction === false) {
return null;
}
/** @var Payment $payment */
$payment = $this->paymentRepository->get($transaction->getPaymentId());
$payment->setData('is_active', !$transaction->getIsClosed());
$payment->getOrder()->setData(OrderInterface::PAYMENT, $payment);
return $payment;
}
}