We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 6a7bb718 authored by Attila Kiss's avatar Attila Kiss Committed by GitHub

Merge pull request #759 from Adyen/develop

Release 6.2.1
parents 7b2f7171 0f77b4b4
...@@ -100,7 +100,10 @@ class CaptureDataBuilder implements BuilderInterface ...@@ -100,7 +100,10 @@ class CaptureDataBuilder implements BuilderInterface
// The latest invoice will contain only the selected items(and quantities) for the (partial) capture // The latest invoice will contain only the selected items(and quantities) for the (partial) capture
$latestInvoice = $invoices->getLastItem(); $latestInvoice = $invoices->getLastItem();
foreach ($latestInvoice->getItems() as $invoiceItem) { foreach ($latestInvoice->getItems() as $invoiceItem) {
if ($invoiceItem->getOrderItem()->getParentItem()) {
continue;
}
++$count; ++$count;
$numberOfItems = (int)$invoiceItem->getQty(); $numberOfItems = (int)$invoiceItem->getQty();
$formFields = $this->adyenHelper->createOpenInvoiceLineItem( $formFields = $this->adyenHelper->createOpenInvoiceLineItem(
......
...@@ -24,60 +24,112 @@ ...@@ -24,60 +24,112 @@
namespace Adyen\Payment\Observer\Adminhtml; namespace Adyen\Payment\Observer\Adminhtml;
use Adyen\Payment\Helper\Data as AdyenHelper;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Observer\AdyenHppDataAssignObserver;
use Exception;
use Magento\Framework\Event\Observer; use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver; use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\InvoiceRepository;
use Magento\Sales\Model\Order\Shipment;
use Psr\Log\LoggerInterface;
use Throwable;
class BeforeShipmentObserver extends AbstractDataAssignObserver class BeforeShipmentObserver extends AbstractDataAssignObserver
{ {
private $adyenHelper; private $adyenHelper;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var InvoiceRepository
*/
private $invoiceRepository;
/** /**
* BeforeShipmentObserver constructor. * BeforeShipmentObserver constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param AdyenHelper $adyenHelper
* @param AdyenLogger $logger
* @param InvoiceRepository $invoiceRepository
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper AdyenHelper $adyenHelper,
AdyenLogger $logger,
InvoiceRepository $invoiceRepository
) { ) {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->logger = $logger;
$this->invoiceRepository = $invoiceRepository;
} }
/** /**
* @param Observer $observer * @param Observer $observer
* @throws \Magento\Framework\Exception\LocalizedException * @throws Exception
*/ */
public function execute(Observer $observer) public function execute(Observer $observer)
{ {
$shipment = $observer->getEvent()->getShipment(); /** @var Shipment $shipment */
$shipment = $observer->getEvent()->getData('shipment');
$order = $shipment->getOrder(); $order = $shipment->getOrder();
if (!$this->isPaymentMethodAdyen($order)) {
$this->logger->info(
"Payment method is not from Adyen for order id {$order->getId()}",
['observer' => 'BeforeShipmentObserver']
);
return;
}
$captureOnShipment = $this->adyenHelper->getConfigData( $captureOnShipment = $this->adyenHelper->getConfigData(
'capture_on_shipment', 'capture_on_shipment',
'adyen_abstract', 'adyen_abstract',
$order->getStoreId() $order->getStoreId()
); );
if ($this->isPaymentMethodAdyen($order) && $captureOnShipment) { if (!$captureOnShipment) {
$payment = $order->getPayment(); $this->logger->info(
$brandCode = $payment->getAdditionalInformation( "Capture on shipment not configured for order id {$order->getId()}",
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE ['observer' => 'BeforeShipmentObserver']
); );
return;
}
$payment = $order->getPayment();
$brandCode = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE);
if (!$this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$this->logger->info(
"Payment method is from Adyen but isn't OpenInvoice for order id {$order->getId()}",
['observer' => 'BeforeShipmentObserver']
);
return;
}
if (!$order->canInvoice()) {
$this->logger->info(
"Cannot invoice order with id {$order->getId()}",
['observer' => 'BeforeShipmentObserver']
);
return;
}
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) { try {
if ($order->canInvoice()) { $invoice = $order->prepareInvoice();
try { $invoice->getOrder()->setIsInProcess(true);
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// set transaction id so you can do a online refund from credit memo // set transaction id so you can do a online refund from credit memo
$pspReference = $order->getPayment()->getAdyenPspReference(); $pspReference = $order->getPayment()->getAdyenPspReference();
$invoice->setTransactionId($pspReference); $invoice->setTransactionId($pspReference);
$invoice->register()->pay(); $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
$invoice->save(); $invoice->register()->pay();
} catch (\Exception $e) { $this->invoiceRepository->save($invoice);
throw new \Exception(sprintf('Error saving invoice. The error message is:', $e->getMessage())); } catch (Throwable $e) {
} $this->logger->error($e);
} throw new Exception('Error saving invoice. The error message is: ' . $e->getMessage());
}
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "adyen/module-payment", "name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.", "description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module", "type": "magento2-module",
"version": "6.2.0", "version": "6.2.1",
"license": [ "license": [
"OSL-3.0", "OSL-3.0",
"AFL-3.0" "AFL-3.0"
......
...@@ -900,13 +900,6 @@ ...@@ -900,13 +900,6 @@
</arguments> </arguments>
</virtualType> </virtualType>
<!--Checkout Response validator-->
<virtualType name="CheckoutResponseValidator" type="Adyen\Payment\Gateway\Validator\CheckoutResponseValidator">
<arguments>
<argument name="loggerInterface" xsi:type="object">Adyen\Payment\Logger\AdyenLogger</argument>
</arguments>
</virtualType>
<virtualType name="PosCloudResponseValidator" type="Adyen\Payment\Gateway\Validator\PosCloudResponseValidator"> <virtualType name="PosCloudResponseValidator" type="Adyen\Payment\Gateway\Validator\PosCloudResponseValidator">
<arguments> <arguments>
<argument name="loggerInterface" xsi:type="object">Adyen\Payment\Logger\AdyenLogger</argument> <argument name="loggerInterface" xsi:type="object">Adyen\Payment\Logger\AdyenLogger</argument>
......
...@@ -111,7 +111,7 @@ $ccExpYear = $block->getInfoData('cc_exp_year'); ...@@ -111,7 +111,7 @@ $ccExpYear = $block->getInfoData('cc_exp_year');
*/ */
var secureFieldsInitialize = function () { var secureFieldsInitialize = function () {
if (!"<?php $block->getCheckoutOriginKeys(); ?>") { if (!"<?= $block->getCheckoutOriginKeys(); ?>") {
document.getElementById('noApiKey').style = "visibility: visible; display:inline-block"; document.getElementById('noApiKey').style = "visibility: visible; display:inline-block";
return; return;
} }
......
...@@ -65,12 +65,6 @@ define( ...@@ -65,12 +65,6 @@ define(
getCode: function () { getCode: function () {
return 'adyen_google_pay'; return 'adyen_google_pay';
}, },
getData: function () {
return {
'method': this.item.method,
'additional_data': {}
};
},
isActive: function () { isActive: function () {
return true; return true;
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment