Skip to content

Commit 29cadf1

Browse files
committed
PLUG-106: Use correct method to get total refund amount, formatting.
1 parent a5c9ffc commit 29cadf1

32 files changed

+141
-119
lines changed

Api/Log/LogService.php renamed to Api/Log/LogServiceInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@
1111
* Log repository interface
1212
* @api
1313
*/
14-
interface LogService
14+
interface LogServiceInterface
1515
{
1616
/**
1717
* Add record to error log
1818
*
1919
* @param string $type
2020
* @param mixed $data
2121
*/
22-
public function error(string $type, $data): LogService;
22+
public function error(string $type, $data): LogServiceInterface;
2323

2424
/**
2525
* Add record to debug log
2626
*
2727
* @param string $type
2828
* @param mixed $data
2929
*/
30-
public function debug(string $type, $data): LogService;
30+
public function debug(string $type, $data): LogServiceInterface;
3131

3232
/**
3333
* @param string|int $prefix
3434
*/
35-
public function addPrefix($prefix): LogService;
35+
public function addPrefix($prefix): LogServiceInterface;
3636

3737
/**
3838
* @param string|int $prefix
39-
* @return LogService
39+
* @return LogServiceInterface
4040
*/
41-
public function removePrefix($prefix): LogService;
41+
public function removePrefix($prefix): LogServiceInterface;
4242
}

Block/Adminhtml/System/Config/Button/Credentials.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Config\Block\System\Config\Form\Field;
1414
use Magento\Framework\App\RequestInterface;
1515
use Magento\Framework\Data\Form\Element\AbstractElement;
16-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
16+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1717

1818
/**
1919
* Credentials validation button class

Controller/Checkout/BaseController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
use Magento\Framework\Controller\Result\Json as JsonResult;
1414
use Magento\Framework\Controller\Result\JsonFactory;
1515
use Magento\Framework\Controller\ResultInterface;
16-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
16+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1717

1818
abstract class BaseController
1919
{
20-
const CACHE_CONTROL = 'no-store, no-cache, must-revalidate, max-age=0';
20+
private const CACHE_CONTROL = 'no-store, no-cache, must-revalidate, max-age=0';
2121

2222
protected Context $context;
2323
protected LogRepository $logger;
@@ -55,7 +55,7 @@ public function execute()
5555
/**
5656
* @return ResultInterface|ResponseInterface
5757
*/
58-
protected abstract function executeAction();
58+
abstract protected function executeAction();
5959

6060
/**
6161
* @param string $to

Controller/Checkout/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\Controller\ResultInterface;
1414
use Magento\Framework\View\Result\PageFactory;
1515
use Magento\Framework\Controller\Result\JsonFactory;
16-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
16+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1717

1818
class Process extends BaseController implements HttpGetActionInterface, HttpPostActionInterface
1919
{

Controller/Checkout/Redirect.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Magento\Framework\Exception\NoSuchEntityException;
1919
use Magento\Framework\Exception\Plugin\AuthenticationException;
2020
use Magento\Sales\Api\OrderRepositoryInterface;
21-
use TrueLayer\Connect\Api\Log\LogService;
21+
use TrueLayer\Connect\Api\Log\LogServiceInterface;
2222
use TrueLayer\Connect\Service\Order\HPPService;
2323
use TrueLayer\Connect\Service\Order\PaymentCreationService;
2424
use TrueLayer\Connect\Service\Order\PaymentErrorMessageManager;
@@ -43,7 +43,7 @@ class Redirect extends BaseController implements HttpGetActionInterface
4343
* @param PaymentCreationService $paymentCreationService
4444
* @param PaymentErrorMessageManager $paymentErrorMessageManager
4545
* @param HPPService $hppService
46-
* @param LogService $logger
46+
* @param LogServiceInterface $logger
4747
*/
4848
public function __construct(
4949
Context $context,
@@ -53,9 +53,8 @@ public function __construct(
5353
PaymentCreationService $paymentCreationService,
5454
PaymentErrorMessageManager $paymentErrorMessageManager,
5555
HPPService $hppService,
56-
LogService $logger
57-
)
58-
{
56+
LogServiceInterface $logger
57+
) {
5958
$this->checkoutSession = $checkoutSession;
6059
$this->orderRepository = $orderRepository;
6160
$this->paymentCreationService = $paymentCreationService;
@@ -71,7 +70,7 @@ public function __construct(
7170
public function executeAction(): ResponseInterface
7271
{
7372
try {
74-
return $this->createPaymentAndRedirect();
73+
return $this->createPaymentAndRedirect();
7574
} catch (Exception $e) {
7675
$this->logger->error('Failed to create payment and redirect to HPP', $e);
7776
$this->failOrder();
@@ -121,4 +120,4 @@ private function redirectToFailPage(): ResponseInterface
121120
$this->paymentErrorMessageManager->addMessage('There was an issue creating your payment. Please try again.');
122121
return $this->redirect('checkout/cart/index');
123122
}
124-
}
123+
}

Controller/Checkout/Status.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\Exception\NoSuchEntityException;
1818
use Magento\Checkout\Model\Session;
1919
use Magento\Sales\Api\OrderRepositoryInterface;
20-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
20+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
2121
use TrueLayer\Connect\Helper\ValidationHelper;
2222
use TrueLayer\Connect\Model\Config\Repository as ConfigRepository;
2323
use TrueLayer\Connect\Service\Client\ClientFactory;
@@ -32,7 +32,7 @@
3232

3333
class Status extends BaseController implements HttpPostActionInterface
3434
{
35-
const CHECK_API_AFTER_ATTEMPTS = 7;
35+
private const CHECK_API_AFTER_ATTEMPTS = 7;
3636

3737
private Session $session;
3838
private OrderRepositoryInterface $orderRepository;
@@ -101,7 +101,6 @@ public function executeAction(): ResultInterface
101101
return $this->pendingResponse();
102102
}
103103

104-
105104
/**
106105
* @param string $paymentId
107106
* @return ResultInterface|null

Gateway/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Payment\Gateway\Helper\SubjectReader;
1313
use Magento\Sales\Api\Data\OrderInterface;
1414
use Magento\Sales\Api\OrderRepositoryInterface;
15-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
15+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1616

1717
abstract class AbstractCommand implements CommandInterface
1818
{

Gateway/Command/AuthorizePaymentCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Payment\Gateway\Helper\SubjectReader;
1111
use Magento\Sales\Api\OrderRepositoryInterface;
1212
use Magento\Sales\Model\Order\Payment;
13-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
13+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1414

1515
class AuthorizePaymentCommand extends AbstractCommand
1616
{
@@ -40,4 +40,4 @@ protected function executeCommand(array $subject): void
4040
// We will instead send emails when the payment is settled
4141
$payment->getOrder()->setCanSendNewEmailFlag(false);
4242
}
43-
}
43+
}

Gateway/Command/RefundPaymentCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\Sales\Api\OrderRepositoryInterface;
1616
use Magento\Sales\Model\Order\Payment;
1717
use TrueLayer\Connect\Service\Order\RefundService;
18-
use TrueLayer\Connect\Api\Log\LogService;
18+
use TrueLayer\Connect\Api\Log\LogServiceInterface;
1919

2020
class RefundPaymentCommand extends AbstractCommand
2121
{
@@ -24,12 +24,12 @@ class RefundPaymentCommand extends AbstractCommand
2424
/**
2525
* @param RefundService $refundService
2626
* @param OrderRepositoryInterface $orderRepository
27-
* @param LogService $logger
27+
* @param LogServiceInterface $logger
2828
*/
2929
public function __construct(
30-
RefundService $refundService,
30+
RefundService $refundService,
3131
OrderRepositoryInterface $orderRepository,
32-
LogService $logger
32+
LogServiceInterface $logger
3333
) {
3434
$this->refundService = $refundService;
3535
parent::__construct($orderRepository, $logger->addPrefix("RefundPaymentCommand"));
@@ -52,4 +52,4 @@ protected function executeCommand(array $subject): void
5252
$this->logger->addPrefix($order->getEntityId());
5353
$this->refundService->refund($order, $invoiceIncrementId, (float) SubjectReader::readAmount($subject));
5454
}
55-
}
55+
}

Helper/AmountHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public static function toMinor($amount): int
1313
{
1414
return (int) round($amount * 100, 0, PHP_ROUND_HALF_UP);
1515
}
16-
}
16+
}

Helper/PaymentFailureReasonHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PaymentFailureReasonHelper
1313
{
1414
public static function getHumanReadableLabel(string $reason = null): Phrase
1515
{
16-
switch($reason) {
16+
switch ($reason) {
1717
case 'cancelled':
1818
return __('You cancelled the payment.');
1919
case 'expired':

Helper/ValidationHelper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ class ValidationHelper
1313
* @param mixed $input
1414
* @return bool
1515
*/
16-
public static function isUUID($input): bool {
17-
if (!is_string($input)) return false;
16+
public static function isUUID($input): bool
17+
{
18+
if (!is_string($input)) {
19+
return false;
20+
}
21+
1822
$pattern = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
1923
return preg_match($pattern, $input) === 1;
2024
}
21-
}
25+
}

Model/Transaction/Payment/PaymentTransactionDataModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
/**
1515
* Transaction PaymentTransactionDataModel
1616
*/
17-
class PaymentTransactionDataModel extends AbstractModel implements ExtensibleDataInterface, PaymentTransactionDataInterface
17+
class PaymentTransactionDataModel extends AbstractModel
18+
implements ExtensibleDataInterface, PaymentTransactionDataInterface
1819
{
1920

2021
/**

Model/Transaction/Payment/PaymentTransactionRepository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Exception\CouldNotSaveException;
1111
use Magento\Framework\Exception\InputException;
1212
use Magento\Framework\Exception\NoSuchEntityException;
13-
use TrueLayer\Connect\Api\Log\LogService;
13+
use TrueLayer\Connect\Api\Log\LogServiceInterface;
1414
use TrueLayer\Connect\Api\Transaction\Payment\PaymentTransactionDataInterface;
1515
use TrueLayer\Connect\Api\Transaction\Payment\PaymentTransactionDataInterfaceFactory;
1616
use TrueLayer\Connect\Api\Transaction\Payment\PaymentTransactionRepositoryInterface;
@@ -25,19 +25,19 @@ class PaymentTransactionRepository implements PaymentTransactionRepositoryInterf
2525
*/
2626
private $dataFactory;
2727
private PaymentTransactionResourceModel $resource;
28-
private LogService $logger;
28+
private LogServiceInterface $logger;
2929

3030
/**
3131
* PaymentTransactionRepository constructor.
3232
*
3333
* @param PaymentTransactionResourceModel $resource
3434
* @param PaymentTransactionDataInterfaceFactory $dataFactory
35-
* @param LogService $logger
35+
* @param LogServiceInterface $logger
3636
*/
3737
public function __construct(
3838
PaymentTransactionResourceModel $resource,
3939
PaymentTransactionDataInterfaceFactory $dataFactory,
40-
LogService $logger
40+
LogServiceInterface $logger
4141
) {
4242
$this->resource = $resource;
4343
$this->dataFactory = $dataFactory;

Model/Transaction/Payment/PaymentTransactionResourceModel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function isExists(int $entityId): bool
3737
return (bool)$connection->fetchOne($select, $bind);
3838
}
3939

40-
4140
/**
4241
* Check is entity exists
4342
*

Model/Transaction/Refund/RefundTransactionDataModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use Magento\Framework\Model\AbstractModel;
1212
use TrueLayer\Connect\Api\Transaction\Refund\RefundTransactionDataInterface;
1313

14-
class RefundTransactionDataModel extends AbstractModel implements ExtensibleDataInterface, RefundTransactionDataInterface
14+
class RefundTransactionDataModel extends AbstractModel
15+
implements ExtensibleDataInterface, RefundTransactionDataInterface
1516
{
1617
/**
1718
* @inheritDoc

Model/Transaction/Refund/RefundTransactionRepository.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\Framework\Exception\CouldNotSaveException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
12-
use TrueLayer\Connect\Api\Log\LogService;
13-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
12+
use TrueLayer\Connect\Api\Log\LogServiceInterface;
13+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1414
use TrueLayer\Connect\Api\Transaction\Refund\RefundTransactionDataInterface;
1515
use TrueLayer\Connect\Api\Transaction\Refund\RefundTransactionRepositoryInterface;
1616
use TrueLayer\Connect\Api\Transaction\Refund\RefundTransactionDataInterfaceFactory;
@@ -28,7 +28,7 @@ class RefundTransactionRepository implements RefundTransactionRepositoryInterfac
2828
private $collectionFactory;
2929

3030
private RefundTransactionResourceModel $resource;
31-
private LogService $logger;
31+
private LogServiceInterface $logger;
3232

3333
/**
3434
* PaymentTransactionRepository constructor.
@@ -108,7 +108,8 @@ public function save(RefundTransactionDataInterface $entity): RefundTransactionD
108108
return $entity;
109109
} catch (\Exception $exception) {
110110
$this->logger->error('Could not save refund transaction', $exception);
111-
throw new CouldNotSaveException(__(self::COULD_NOT_SAVE_EXCEPTION, $exception->getMessage()));
111+
$msg = self::COULD_NOT_SAVE_EXCEPTION;
112+
throw new CouldNotSaveException(__($msg, $exception->getMessage()));
112113
}
113114
}
114115

Model/Webapi/Webhook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\Quote\Api\CartRepositoryInterface;
1616
use ReflectionException;
1717
use TrueLayer\Connect\Api\Config\RepositoryInterface as ConfigRepository;
18-
use TrueLayer\Connect\Api\Log\LogService as LogRepository;
18+
use TrueLayer\Connect\Api\Log\LogServiceInterface as LogRepository;
1919
use TrueLayer\Connect\Api\Transaction\Payment\PaymentTransactionRepositoryInterface as TransactionRepository;
2020
use TrueLayer\Connect\Api\Webapi\WebhookInterface;
2121
use TrueLayer\Connect\Helper\ValidationHelper;
@@ -105,7 +105,7 @@ public function processTransfer()
105105
->handler(function (TrueLayerWebhookInterface\PaymentFailedEventInterface $event) {
106106
$this->paymentFailedService->handle($event->getPaymentId(), $event->getFailureReason());
107107
})
108-
->handler(function(TrueLayerWebhookInterface\RefundFailedEventInterface $event) {
108+
->handler(function (TrueLayerWebhookInterface\RefundFailedEventInterface $event) {
109109
$this->refundFailedService->handle($event->getRefundId(), $event->getFailureReason());
110110
});
111111

0 commit comments

Comments
 (0)