From b83b6ee4377502d0c96d2d8cf8811d5e6ede9bc0 Mon Sep 17 00:00:00 2001 From: Natalia Sekulich Date: Tue, 22 Oct 2024 10:39:47 +0300 Subject: [PATCH 1/3] Add sending invoice email after capture --- Helper/Transaction.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Helper/Transaction.php b/Helper/Transaction.php index 20be5f9..1883d07 100644 --- a/Helper/Transaction.php +++ b/Helper/Transaction.php @@ -33,11 +33,17 @@ class Transaction extends \Magento\Framework\App\Helper\AbstractHelper */ private $orderRepository; + /** + * @var \Magento\Sales\Model\Order\Email\Sender\InvoiceSender + */ + private $invoiceSender; + /** * @param \Mygento\Payment\Helper\Data $helper * @param \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface $transactionManager * @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepo * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender * @param \Magento\Framework\App\Helper\Context $context */ public function __construct( @@ -45,6 +51,7 @@ public function __construct( \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface $transactionManager, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepo, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, + \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender, \Magento\Framework\App\Helper\Context $context ) { parent::__construct($context); @@ -52,6 +59,7 @@ public function __construct( $this->transactionRepo = $transactionRepo; $this->transactionManager = $transactionManager; $this->orderRepository = $orderRepository; + $this->invoiceSender = $invoiceSender; } /** @@ -108,6 +116,14 @@ public function proceedCapture($order, $transactionId, $amount, $transData = []) $transData ); } + $invoice = $payment->getCreatedInvoice(); + if ($invoice && !$invoice->getEmailSent()) { + $this->invoiceSender->send($invoice); + $order->addStatusHistoryComment( + __('You notified customer about invoice #%1.', $invoice->getIncrementId()) + ) + ->save(); + } } /** From a56d77b060e9d51a645585f31292253aa6dc9ce0 Mon Sep 17 00:00:00 2001 From: Natalia Sekulich Date: Tue, 22 Oct 2024 11:15:32 +0300 Subject: [PATCH 2/3] Fix code style in template --- view/adminhtml/templates/form/form.phtml | 2 +- view/frontend/templates/form/form.phtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/view/adminhtml/templates/form/form.phtml b/view/adminhtml/templates/form/form.phtml index 0e236c5..dfd5989 100644 --- a/view/adminhtml/templates/form/form.phtml +++ b/view/adminhtml/templates/form/form.phtml @@ -15,6 +15,6 @@ $instructions = $block->getInstructions(); ?>" style="display: none;"> escapeHtml($instructions)) - ?> + ?> getInstructions(); ?>" style="display: none;"> escapeHtml($instructions)) - ?> + ?> Date: Wed, 23 Oct 2024 12:40:38 +0300 Subject: [PATCH 3/3] Change return value to OrderPaymentInterface. --- Helper/Transaction.php | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/Helper/Transaction.php b/Helper/Transaction.php index 1883d07..f18bd90 100644 --- a/Helper/Transaction.php +++ b/Helper/Transaction.php @@ -33,17 +33,11 @@ class Transaction extends \Magento\Framework\App\Helper\AbstractHelper */ private $orderRepository; - /** - * @var \Magento\Sales\Model\Order\Email\Sender\InvoiceSender - */ - private $invoiceSender; - /** * @param \Mygento\Payment\Helper\Data $helper * @param \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface $transactionManager * @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepo * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository - * @param \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender * @param \Magento\Framework\App\Helper\Context $context */ public function __construct( @@ -51,7 +45,6 @@ public function __construct( \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface $transactionManager, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepo, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, - \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender, \Magento\Framework\App\Helper\Context $context ) { parent::__construct($context); @@ -59,7 +52,6 @@ public function __construct( $this->transactionRepo = $transactionRepo; $this->transactionManager = $transactionManager; $this->orderRepository = $orderRepository; - $this->invoiceSender = $invoiceSender; } /** @@ -67,6 +59,8 @@ public function __construct( * @param string $transactionId * @param float $amount * @param array $transData + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedAuthorize($order, $transactionId, $amount, $transData = []) { @@ -88,6 +82,8 @@ public function proceedAuthorize($order, $transactionId, $amount, $transData = [ $transData ); } + + return $payment; } /** @@ -95,6 +91,8 @@ public function proceedAuthorize($order, $transactionId, $amount, $transData = [ * @param string $transactionId * @param float $amount * @param array $transData + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedCapture($order, $transactionId, $amount, $transData = []) { @@ -116,14 +114,8 @@ public function proceedCapture($order, $transactionId, $amount, $transData = []) $transData ); } - $invoice = $payment->getCreatedInvoice(); - if ($invoice && !$invoice->getEmailSent()) { - $this->invoiceSender->send($invoice); - $order->addStatusHistoryComment( - __('You notified customer about invoice #%1.', $invoice->getIncrementId()) - ) - ->save(); - } + + return $payment; } /** @@ -131,6 +123,8 @@ public function proceedCapture($order, $transactionId, $amount, $transData = []) * @param string $transactionId * @param string $parentTransactionId * @param float $amount + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedRefund($order, $transactionId, $parentTransactionId, $amount) { @@ -144,6 +138,8 @@ public function proceedRefund($order, $transactionId, $parentTransactionId, $amo $payment->registerRefundNotification($amount); $this->orderRepository->save($order); + + return $payment; } /** @@ -151,6 +147,8 @@ public function proceedRefund($order, $transactionId, $parentTransactionId, $amo * @param string $transactionId * @param string $parentTransactionId * @param float $amount + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedVoid($order, $transactionId, $parentTransactionId, $amount) { @@ -160,6 +158,8 @@ public function proceedVoid($order, $transactionId, $parentTransactionId, $amoun $payment->registerVoidNotification($amount); $this->orderRepository->save($order); + + return $payment; } /** @@ -167,6 +167,8 @@ public function proceedVoid($order, $transactionId, $parentTransactionId, $amoun * @param string $transactionId * @param string $parentTransactionId * @param mixed $transData + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedReceipt($order, $transactionId, $parentTransactionId, $transData) { @@ -205,6 +207,8 @@ public function proceedReceipt($order, $transactionId, $parentTransactionId, $tr ); $this->orderRepository->save($order); + + return $payment; } /** @@ -212,6 +216,8 @@ public function proceedReceipt($order, $transactionId, $parentTransactionId, $tr * @param string $transactionId * @param string $parentTransactionId * @param mixed $transData + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface */ public function proceedRefundReceipt($order, $transactionId, $parentTransactionId, $transData) { @@ -250,6 +256,8 @@ public function proceedRefundReceipt($order, $transactionId, $parentTransactionI ); $this->orderRepository->save($order); + + return $payment; } /**