Skip to content

Commit

Permalink
Release version 4.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Aug 16, 2022
1 parent 41c9ab7 commit 4fbfd36
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 111 deletions.
45 changes: 0 additions & 45 deletions Block/Adminhtml/System/Config/Fieldset/Payment.php

This file was deleted.

19 changes: 14 additions & 5 deletions Gateway/Validator/StockItemsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ class StockItemsValidator implements \Afterpay\Afterpay\Model\Spi\StockItemsVali
private $getItemsToDeductFromShipment;
private $defaultSourceProvider;

/**
* We avoid strict types in constructor for create instances dynamically look at
* \Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy
* @param \Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode
* @param \Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider
* @param \Magento\InventoryShipping\Model\GetItemsToDeductFromShipment $getItemsToDeductFromShipment
* @param \Magento\InventoryShipping\Model\SourceDeductionRequestFromShipmentFactory $sourceDeductionRequestFromShipmentFactory
* @param \Afterpay\Afterpay\Model\Spi\SourceValidatorServiceInterface $sourceValidatorService
*/
public function __construct(
\Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode,
\Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider,
\Magento\InventoryShipping\Model\GetItemsToDeductFromShipment $getItemsToDeductFromShipment,
\Magento\InventoryShipping\Model\SourceDeductionRequestFromShipmentFactory $sourceDeductionRequestFromShipmentFactory,
\Magento\InventorySourceDeductionApi\Model\SourceDeductionServiceInterface $sourceValidatorService
$isSingleSourceMode,
$defaultSourceProvider,
$getItemsToDeductFromShipment,
$sourceDeductionRequestFromShipmentFactory,
$sourceValidatorService
) {
$this->isSingleSourceMode = $isSingleSourceMode;
$this->defaultSourceProvider = $defaultSourceProvider;
Expand Down
20 changes: 15 additions & 5 deletions Model/SourceValidatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@

namespace Afterpay\Afterpay\Model;

class SourceValidatorService implements \Magento\InventorySourceDeductionApi\Model\SourceDeductionServiceInterface
class SourceValidatorService implements \Afterpay\Afterpay\Model\Spi\SourceValidatorServiceInterface
{
private $getStockBySalesChannel;
private $getStockItemConfiguration;
private $getSourceItemBySourceCodeAndSku;

/**
* We avoid strict types in constructor for create instances dynamically look at
* \Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy
* @param \Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku
* @param \Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfiguration
* @param \Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface $getStockBySalesChannel
*/
public function __construct(
\Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku,
\Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfiguration,
\Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface $getStockBySalesChannel
$getSourceItemBySourceCodeAndSku,
$getStockItemConfiguration,
$getStockBySalesChannel
) {
$this->getSourceItemBySourceCodeAndSku = $getSourceItemBySourceCodeAndSku;
$this->getStockItemConfiguration = $getStockItemConfiguration;
$this->getStockBySalesChannel = $getStockBySalesChannel;
}

/**
* @inheritdoc
* Check if shipment items have enough quantity in case of no throws exception
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
*/
public function execute(\Magento\InventorySourceDeductionApi\Model\SourceDeductionRequestInterface $sourceDeductionRequest): void
{
Expand Down
18 changes: 18 additions & 0 deletions Model/Spi/SourceValidatorServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Afterpay\Afterpay\Model\Spi;

/**
* Process source validation
*
* @api
*/
interface SourceValidatorServiceInterface
{
/**
* @param SourceDeductionRequestInterface $sourceDeductionRequest
* @return void
*/
public function execute(\Magento\InventorySourceDeductionApi\Model\SourceDeductionRequestInterface $sourceDeductionRequest): void;
}
5 changes: 4 additions & 1 deletion Model/Spi/StockItemsValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
interface StockItemsValidatorInterface
{
/**
* @throws \Magento\Framework\Validation\ValidationException
* Check if shipment items have enough quantity in case of no throws exception
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
*/
public function validate(\Magento\Sales\Model\Order\Shipment $shipment): void;
}
63 changes: 63 additions & 0 deletions Model/StockItemsValidator/StockItemsValidatorProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php declare(strict_types=1);

namespace Afterpay\Afterpay\Model\StockItemsValidator;

use Magento\Framework\App\ObjectManager;

class StockItemsValidatorProxy implements \Afterpay\Afterpay\Model\Spi\StockItemsValidatorInterface, \Magento\Framework\ObjectManager\NoninterceptableInterface
{
private $subject = null;
private $stockItemValidatorFactory;
private $sourceValidatorServiceFactory;
private $moduleManager;

public function __construct(
\Afterpay\Afterpay\Gateway\Validator\StockItemsValidatorFactory $stockItemsValidatorFactory,
\Afterpay\Afterpay\Model\SourceValidatorServiceFactory $sourceValidatorServiceFactory,
\Magento\Framework\Module\Manager $moduleManager
) {
$this->stockItemValidatorFactory = $stockItemsValidatorFactory;
$this->sourceValidatorServiceFactory = $sourceValidatorServiceFactory;
$this->moduleManager = $moduleManager;
}

/**
* Check msi functionality existing if no then skip validation
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
*/
public function validate(\Magento\Sales\Model\Order\Shipment $shipment): void
{
if (!$this->moduleManager->isEnabled('Magento_InventoryCatalogApi') ||
!$this->moduleManager->isEnabled('Magento_InventoryShipping') ||
!$this->moduleManager->isEnabled('Magento_InventorySourceDeductionApi') ||
!$this->moduleManager->isEnabled('Magento_InventoryConfigurationApi') ||
!$this->moduleManager->isEnabled('Magento_InventorySalesApi')
) {
return;
}
$stockItemsValidator = $this->getStockItemValidator();
$stockItemsValidator->validate($shipment);
}

private function getStockItemValidator(): \Afterpay\Afterpay\Model\Spi\StockItemsValidatorInterface
{
if ($this->subject == null) {
$objectManager = ObjectManager::getInstance();
$sourceValidatorService = $this->sourceValidatorServiceFactory->create([
'getSourceItemBySourceCodeAndSku' => $objectManager->create('\\Magento\\InventorySourceDeductionApi\\Model\\GetSourceItemBySourceCodeAndSku'),
'getStockItemConfiguration' => $objectManager->create('\\Magento\\InventoryConfigurationApi\\Api\\GetStockItemConfigurationInterface'),
'getStockBySalesChannel' => $objectManager->create('\\Magento\\InventorySalesApi\\Api\\GetStockBySalesChannelInterface'),
]);
$this->subject = $this->stockItemValidatorFactory->create([
'isSingleSourceMode' => $objectManager->create('\\Magento\\InventoryCatalogApi\\Model\\IsSingleSourceModeInterface'),
'defaultSourceProvider' => $objectManager->create('\\Magento\\InventoryCatalogApi\\Api\\DefaultSourceProviderInterface'),
'getItemsToDeductFromShipment' => $objectManager->create('\\Magento\\InventoryShipping\\Model\\GetItemsToDeductFromShipment'),
'sourceDeductionRequestFromShipmentFactory' => $objectManager->create('\\Magento\\InventoryShipping\\Model\\SourceDeductionRequestFromShipmentFactory'),
'sourceValidatorService' => $sourceValidatorService,
]);
}
return $this->subject;
}
}
3 changes: 3 additions & 0 deletions Observer/Adminhtml/ConfigSaveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var array $changedPaths */
$changedPaths = $observer->getData('changed_paths');
if (!is_array($changedPaths)) {
return;
}
$isAfterpayConfigChanged = count(array_intersect($changedPaths, self::AFTERPAY_CONFIGS)) > 0;
if ($isAfterpayConfigChanged || count(array_intersect($changedPaths, self::CONFIGS_PATHS_TO_TRACK)) > 0) {
$websiteId = $observer->getData('website');
Expand Down
6 changes: 4 additions & 2 deletions Plugin/Block/Adminhtml/Order/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public function afterAddButton(
$result,
$buttonId
) {
if ($buttonId !== 'order_creditmemo') {
return $result;
}
$order = $orderView->getOrder();
$payment = $order->getPayment();
if ($payment == null) {
return $result;
}
if ($payment->getMethod() == \Afterpay\Afterpay\Gateway\Config\Config::CODE
&& $buttonId == 'order_creditmemo') {
if ($payment->getMethod() === \Afterpay\Afterpay\Gateway\Config\Config::CODE) {
$orderView->removeButton($buttonId);
}
return $result;
Expand Down
2 changes: 1 addition & 1 deletion Setup/Patch/Data/AdaptCapturedDiscounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function getNewOrdersAdditionalInfo(array $paymentsInfo): array
$additionalInfo[AdditionalInformationInterface::AFTERPAY_CAPTURED_DISCOUNT] = $totalDiscountAmount;
if ($additionalInfo[AdditionalInformationInterface::AFTERPAY_PAYMENT_STATE] != PaymentStateInterface::CAPTURED) {
$additionalInfo[AdditionalInformationInterface::AFTERPAY_CAPTURED_DISCOUNT] -=
$additionalInfo[AdditionalInformationInterface::AFTERPAY_ROLLOVER_DISCOUNT];
$additionalInfo[AdditionalInformationInterface::AFTERPAY_ROLLOVER_DISCOUNT] ?? 0;
}
$ordersAdditionalInfo[$payment['order_id']] = $additionalInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions Setup/Patch/Data/AdaptPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AdaptPayments implements \Magento\Framework\Setup\Patch\DataPatchInterface
{
private const METHOD_CODE = 'afterpaypayovertime';
protected const METHOD_CODE = 'afterpaypayovertime';

private $salesSetup;

Expand Down Expand Up @@ -35,7 +35,7 @@ public function apply(): self
'replace(additional_information, "afterpay_payment_status", "afterpay_payment_state")'
)
],
['method = ?' => self::METHOD_CODE]
['method = ?' => static::METHOD_CODE]
);

return $this;
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "Apache-2.0",
"type": "magento2-module",
"description": "Magento 2 Afterpay Payment Module",
"version": "4.0.2",
"version": "4.0.4",
"require": {
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
"magento/framework": "^102.0",
Expand All @@ -24,5 +24,11 @@
"psr-4": {
"Afterpay\\Afterpay\\": ""
}
},
"repositories": {
"warning": {
"type": "composer",
"url": "https://raw.githubusercontent.com/afterpay/magento-2/develop/packages.json?token=GHSAT0AAAAAABOYPU7VUV5K2PRN6PHQGVV2YVB5HLQ"
}
}
}
9 changes: 2 additions & 7 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<type name="Afterpay\Afterpay\Gateway\Http\Client\Client">
<arguments>
<argument name="debugLogger" xsi:type="object">AfterpayDebugLogger</argument>
<argument name="client" xsi:type="object" shared="false">\Magento\Framework\HTTP\ClientInterface</argument>
</arguments>
</type>

Expand Down Expand Up @@ -258,12 +259,6 @@
<type name="Magento\Payment\Model\Checks\SpecificationFactory">
<plugin name="afterpay_add_additional_checks" type="Afterpay\Afterpay\Plugin\Model\Checks\SpecificationFactory" />
</type>

<type name="Afterpay\Afterpay\Gateway\Validator\StockItemsValidator">
<arguments>
<argument name="sourceValidatorService" xsi:type="object">Afterpay\Afterpay\Model\SourceValidatorService</argument>
</arguments>
</type>
<virtualType name="Afterpay\Afterpay\Logger" type="Magento\Framework\Logger\Monolog">
<arguments>
<argument name="name" xsi:type="const">Afterpay\Afterpay\Gateway\Config\Config::CODE</argument>
Expand All @@ -288,7 +283,7 @@
<type name="Afterpay\Afterpay\Model\Order\Shipment\CaptureProcessor">
<arguments>
<argument name="authCaptureCommand" xsi:type="object">Afterpay\Afterpay\Gateway\Command\AuthCaptureCommand</argument>
<argument name="stockItemsValidator" xsi:type="object">Afterpay\Afterpay\Gateway\Validator\StockItemsValidator</argument>
<argument name="stockItemsValidator" xsi:type="object">Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy</argument>
</arguments>
</type>
<type name="Afterpay\Afterpay\Model\CheckoutManagement\CheckoutManagement">
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Afterpay_Afterpay" setup_version="5.0.1-rc2">
<module name="Afterpay_Afterpay" setup_version="4.0.4">
<sequence>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
Expand Down
41 changes: 0 additions & 41 deletions view/frontend/web/css/afterpay-checkout.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,6 @@
color: #a0a0a0;
text-align: center;
}
.afterpay-checkout-note-header {
h3 {
color: #00a4e4;
text-align: left;
}
}
ul {
padding-left: 1rem;
padding-right: 1rem;
li {
width: 24%;
display: inline-block;
}
&.cost {
li {
font-size: 1.8rem;
color: #153F72;
}
}
&.icon {
.afterpay_checkout_steps {
background-size: 18px 18px;
vertical-align: middle;
display: inline-block;
height: 18px;
width: 18px;
}
.afterpay_checkout_steps_1 {
background-image: url(https://static.afterpay.com/checkout/[email protected]);
}
.afterpay_checkout_steps_2 {
background-image: url(https://static.afterpay.com/checkout/[email protected]);
}
.afterpay_checkout_steps_3 {
background-image: url(https://static.afterpay.com/checkout/[email protected]);
}
.afterpay_checkout_steps_4 {
background-image: url(https://static.afterpay.com/checkout/[email protected]);
}
}
}
}
.payment-method-content {
overflow: hidden;
Expand Down

0 comments on commit 4fbfd36

Please sign in to comment.