Skip to content

Instantly share code, notes, and snippets.

@shinesoftware
Last active March 6, 2019 18:00
Show Gist options
  • Save shinesoftware/24b0ee9a0493b9c7a58b2542f8d2a36d to your computer and use it in GitHub Desktop.
Save shinesoftware/24b0ee9a0493b9c7a58b2542f8d2a36d to your computer and use it in GitHub Desktop.
<?php
namespace Shinesoftware\Bnl\Cron;
use Shinesoftware\Bnl\Model\Utils;
class CheckPayments
{
/**
* @var \Shinesoftware\Bnl\Model\Logger\Shinelogger
*/
protected $_logger;
/**
* @var Utils
*/
protected $_utils;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_config;
/**
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
*/
protected $_orderCollectionFactory;
/**
* CheckPayments constructor.
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
* @param \Shinesoftware\Bnl\Model\Logger\Shinelogger $logger
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
\Shinesoftware\Bnl\Model\Utils $utils,
\Shinesoftware\Bnl\Model\Logger\Shinelogger $logger
)
{
$this->_config = $scopeConfig;
$this->_orderCollectionFactory = $orderCollectionFactory;
$this->_utils = $utils;
$this->_logger = $logger;
}
public function execute()
{
$collection = $this->_orderCollectionFactory->create()->addAttributeToSelect('*');
$cron_max_limit = $this->_config->getValue('payment/bnl_settings/chkmaxlimit');
if(empty($cron_max_limit)){
$this->_logger->addWarning('BNL Payment Cron is disabled!');
return $this;
}
$this->_logger->addInfo('BNL Payment Cron is active!');
foreach ($collection as $order) {
if ("payment_review" == $order->getStatus()) {
$paymentMethod = $order->getPayment()->getMethodInstance()->getCode();
$this->_logger->addInfo('Checking the order: ' . $order->getIncrementId());
if (strpos($paymentMethod, "bnl_") !== false) {
$order_date = new \DateTime($order->getCreatedAt());
$since_start = $order_date->diff(new \DateTime());
$this->_logger->addInfo('This order has been paid by BNL Payment Gateway: ' . $order->getIncrementId());
if ($since_start->i > $cron_max_limit) {
$result = $this->_utils->inquiryTransaction($order);
if($result){
$this->_logger->addInfo('The payment gateway replies with: ' . $result);
}
}
}
}
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment