From a6d09f77a080e9792a992638e7fed12fab142f77 Mon Sep 17 00:00:00 2001 From: Hugo Posnic Date: Wed, 24 Jan 2024 15:45:59 +0100 Subject: [PATCH] 3.5.1 --- Gateway/Config/Config.php | 2 +- Gateway/HandlePayment.php | 10 ++++++---- Gateway/HandleRefund.php | 11 ++++++++++- Gateway/Http/DummyTransferFactory.php | 2 +- Helper/Fintecture.php | 14 ++++++++++++++ composer.json | 2 +- etc/module.xml | 2 +- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Gateway/Config/Config.php b/Gateway/Config/Config.php index a89f7d8..97a91d9 100644 --- a/Gateway/Config/Config.php +++ b/Gateway/Config/Config.php @@ -7,7 +7,7 @@ class Config extends BaseConfig { const CODE = 'fintecture'; - const VERSION = '3.5.0'; + const VERSION = '3.5.1'; const KEY_SHOP_NAME = 'general/store_information/name'; const KEY_ACTIVE = 'active'; diff --git a/Gateway/HandlePayment.php b/Gateway/HandlePayment.php index f20de14..7c05dcd 100644 --- a/Gateway/HandlePayment.php +++ b/Gateway/HandlePayment.php @@ -7,7 +7,6 @@ use Fintecture\Payment\Helper\Fintecture as FintectureHelper; use Fintecture\Payment\Logger\Logger; use Magento\Framework\DB\Transaction; -use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Api\InvoiceRepositoryInterface; use Magento\Sales\Api\OrderManagementInterface; use Magento\Sales\Api\OrderPaymentRepositoryInterface; @@ -140,6 +139,8 @@ public function create( $payment->setAmountPaid($paidAmount); $payment->setBaseAmountPaid($basePaidAmount); + $payment->setTransactionId($params['sessionId']); + $this->paymentRepository->save($payment); $transaction = $this->transactionBuilder->setPayment($payment) @@ -153,7 +154,7 @@ public function create( 'type' => $params['type'], ]]) ->setFailSafe(true) - ->build(TransactionInterface::TYPE_CAPTURE); + ->build(Payment\Transaction::TYPE_CAPTURE); $this->transactionRepository->save($transaction); @@ -208,14 +209,15 @@ public function sendInvoice(Order $order, array $params): void if ($this->fintectureHelper->isStatusAlreadyFinal($order) && $order->canInvoice() && $this->config->isInvoicingActive()) { $invoice = $this->invoiceService->prepareInvoice($order); + $invoice->setRequestedCaptureCase(Order\Invoice::CAPTURE_ONLINE); $invoice->setTransactionId($params['sessionId']); $invoice->register(); $invoice->pay(); $this->invoiceRepository->save($invoice); - $transactionSave = $this->transaction + $transaction = $this->transaction ->addObject($invoice) ->addObject($invoice->getOrder()); - $transactionSave->save(); + $transaction->save(); // Send Invoice mail to customer $this->invoiceSender->send($invoice); diff --git a/Gateway/HandleRefund.php b/Gateway/HandleRefund.php index cd0fb58..55040ee 100644 --- a/Gateway/HandleRefund.php +++ b/Gateway/HandleRefund.php @@ -198,7 +198,16 @@ public function applyWithoutCreditmemo(Order $order, float $amount): bool // Create a credit memo only for a full refund if ($isFullRefund) { - $creditmemo = $this->creditmemoFactory->createByOrder($order); + $invoice = $this->fintectureHelper->getInvoiceByOrder($order); + if (!$invoice) { + $this->fintectureLogger->error('Apply refund', [ + 'message' => 'No invoice found', + 'orderIncrementId' => $order->getIncrementId(), + ]); + + return false; + } + $creditmemo = $this->creditmemoFactory->createByInvoice($invoice); return $this->apply($order, $creditmemo, $amount); } diff --git a/Gateway/Http/DummyTransferFactory.php b/Gateway/Http/DummyTransferFactory.php index 6e752dc..eb43be3 100644 --- a/Gateway/Http/DummyTransferFactory.php +++ b/Gateway/Http/DummyTransferFactory.php @@ -39,7 +39,7 @@ public function __construct( */ public function create(array $request) { - return $this->transferBuilder // ignored... + return $this->transferBuilder ->setBody($request) ->setMethod('POST') ->build(); diff --git a/Helper/Fintecture.php b/Helper/Fintecture.php index 3703b4c..29aeef9 100644 --- a/Helper/Fintecture.php +++ b/Helper/Fintecture.php @@ -15,6 +15,7 @@ use Magento\Sales\Api\TransactionRepositoryInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Creditmemo; +use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment\Transaction; use Magento\Sales\Model\Order\Status\History; use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory; @@ -134,6 +135,19 @@ public function getSessionIdByOrderId(string $orderId): ?string return null; } + public function getInvoiceByOrder(Order $order): ?Invoice + { + $invoices = $order->getInvoiceCollection(); + if ($invoices->count() === 0) { + return null; + } + + /** @var Invoice $invoice */ + $invoice = $invoices->getLastItem(); + + return $invoice; + } + public function getCreditmemoByTransactionId(OrderInterface $order, string $creditmemoTransactionId): ?Creditmemo { try { diff --git a/composer.json b/composer.json index 45c4925..0a3d722 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "email": "contact@fintecture.com" }, "type": "magento2-module", - "version": "3.5.0", + "version": "3.5.1", "license": [ "GPL-3.0" ], diff --git a/etc/module.xml b/etc/module.xml index a8b1e53..9d871ac 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - +