Skip to content

Commit 27f7c42

Browse files
Merge pull request #89 from hugofintecture/3.5.1
3.5.1
2 parents 8484a1e + a6d09f7 commit 27f7c42

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

Gateway/Config/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Config extends BaseConfig
88
{
99
const CODE = 'fintecture';
10-
const VERSION = '3.5.0';
10+
const VERSION = '3.5.1';
1111

1212
const KEY_SHOP_NAME = 'general/store_information/name';
1313
const KEY_ACTIVE = 'active';

Gateway/HandlePayment.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Fintecture\Payment\Helper\Fintecture as FintectureHelper;
88
use Fintecture\Payment\Logger\Logger;
99
use Magento\Framework\DB\Transaction;
10-
use Magento\Sales\Api\Data\TransactionInterface;
1110
use Magento\Sales\Api\InvoiceRepositoryInterface;
1211
use Magento\Sales\Api\OrderManagementInterface;
1312
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
@@ -140,6 +139,8 @@ public function create(
140139
$payment->setAmountPaid($paidAmount);
141140
$payment->setBaseAmountPaid($basePaidAmount);
142141

142+
$payment->setTransactionId($params['sessionId']);
143+
143144
$this->paymentRepository->save($payment);
144145

145146
$transaction = $this->transactionBuilder->setPayment($payment)
@@ -153,7 +154,7 @@ public function create(
153154
'type' => $params['type'],
154155
]])
155156
->setFailSafe(true)
156-
->build(TransactionInterface::TYPE_CAPTURE);
157+
->build(Payment\Transaction::TYPE_CAPTURE);
157158

158159
$this->transactionRepository->save($transaction);
159160

@@ -208,14 +209,15 @@ public function sendInvoice(Order $order, array $params): void
208209
if ($this->fintectureHelper->isStatusAlreadyFinal($order)
209210
&& $order->canInvoice() && $this->config->isInvoicingActive()) {
210211
$invoice = $this->invoiceService->prepareInvoice($order);
212+
$invoice->setRequestedCaptureCase(Order\Invoice::CAPTURE_ONLINE);
211213
$invoice->setTransactionId($params['sessionId']);
212214
$invoice->register();
213215
$invoice->pay();
214216
$this->invoiceRepository->save($invoice);
215-
$transactionSave = $this->transaction
217+
$transaction = $this->transaction
216218
->addObject($invoice)
217219
->addObject($invoice->getOrder());
218-
$transactionSave->save();
220+
$transaction->save();
219221
// Send Invoice mail to customer
220222
$this->invoiceSender->send($invoice);
221223

Gateway/HandleRefund.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,16 @@ public function applyWithoutCreditmemo(Order $order, float $amount): bool
198198

199199
// Create a credit memo only for a full refund
200200
if ($isFullRefund) {
201-
$creditmemo = $this->creditmemoFactory->createByOrder($order);
201+
$invoice = $this->fintectureHelper->getInvoiceByOrder($order);
202+
if (!$invoice) {
203+
$this->fintectureLogger->error('Apply refund', [
204+
'message' => 'No invoice found',
205+
'orderIncrementId' => $order->getIncrementId(),
206+
]);
207+
208+
return false;
209+
}
210+
$creditmemo = $this->creditmemoFactory->createByInvoice($invoice);
202211

203212
return $this->apply($order, $creditmemo, $amount);
204213
}

Gateway/Http/DummyTransferFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
*/
4040
public function create(array $request)
4141
{
42-
return $this->transferBuilder // ignored...
42+
return $this->transferBuilder
4343
->setBody($request)
4444
->setMethod('POST')
4545
->build();

Helper/Fintecture.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Sales\Api\TransactionRepositoryInterface;
1616
use Magento\Sales\Model\Order;
1717
use Magento\Sales\Model\Order\Creditmemo;
18+
use Magento\Sales\Model\Order\Invoice;
1819
use Magento\Sales\Model\Order\Payment\Transaction;
1920
use Magento\Sales\Model\Order\Status\History;
2021
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory;
@@ -134,6 +135,19 @@ public function getSessionIdByOrderId(string $orderId): ?string
134135
return null;
135136
}
136137

138+
public function getInvoiceByOrder(Order $order): ?Invoice
139+
{
140+
$invoices = $order->getInvoiceCollection();
141+
if ($invoices->count() === 0) {
142+
return null;
143+
}
144+
145+
/** @var Invoice $invoice */
146+
$invoice = $invoices->getLastItem();
147+
148+
return $invoice;
149+
}
150+
137151
public function getCreditmemoByTransactionId(OrderInterface $order, string $creditmemoTransactionId): ?Creditmemo
138152
{
139153
try {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"email": "[email protected]"
88
},
99
"type": "magento2-module",
10-
"version": "3.5.0",
10+
"version": "3.5.1",
1111
"license": [
1212
"GPL-3.0"
1313
],

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="Fintecture_Payment" setup_version="3.5.0">
4+
<module name="Fintecture_Payment" setup_version="3.5.1">
55
<sequence>
66
<module name="Magento_Sales"/>
77
<module name="Magento_Payment"/>

0 commit comments

Comments
 (0)