Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.3
2.6.0
4 changes: 3 additions & 1 deletion Api/TpayConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Tpay\Magento2\Api;

/** @api */
/**
* @api
*/
interface TpayConfigInterface
{
public function isTpayActive(): bool;
Expand Down
4 changes: 3 additions & 1 deletion Api/TpayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Tpay\Magento2\Api;

/** @api */
/**
* @api
*/
interface TpayInterface
{
public const CODE = 'Tpay_Magento2';
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.6.0

### Changed

- Removed OrderRepository override that provided loadByIncrementId method, loading order details using OrderRepository::get

## 2.5.3

### Added
Expand Down
1 change: 1 addition & 0 deletions Controller/Tpay/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function execute(): ResultInterface
if ($orderId) {
$payment = $this->tpayService->getPayment($orderId);
$paymentData = $payment->getData();

$additionalPaymentInformation = $paymentData['additional_information'];

if (!$additionalPaymentInformation[TpayInterface::TERMS_ACCEPT]) {
Expand Down
4 changes: 3 additions & 1 deletion Controller/Tpay/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function execute(): ResultInterface
return $this->redirectFactory->redirectCheckoutCart();
}

$additionalPaymentInfo = $this->tpayService->getPayment($orderId)->getData()['additional_information'];
$order = $this->checkoutSession->getLastRealOrder();

$additionalPaymentInfo = $order->getPayment()->getData()['additional_information'];

if ($this->additionalPaymentInfoValidator->validateCardData($additionalPaymentInfo)) {
return $this->redirectFactory->redirectCardPayment();
Expand Down
2 changes: 1 addition & 1 deletion Cron/CancelOverdue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use DateTime;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
use Tpay\Magento2\Api\TpayInterface;
use Tpay\Magento2\Model\Sales\OrderRepository;

class CancelOverdue
{
Expand Down
43 changes: 43 additions & 0 deletions Helper/OrderResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Tpay\Magento2\Helper;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\ResourceModel\Order;

class OrderResolver
{
/** @var OrderRepositoryInterface */
private $orderRepository;

/** @var Order */
private $orderResource;

private $cache = [];

public function __construct(OrderRepositoryInterface $orderRepository, Order $orderResource)
{
$this->orderRepository = $orderRepository;
$this->orderResource = $orderResource;
}

public function getOrderByIncrementId(string $incrementId): OrderInterface
{
$orderId = $this->getOrderIdByIncrementId($incrementId);

return $this->orderRepository->get($orderId);
}

public function getOrderIdByIncrementId(string $incrementId): int
{
if (!isset($this->cache[$incrementId])) {
$connection = $this->orderResource->getConnection();
$select = $connection->select()->from($this->orderResource->getMainTable(), ['entity_id'])->where('increment_id = ?', $incrementId);
$orderId = $connection->fetchOne($select);
$this->cache[$incrementId] = (int) $orderId;
}

return $this->cache[$incrementId];
}
}
30 changes: 0 additions & 30 deletions Model/Sales/OrderRepository.php

This file was deleted.

22 changes: 11 additions & 11 deletions Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
use Magento\Payment\Model\Method\Adapter;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Store\Model\StoreManager;
use Psr\Log\LoggerInterface;
use Tpay\Magento2\Api\Sales\OrderRepositoryInterface;
use Tpay\Magento2\Api\TpayInterface;
use Tpay\Magento2\Helper\OrderResolver;
use Tpay\Magento2\Model\ApiFacade\Refund\RefundApiFacade;
use Tpay\Magento2\Provider\ConfigurationProvider;
use Tpay\OriginApi\Validators\FieldsValidator;
Expand Down Expand Up @@ -58,9 +59,6 @@ class TpayPayment extends Adapter implements TpayInterface
/** @var CustomerSession */
protected $customerSession;

/** @var OrderRepositoryInterface */
protected $orderRepository;

/** @var Escaper */
protected $escaper;

Expand All @@ -82,6 +80,9 @@ class TpayPayment extends Adapter implements TpayInterface
/** @var CacheInterface */
protected $cache;

/** @var OrderResolver */
private $orderResolver;

private $supportedVendors = [
'visa',
'jcb',
Expand All @@ -104,7 +105,7 @@ public function __construct(
UrlInterface $urlBuilder,
Session $checkoutSession,
CustomerSession $customerSession,
OrderRepositoryInterface $orderRepository,
OrderResolver $orderResolver,
Escaper $escaper,
StoreManager $storeManager,
ConfigurationProvider $configurationProvider,
Expand All @@ -129,7 +130,7 @@ public function __construct(
$this->escaper = $escaper;
$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->orderRepository = $orderRepository;
$this->orderResolver = $orderResolver;
$this->storeManager = $storeManager;
$this->configurationProvider = $configurationProvider;
$this->infoInstance = $infoInstance;
Expand Down Expand Up @@ -305,8 +306,7 @@ public function getCheckoutTotal()
$amount = (float) $this->getCheckout()->getQuote()->getBaseGrandTotal();

if (!$amount && $this->getCheckout()->getLastRealOrderId()) {
$orderId = $this->getCheckout()->getLastRealOrderId();
$order = $this->orderRepository->getByIncrementId($orderId);
$order = $this->getCheckout()->getLastRealOrder();
$amount = $order->getBaseGrandTotal();
}

Expand Down Expand Up @@ -378,12 +378,12 @@ protected function getCheckout(): Session
return $this->checkoutSession;
}

protected function getOrder(?string $orderId = null): \Magento\Sales\Api\Data\OrderInterface
protected function getOrder(?string $orderId = null): OrderInterface
{
if (null === $orderId) {
$orderId = $this->getCheckout()->getLastRealOrderId();
return $this->getCheckout()->getLastRealOrder();
}

return $this->orderRepository->getByIncrementId($orderId);
return $this->orderResolver->getOrderByIncrementId($orderId);
}
}
18 changes: 12 additions & 6 deletions Service/TpayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Service\InvoiceService;
use Tpay\Magento2\Api\Sales\OrderRepositoryInterface;
use Tpay\Magento2\Helper\OrderResolver;

class TpayService
{
Expand All @@ -23,19 +24,24 @@ class TpayService
/** @var InvoiceService */
protected $invoiceService;

/** @var OrderResolver */
private $orderResolver;

public function __construct(
OrderRepositoryInterface $orderRepository,
OrderPaymentRepositoryInterface $orderPaymentRepository,
InvoiceService $invoiceService
InvoiceService $invoiceService,
OrderResolver $orderResolver
) {
$this->orderRepository = $orderRepository;
$this->orderPaymentRepository = $orderPaymentRepository;
$this->invoiceService = $invoiceService;
$this->orderResolver = $orderResolver;
}

public function setOrderStatePendingPayment(string $orderId, bool $sendEmail): OrderInterface
{
$order = $this->orderRepository->getByIncrementId($orderId);
$order = $this->orderResolver->getOrderByIncrementId($orderId);
$order
->setTotalDue($order->getBaseGrandTotal())
->setTotalPaid(0.00)
Expand All @@ -53,22 +59,22 @@ public function setOrderStatePendingPayment(string $orderId, bool $sendEmail): O
public function addCommentToHistory($orderId, $comment)
{
/** @var Order $order */
$order = $this->orderRepository->getByIncrementId($orderId);
$order = $this->orderResolver->getOrderByIncrementId($orderId);
$order->addStatusToHistory($order->getState(), $comment);
$this->orderRepository->save($order);
}

public function getPayment(string $orderId): OrderPaymentInterface
{
/** @var Order $order */
$order = $this->orderRepository->getByIncrementId($orderId);
$order = $this->orderResolver->getOrderByIncrementId($orderId);

return $order->getPayment();
}

public function getOrderById(string $orderId): OrderInterface
{
return $this->orderRepository->getByIncrementId($orderId);
return $this->orderResolver->getOrderByIncrementId($orderId);
}

public function saveOrderPayment(OrderPaymentInterface $payment): OrderPaymentInterface
Expand Down
1 change: 0 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<preference for="Tpay\Magento2\Api\AliasRepositoryInterface" type="Tpay\Magento2\Model\AliasRepository" />
<preference for="Tpay\Magento2\Api\Data\TokensInterface" type="Tpay\Magento2\Model\Token"/>
<preference for="Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorFactoryInterface" type="Tpay\Magento2\Notification\Strategy\Factory\NotificationProcessorFactory" />
<preference for="Tpay\Magento2\Api\Sales\OrderRepositoryInterface" type="Tpay\Magento2\Model\Sales\OrderRepository" />
<preference for="Tpay\Magento2\Api\TokenRepositoryInterface" type="Tpay\Magento2\Model\TokenRepository"/>
<preference for="Tpay\Magento2\Api\TpayConfigInterface" type="Tpay\Magento2\Provider\ConfigurationProvider" />
<preference for="Tpay\Magento2\Api\TpayInterface" type="Tpay\Magento2\Model\TpayPayment" />
Expand Down