diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php index 78b73f7..14a7dad 100644 --- a/Controller/Checkout/Redirect.php +++ b/Controller/Checkout/Redirect.php @@ -18,7 +18,6 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\Plugin\AuthenticationException; use Magento\Sales\Api\OrderRepositoryInterface; -use Magento\Sales\Model\Order; use TrueLayer\Connect\Api\Log\LogService; use TrueLayer\Connect\Service\Order\HPPService; use TrueLayer\Connect\Service\Order\PaymentCreationService; diff --git a/Controller/Checkout/Status.php b/Controller/Checkout/Status.php index ef97fe9..3b183ec 100644 --- a/Controller/Checkout/Status.php +++ b/Controller/Checkout/Status.php @@ -9,7 +9,6 @@ use Exception; use Magento\Framework\App\Action\Context; -use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\Controller\ResultInterface; diff --git a/Gateway/Command/AuthorizePaymentCommand.php b/Gateway/Command/AuthorizePaymentCommand.php index 2f180ac..e9b86a2 100644 --- a/Gateway/Command/AuthorizePaymentCommand.php +++ b/Gateway/Command/AuthorizePaymentCommand.php @@ -9,6 +9,7 @@ use Magento\Payment\Gateway\Helper\SubjectReader; use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\Order\Payment; use TrueLayer\Connect\Api\Log\LogService as LogRepository; class AuthorizePaymentCommand extends AbstractCommand @@ -27,9 +28,16 @@ public function __construct(OrderRepositoryInterface $orderRepository, LogReposi */ protected function executeCommand(array $subject): void { + /** @var Payment $payment */ + $payment = SubjectReader::readPayment($subject)->getPayment(); + // Set the transaction to pending so that the order is created in a pending state // The pending state set by magento is not the one we want, so we will overwrite that in OrderPlacedHandler // This status will also help third party code that may be listening to transactions. - SubjectReader::readPayment($subject)->getPayment()->setIsTransactionPending(true); + $payment->setIsTransactionPending(true); + + // Do not send emails when the order is placed + // We will instead send emails when the payment is settled + $payment->getOrder()->setCanSendNewEmailFlag(false); } } \ No newline at end of file diff --git a/Model/Webapi/Webhook.php b/Model/Webapi/Webhook.php index b76a375..2e69346 100644 --- a/Model/Webapi/Webhook.php +++ b/Model/Webapi/Webhook.php @@ -22,7 +22,6 @@ use TrueLayer\Connect\Service\Order\PaymentUpdate\PaymentFailedService; use TrueLayer\Connect\Service\Order\PaymentUpdate\PaymentSettledService; use TrueLayer\Connect\Service\Order\RefundUpdate\RefundFailedService; -use TrueLayer\Connect\Helper\ValidationService; use TrueLayer\Exceptions\Exception; use TrueLayer\Exceptions\InvalidArgumentException; use TrueLayer\Exceptions\SignerException; diff --git a/Observer/CreditMemoObserver.php b/Observer/CreditMemoObserver.php index 0b470da..0727f27 100644 --- a/Observer/CreditMemoObserver.php +++ b/Observer/CreditMemoObserver.php @@ -7,6 +7,7 @@ namespace TrueLayer\Connect\Observer; +use Exception; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Exception\LocalizedException; @@ -36,6 +37,7 @@ public function __construct(RefundTransactionRepositoryInterface $refundTransact /** * @param Observer $observer * @throws LocalizedException + * @throws Exception */ public function execute(Observer $observer) { @@ -56,7 +58,7 @@ public function execute(Observer $observer) RefundTransactionDataInterface::ORDER_ID => $order->getEntityId(), RefundTransactionDataInterface::CREDITMEMO_ID => ['null' => true], ], [RefundTransactionDataInterface::ENTITY_ID => 'DESC']); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Failed loading transaction', $e); throw $e; } diff --git a/Service/Log/LogService.php b/Service/Log/LogService.php index 5b09cb0..c4eaba4 100644 --- a/Service/Log/LogService.php +++ b/Service/Log/LogService.php @@ -7,6 +7,7 @@ namespace TrueLayer\Connect\Service\Log; +use Exception; use Monolog\Logger; use TrueLayer\Connect\Api\Config\RepositoryInterface as ConfigProvider; use TrueLayer\Connect\Api\Log\LogService as LogServiceInterface; @@ -105,7 +106,7 @@ private function buildMessage(string $msg, $data = ''): string */ private function convertDataToString($data): string { - if ($data instanceof \Exception) { + if ($data instanceof Exception) { return $data->getMessage() . " " . $data->getTraceAsString(); } @@ -119,6 +120,6 @@ private function convertDataToString($data): string } } - return "{$data}"; + return "$data"; } } diff --git a/Service/Order/BaseTransactionService.php b/Service/Order/BaseTransactionService.php index c3b8bdf..cd24b47 100644 --- a/Service/Order/BaseTransactionService.php +++ b/Service/Order/BaseTransactionService.php @@ -50,7 +50,7 @@ public function execute(Callable $fn): void try { $this->logger->debug('Execute logic'); $fn($transaction); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Exception in transaction', $e); throw $e; } finally { diff --git a/Service/Order/PaymentUpdate/PaymentFailedService.php b/Service/Order/PaymentUpdate/PaymentFailedService.php index e55c816..ec48075 100644 --- a/Service/Order/PaymentUpdate/PaymentFailedService.php +++ b/Service/Order/PaymentUpdate/PaymentFailedService.php @@ -65,7 +65,7 @@ private function cancelOrder(PaymentTransactionDataInterface $transaction, strin } $niceMessage = PaymentFailureReasonHelper::getHumanReadableLabel($failureReason); - $orderComment = "Order cancelled. {$niceMessage} ($failureReason)"; + $orderComment = "Order cancelled. $niceMessage ($failureReason)"; $order->addStatusToHistory($order->getStatus(), $orderComment, true); $this->orderRepository->save($order); $this->logger->debug('Order comment added'); diff --git a/Service/Order/PaymentUpdate/PaymentSettledService.php b/Service/Order/PaymentUpdate/PaymentSettledService.php index 7fcae94..f4c2c59 100644 --- a/Service/Order/PaymentUpdate/PaymentSettledService.php +++ b/Service/Order/PaymentUpdate/PaymentSettledService.php @@ -60,7 +60,7 @@ public function __construct( * @throws LocalizedException * @throws Exception */ - public function handle(string $paymentId) + public function handle(string $paymentId): void { $prefix = "PaymentSettledService $paymentId"; $this->logger->addPrefix($prefix); @@ -78,7 +78,7 @@ public function handle(string $paymentId) $this->logger->removePrefix($prefix); } - private function updateOrder(OrderInterface $order, string $paymentId) + private function updateOrder(OrderInterface $order, string $paymentId): void { // Update order payment $payment = $order->getPayment(); diff --git a/Service/Order/RefundUpdate/RefundTransactionService.php b/Service/Order/RefundUpdate/RefundTransactionService.php index 3e4aeb2..3ec44a5 100644 --- a/Service/Order/RefundUpdate/RefundTransactionService.php +++ b/Service/Order/RefundUpdate/RefundTransactionService.php @@ -12,7 +12,6 @@ use Magento\Framework\Exception\NoSuchEntityException; use TrueLayer\Connect\Api\Log\LogService; use TrueLayer\Connect\Api\Transaction\BaseTransactionDataInterface; -use TrueLayer\Connect\Api\Transaction\Payment\PaymentTransactionRepositoryInterface; use TrueLayer\Connect\Api\Transaction\Refund\RefundTransactionRepositoryInterface; use TrueLayer\Connect\Service\Order\BaseTransactionService;