Skip to content

Commit

Permalink
Merge pull request #2574 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 9.4.1
  • Loading branch information
candemiralp authored Apr 5, 2024
2 parents 9014493 + 0de9c66 commit f80d67c
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mftf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Functional Tests
on:
workflow_dispatch:
pull_request:
branches: [main, develop]
branches: [main]

jobs:
build:
Expand Down
4 changes: 3 additions & 1 deletion Helper/OpenInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function getOpenInvoiceDataForCreditMemo(Order\Creditmemo $creditMemo)
$formFields = ['lineItems' => []];

foreach ($creditMemo->getItems() as $creditmemoItem) {
if ($creditmemoItem->getQty() <= 0) {
// Child items only identifies the variant data and doesn't contain line item information.
$isChildItem = $creditmemoItem->getOrderItem()->getParentItem() !== null;
if ($creditmemoItem->getQty() <= 0 || $isChildItem) {
continue;
}

Expand Down
9 changes: 3 additions & 6 deletions Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
use Adyen\AdyenException;
use Adyen\Client;
use Adyen\ConnectionException;
use Adyen\Payment\Helper\Util\PaymentMethodUtil;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\Ui\Adminhtml\AdyenMotoConfigProvider;
use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider;
use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
use Adyen\Util\ManualCapture;
use Exception;
use Magento\Framework\App\Area;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\AbstractHelper;
Expand All @@ -42,6 +41,7 @@
use Magento\Store\Model\Store;
use Magento\Vault\Api\PaymentTokenRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;

class PaymentMethods extends AbstractHelper
{
const ADYEN_HPP = 'adyen_hpp';
Expand Down Expand Up @@ -85,7 +85,6 @@ class PaymentMethods extends AbstractHelper
protected \Magento\Quote\Model\Quote $quote;
private ChargedCurrency $chargedCurrency;
private Config $configHelper;
private ManualCapture $manualCapture;
private SerializerInterface $serializer;
private PaymentTokenRepositoryInterface $paymentTokenRepository;
private SearchCriteriaBuilder $searchCriteriaBuilder;
Expand All @@ -105,7 +104,6 @@ public function __construct(
ChargedCurrency $chargedCurrency,
Config $configHelper,
MagentoDataHelper $dataHelper,
ManualCapture $manualCapture,
SerializerInterface $serializer,
AdyenDataHelper $adyenDataHelper,
PaymentTokenRepositoryInterface $paymentTokenRepository,
Expand All @@ -125,7 +123,6 @@ public function __construct(
$this->chargedCurrency = $chargedCurrency;
$this->configHelper = $configHelper;
$this->dataHelper = $dataHelper;
$this->manualCapture = $manualCapture;
$this->serializer = $serializer;
$this->adyenDataHelper = $adyenDataHelper;
$this->paymentTokenRepository = $paymentTokenRepository;
Expand Down Expand Up @@ -519,7 +516,7 @@ public function getCcAvailableTypesByAlt(): array
public function isAutoCapture(Order $order, string $notificationPaymentMethod): bool
{
// validate if payment methods allows manual capture
if ($this->manualCapture->isManualCaptureSupported($notificationPaymentMethod)) {
if (PaymentMethodUtil::isManualCaptureSupported($notificationPaymentMethod)) {
$captureMode = trim(
(string) $this->configHelper->getConfigData(
'capture_mode',
Expand Down
4 changes: 4 additions & 0 deletions Helper/Util/PaymentMethodUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PaymentMethodUtil
'laser',
'paypal',
'sepadirectdebit',
'ach',
'dankort',
'elo',
'hipercard',
Expand All @@ -42,6 +43,9 @@ class PaymentMethodUtil
'paywithgoogle',
'mc_googlepay',
'visa_googlepay',
'amex_googlepay',
'discover_googlepay',
'maestro_googlepay',
'svs',
'givex',
'valuelink',
Expand Down
6 changes: 5 additions & 1 deletion Model/AdyenAmountCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public function getAmountWithDiscount()

public function getCalculatedTaxPercentage()
{
return $this->getTaxAmount() / ($this->getAmountWithDiscount()) * 100;
if ($this->getAmountWithDiscount() > 0) {
return ($this->getTaxAmount() / $this->getAmountWithDiscount()) * 100;
} else {
return 0;
}
}
}
61 changes: 49 additions & 12 deletions Observer/BeforeShipmentObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,81 @@

use Adyen\Payment\Helper\Data as AdyenHelper;
use Adyen\Payment\Helper\Config as ConfigHelper;
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Observer\AdyenPaymentMethodDataAssignObserver;
use Exception;
use Magento\Framework\Event\Observer;
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
{
const XML_ADYEN_ABSTRACT_PREFIX = "adyen_abstract";
const ONSHIPMENT_CAPTURE_OPENINVOICE = 'onshipment';

private $adyenHelper;
/**
* @var AdyenHelper
*/
private AdyenHelper $adyenHelper;

private $configHelper;
/**
* @var ConfigHelper
*/
private ConfigHelper $configHelper;

/**
* @var LoggerInterface
*/
private $logger;
private LoggerInterface $logger;

/**
* @var InvoiceRepository
*/
private $invoiceRepository;
private InvoiceRepository $invoiceRepository;

/**
* @var PaymentMethods
*/
private PaymentMethods $paymentMethodsHelper;

/**
* BeforeShipmentObserver constructor.
*
* @param AdyenHelper $adyenHelper
* @param ConfigHelper $configHelper
* @param AdyenLogger $logger
* @param InvoiceRepository $invoiceRepository
* @param PaymentMethods $paymentMethodsHelper
*/
public function __construct(
AdyenHelper $adyenHelper,
ConfigHelper $configHelper,
AdyenLogger $logger,
InvoiceRepository $invoiceRepository
InvoiceRepository $invoiceRepository,
PaymentMethods $paymentMethodsHelper
) {
$this->adyenHelper = $adyenHelper;
$this->configHelper = $configHelper;
$this->logger = $logger;
$this->invoiceRepository = $invoiceRepository;
$this->paymentMethodsHelper = $paymentMethodsHelper;
}

/**
* @param Observer $observer
* @throws Exception
*/
public function execute(Observer $observer)
public function execute(Observer $observer): void
{
/** @var Shipment $shipment */
$shipment = $observer->getEvent()->getData('shipment');
$order = $shipment->getOrder();
$paymentMethod = $order->getPayment()->getMethod();

if (!$this->isPaymentMethodAdyen($order)) {
if (!$this->paymentMethodsHelper->isAdyenPayment($paymentMethod)) {
$this->logger->info(
"Payment method is not from Adyen for order id {$order->getId()}",
['observer' => 'BeforeShipmentObserver']
Expand Down Expand Up @@ -116,26 +131,48 @@ public function execute(Observer $observer)
}

try {
$invoice = $order->prepareInvoice();
$itemsToBeInvoiced = $this->itemsToBeInvoiced($shipment);

$invoice = $order->prepareInvoice($itemsToBeInvoiced);
$invoice->getOrder()->setIsInProcess(true);

// set transaction id so you can do a online refund from credit memo
// set transaction id, so you can do an online refund from credit memo
$pspReference = $order->getPayment()->getAdyenPspReference();
$invoice->setTransactionId($pspReference);
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
$invoice->register();
$this->invoiceRepository->save($invoice);
} catch (Throwable $e) {
} catch (Exception $e) {
$this->logger->error($e);
throw new Exception('Error saving invoice. The error message is: ' . $e->getMessage());
}
}

/**
* @deprecated Use isAdyenPayment() method from Adyen\Payment\Helper\PaymentMethods.
*
* Determine if the payment method is Adyen
*/
public function isPaymentMethodAdyen($order)
{
return strpos((string) $order->getPayment()->getMethod(), 'adyen') !== false;
}

/**
* Builds the invoice item array in the form of "ORDER_ITEM_ID => QTY"
*
* @param Shipment $shipment
* @return array
*/
private function itemsToBeInvoiced(Shipment $shipment): array
{
$shipmentItems = $shipment->getItems();
$invoiceItems = [];

foreach ($shipmentItems as $shipmentItem) {
$invoiceItems[$shipmentItem->getOrderItemId()] = $shipmentItem->getQty();
}

return $invoiceItems;
}
}
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reporting Security Issues

We welcome reports of possible vulnerabilities or issues as part of our responsible disclosure program. For more information go to
https://support.adyen.com/hc/en-us/articles/115001187330-How-do-I-report-a-possible-security-issue-to-Adyen-
[this page](https://www.adyen.com/policies-and-disclaimer/responsible-disclosure).
8 changes: 1 addition & 7 deletions Setup/Patch/Data/CreateStatusAuthorized.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\StatusFactory;
use Magento\Sales\Model\ResourceModel\Order\StatusFactory as StatusResourceFactory;
use Magento\Sales\Model\ResourceModel\Order\Status as StatusResource;

class CreateStatusAuthorized implements DataPatchInterface, PatchVersionInterface
class CreateStatusAuthorized implements DataPatchInterface
{
private ModuleDataSetupInterface $moduleDataSetup;
private WriterInterface $configWriter;
Expand Down Expand Up @@ -103,9 +102,4 @@ public static function getDependencies(): array
{
return [];
}

public static function getVersion(): string
{
return '9.0.3';
}
}
10 changes: 1 addition & 9 deletions Setup/Patch/Data/CreditCardsBecomeCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

class CreditCardsBecomeCards implements DataPatchInterface, PatchVersionInterface
class CreditCardsBecomeCards implements DataPatchInterface
{
private ModuleDataSetupInterface $moduleDataSetup;

Expand Down Expand Up @@ -65,12 +65,4 @@ public static function getDependencies()
{
return [];
}

/**
* @inheritDoc
*/
public static function getVersion()
{
return '9.0.5';
}
}
8 changes: 1 addition & 7 deletions Setup/Patch/Data/RatepayIdConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

class RatepayIdConfiguration implements DataPatchInterface, PatchVersionInterface
class RatepayIdConfiguration implements DataPatchInterface
{
private ModuleDataSetupInterface $moduleDataSetup;
private WriterInterface $configWriter;
Expand Down Expand Up @@ -96,9 +95,4 @@ public static function getDependencies(): array
{
return [];
}

public static function getVersion(): string
{
return '9.0.0';
}
}
15 changes: 1 addition & 14 deletions Setup/Patch/Data/RemoveMinMaxOrderConfigMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

namespace Adyen\Payment\Setup\Patch\Data;

use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

class RemoveMinMaxOrderConfigMigration implements DataPatchInterface, PatchVersionInterface
class RemoveMinMaxOrderConfigMigration implements DataPatchInterface
{
private ModuleDataSetupInterface $moduleDataSetup;
private ReinitableConfigInterface $reinitableConfig;

public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
ReinitableConfigInterface $reinitableConfig
)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->reinitableConfig = $reinitableConfig;
}

/**
Expand Down Expand Up @@ -67,12 +62,4 @@ public static function getDependencies()
{
return [];
}

/**
* @inheritDoc
*/
public static function getVersion()
{
return '9.0.0';
}
}
1 change: 0 additions & 1 deletion Setup/Patch/Data/VaultMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\PaymentTokenManagementInterface;
use Magento\Vault\Api\PaymentTokenRepositoryInterface;

Expand Down
Loading

0 comments on commit f80d67c

Please sign in to comment.