Skip to content

Commit 4fbfd36

Browse files
Release version 4.0.4
1 parent 41c9ab7 commit 4fbfd36

File tree

14 files changed

+134
-111
lines changed

14 files changed

+134
-111
lines changed

Block/Adminhtml/System/Config/Fieldset/Payment.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

Gateway/Validator/StockItemsValidator.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ class StockItemsValidator implements \Afterpay\Afterpay\Model\Spi\StockItemsVali
1010
private $getItemsToDeductFromShipment;
1111
private $defaultSourceProvider;
1212

13+
/**
14+
* We avoid strict types in constructor for create instances dynamically look at
15+
* \Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy
16+
* @param \Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode
17+
* @param \Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider
18+
* @param \Magento\InventoryShipping\Model\GetItemsToDeductFromShipment $getItemsToDeductFromShipment
19+
* @param \Magento\InventoryShipping\Model\SourceDeductionRequestFromShipmentFactory $sourceDeductionRequestFromShipmentFactory
20+
* @param \Afterpay\Afterpay\Model\Spi\SourceValidatorServiceInterface $sourceValidatorService
21+
*/
1322
public function __construct(
14-
\Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode,
15-
\Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider,
16-
\Magento\InventoryShipping\Model\GetItemsToDeductFromShipment $getItemsToDeductFromShipment,
17-
\Magento\InventoryShipping\Model\SourceDeductionRequestFromShipmentFactory $sourceDeductionRequestFromShipmentFactory,
18-
\Magento\InventorySourceDeductionApi\Model\SourceDeductionServiceInterface $sourceValidatorService
23+
$isSingleSourceMode,
24+
$defaultSourceProvider,
25+
$getItemsToDeductFromShipment,
26+
$sourceDeductionRequestFromShipmentFactory,
27+
$sourceValidatorService
1928
) {
2029
$this->isSingleSourceMode = $isSingleSourceMode;
2130
$this->defaultSourceProvider = $defaultSourceProvider;

Model/SourceValidatorService.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22

33
namespace Afterpay\Afterpay\Model;
44

5-
class SourceValidatorService implements \Magento\InventorySourceDeductionApi\Model\SourceDeductionServiceInterface
5+
class SourceValidatorService implements \Afterpay\Afterpay\Model\Spi\SourceValidatorServiceInterface
66
{
77
private $getStockBySalesChannel;
88
private $getStockItemConfiguration;
99
private $getSourceItemBySourceCodeAndSku;
1010

11+
/**
12+
* We avoid strict types in constructor for create instances dynamically look at
13+
* \Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy
14+
* @param \Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku
15+
* @param \Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfiguration
16+
* @param \Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface $getStockBySalesChannel
17+
*/
1118
public function __construct(
12-
\Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku,
13-
\Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface $getStockItemConfiguration,
14-
\Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface $getStockBySalesChannel
19+
$getSourceItemBySourceCodeAndSku,
20+
$getStockItemConfiguration,
21+
$getStockBySalesChannel
1522
) {
1623
$this->getSourceItemBySourceCodeAndSku = $getSourceItemBySourceCodeAndSku;
1724
$this->getStockItemConfiguration = $getStockItemConfiguration;
1825
$this->getStockBySalesChannel = $getStockBySalesChannel;
1926
}
2027

2128
/**
22-
* @inheritdoc
29+
* Check if shipment items have enough quantity in case of no throws exception
30+
* @throws \Magento\Framework\Exception\LocalizedException
31+
* @throws \Magento\Framework\Exception\NoSuchEntityException
32+
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
2333
*/
2434
public function execute(\Magento\InventorySourceDeductionApi\Model\SourceDeductionRequestInterface $sourceDeductionRequest): void
2535
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Afterpay\Afterpay\Model\Spi;
5+
6+
/**
7+
* Process source validation
8+
*
9+
* @api
10+
*/
11+
interface SourceValidatorServiceInterface
12+
{
13+
/**
14+
* @param SourceDeductionRequestInterface $sourceDeductionRequest
15+
* @return void
16+
*/
17+
public function execute(\Magento\InventorySourceDeductionApi\Model\SourceDeductionRequestInterface $sourceDeductionRequest): void;
18+
}

Model/Spi/StockItemsValidatorInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
interface StockItemsValidatorInterface
66
{
77
/**
8-
* @throws \Magento\Framework\Validation\ValidationException
8+
* Check if shipment items have enough quantity in case of no throws exception
9+
* @throws \Magento\Framework\Exception\LocalizedException
10+
* @throws \Magento\Framework\Exception\NoSuchEntityException
11+
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
912
*/
1013
public function validate(\Magento\Sales\Model\Order\Shipment $shipment): void;
1114
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Afterpay\Afterpay\Model\StockItemsValidator;
4+
5+
use Magento\Framework\App\ObjectManager;
6+
7+
class StockItemsValidatorProxy implements \Afterpay\Afterpay\Model\Spi\StockItemsValidatorInterface, \Magento\Framework\ObjectManager\NoninterceptableInterface
8+
{
9+
private $subject = null;
10+
private $stockItemValidatorFactory;
11+
private $sourceValidatorServiceFactory;
12+
private $moduleManager;
13+
14+
public function __construct(
15+
\Afterpay\Afterpay\Gateway\Validator\StockItemsValidatorFactory $stockItemsValidatorFactory,
16+
\Afterpay\Afterpay\Model\SourceValidatorServiceFactory $sourceValidatorServiceFactory,
17+
\Magento\Framework\Module\Manager $moduleManager
18+
) {
19+
$this->stockItemValidatorFactory = $stockItemsValidatorFactory;
20+
$this->sourceValidatorServiceFactory = $sourceValidatorServiceFactory;
21+
$this->moduleManager = $moduleManager;
22+
}
23+
24+
/**
25+
* Check msi functionality existing if no then skip validation
26+
* @throws \Magento\Framework\Exception\LocalizedException
27+
* @throws \Magento\Framework\Exception\NoSuchEntityException
28+
* @throws \Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException
29+
*/
30+
public function validate(\Magento\Sales\Model\Order\Shipment $shipment): void
31+
{
32+
if (!$this->moduleManager->isEnabled('Magento_InventoryCatalogApi') ||
33+
!$this->moduleManager->isEnabled('Magento_InventoryShipping') ||
34+
!$this->moduleManager->isEnabled('Magento_InventorySourceDeductionApi') ||
35+
!$this->moduleManager->isEnabled('Magento_InventoryConfigurationApi') ||
36+
!$this->moduleManager->isEnabled('Magento_InventorySalesApi')
37+
) {
38+
return;
39+
}
40+
$stockItemsValidator = $this->getStockItemValidator();
41+
$stockItemsValidator->validate($shipment);
42+
}
43+
44+
private function getStockItemValidator(): \Afterpay\Afterpay\Model\Spi\StockItemsValidatorInterface
45+
{
46+
if ($this->subject == null) {
47+
$objectManager = ObjectManager::getInstance();
48+
$sourceValidatorService = $this->sourceValidatorServiceFactory->create([
49+
'getSourceItemBySourceCodeAndSku' => $objectManager->create('\\Magento\\InventorySourceDeductionApi\\Model\\GetSourceItemBySourceCodeAndSku'),
50+
'getStockItemConfiguration' => $objectManager->create('\\Magento\\InventoryConfigurationApi\\Api\\GetStockItemConfigurationInterface'),
51+
'getStockBySalesChannel' => $objectManager->create('\\Magento\\InventorySalesApi\\Api\\GetStockBySalesChannelInterface'),
52+
]);
53+
$this->subject = $this->stockItemValidatorFactory->create([
54+
'isSingleSourceMode' => $objectManager->create('\\Magento\\InventoryCatalogApi\\Model\\IsSingleSourceModeInterface'),
55+
'defaultSourceProvider' => $objectManager->create('\\Magento\\InventoryCatalogApi\\Api\\DefaultSourceProviderInterface'),
56+
'getItemsToDeductFromShipment' => $objectManager->create('\\Magento\\InventoryShipping\\Model\\GetItemsToDeductFromShipment'),
57+
'sourceDeductionRequestFromShipmentFactory' => $objectManager->create('\\Magento\\InventoryShipping\\Model\\SourceDeductionRequestFromShipmentFactory'),
58+
'sourceValidatorService' => $sourceValidatorService,
59+
]);
60+
}
61+
return $this->subject;
62+
}
63+
}

Observer/Adminhtml/ConfigSaveAfter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3333
{
3434
/** @var array $changedPaths */
3535
$changedPaths = $observer->getData('changed_paths');
36+
if (!is_array($changedPaths)) {
37+
return;
38+
}
3639
$isAfterpayConfigChanged = count(array_intersect($changedPaths, self::AFTERPAY_CONFIGS)) > 0;
3740
if ($isAfterpayConfigChanged || count(array_intersect($changedPaths, self::CONFIGS_PATHS_TO_TRACK)) > 0) {
3841
$websiteId = $observer->getData('website');

Plugin/Block/Adminhtml/Order/View.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public function afterAddButton(
1414
$result,
1515
$buttonId
1616
) {
17+
if ($buttonId !== 'order_creditmemo') {
18+
return $result;
19+
}
1720
$order = $orderView->getOrder();
1821
$payment = $order->getPayment();
1922
if ($payment == null) {
2023
return $result;
2124
}
22-
if ($payment->getMethod() == \Afterpay\Afterpay\Gateway\Config\Config::CODE
23-
&& $buttonId == 'order_creditmemo') {
25+
if ($payment->getMethod() === \Afterpay\Afterpay\Gateway\Config\Config::CODE) {
2426
$orderView->removeButton($buttonId);
2527
}
2628
return $result;

Setup/Patch/Data/AdaptCapturedDiscounts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function getNewOrdersAdditionalInfo(array $paymentsInfo): array
6868
$additionalInfo[AdditionalInformationInterface::AFTERPAY_CAPTURED_DISCOUNT] = $totalDiscountAmount;
6969
if ($additionalInfo[AdditionalInformationInterface::AFTERPAY_PAYMENT_STATE] != PaymentStateInterface::CAPTURED) {
7070
$additionalInfo[AdditionalInformationInterface::AFTERPAY_CAPTURED_DISCOUNT] -=
71-
$additionalInfo[AdditionalInformationInterface::AFTERPAY_ROLLOVER_DISCOUNT];
71+
$additionalInfo[AdditionalInformationInterface::AFTERPAY_ROLLOVER_DISCOUNT] ?? 0;
7272
}
7373
$ordersAdditionalInfo[$payment['order_id']] = $additionalInfo;
7474
}

Setup/Patch/Data/AdaptPayments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class AdaptPayments implements \Magento\Framework\Setup\Patch\DataPatchInterface
66
{
7-
private const METHOD_CODE = 'afterpaypayovertime';
7+
protected const METHOD_CODE = 'afterpaypayovertime';
88

99
private $salesSetup;
1010

@@ -35,7 +35,7 @@ public function apply(): self
3535
'replace(additional_information, "afterpay_payment_status", "afterpay_payment_state")'
3636
)
3737
],
38-
['method = ?' => self::METHOD_CODE]
38+
['method = ?' => static::METHOD_CODE]
3939
);
4040

4141
return $this;

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license": "Apache-2.0",
44
"type": "magento2-module",
55
"description": "Magento 2 Afterpay Payment Module",
6-
"version": "4.0.2",
6+
"version": "4.0.4",
77
"require": {
88
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
99
"magento/framework": "^102.0",
@@ -24,5 +24,11 @@
2424
"psr-4": {
2525
"Afterpay\\Afterpay\\": ""
2626
}
27+
},
28+
"repositories": {
29+
"warning": {
30+
"type": "composer",
31+
"url": "https://raw.githubusercontent.com/afterpay/magento-2/develop/packages.json?token=GHSAT0AAAAAABOYPU7VUV5K2PRN6PHQGVV2YVB5HLQ"
32+
}
2733
}
2834
}

etc/di.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
<type name="Afterpay\Afterpay\Gateway\Http\Client\Client">
162162
<arguments>
163163
<argument name="debugLogger" xsi:type="object">AfterpayDebugLogger</argument>
164+
<argument name="client" xsi:type="object" shared="false">\Magento\Framework\HTTP\ClientInterface</argument>
164165
</arguments>
165166
</type>
166167

@@ -258,12 +259,6 @@
258259
<type name="Magento\Payment\Model\Checks\SpecificationFactory">
259260
<plugin name="afterpay_add_additional_checks" type="Afterpay\Afterpay\Plugin\Model\Checks\SpecificationFactory" />
260261
</type>
261-
262-
<type name="Afterpay\Afterpay\Gateway\Validator\StockItemsValidator">
263-
<arguments>
264-
<argument name="sourceValidatorService" xsi:type="object">Afterpay\Afterpay\Model\SourceValidatorService</argument>
265-
</arguments>
266-
</type>
267262
<virtualType name="Afterpay\Afterpay\Logger" type="Magento\Framework\Logger\Monolog">
268263
<arguments>
269264
<argument name="name" xsi:type="const">Afterpay\Afterpay\Gateway\Config\Config::CODE</argument>
@@ -288,7 +283,7 @@
288283
<type name="Afterpay\Afterpay\Model\Order\Shipment\CaptureProcessor">
289284
<arguments>
290285
<argument name="authCaptureCommand" xsi:type="object">Afterpay\Afterpay\Gateway\Command\AuthCaptureCommand</argument>
291-
<argument name="stockItemsValidator" xsi:type="object">Afterpay\Afterpay\Gateway\Validator\StockItemsValidator</argument>
286+
<argument name="stockItemsValidator" xsi:type="object">Afterpay\Afterpay\Model\StockItemsValidator\StockItemsValidatorProxy</argument>
292287
</arguments>
293288
</type>
294289
<type name="Afterpay\Afterpay\Model\CheckoutManagement\CheckoutManagement">

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="Afterpay_Afterpay" setup_version="5.0.1-rc2">
4+
<module name="Afterpay_Afterpay" setup_version="4.0.4">
55
<sequence>
66
<module name="Magento_Payment"/>
77
<module name="Magento_Checkout"/>

view/frontend/web/css/afterpay-checkout.less

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,6 @@
55
color: #a0a0a0;
66
text-align: center;
77
}
8-
.afterpay-checkout-note-header {
9-
h3 {
10-
color: #00a4e4;
11-
text-align: left;
12-
}
13-
}
14-
ul {
15-
padding-left: 1rem;
16-
padding-right: 1rem;
17-
li {
18-
width: 24%;
19-
display: inline-block;
20-
}
21-
&.cost {
22-
li {
23-
font-size: 1.8rem;
24-
color: #153F72;
25-
}
26-
}
27-
&.icon {
28-
.afterpay_checkout_steps {
29-
background-size: 18px 18px;
30-
vertical-align: middle;
31-
display: inline-block;
32-
height: 18px;
33-
width: 18px;
34-
}
35-
.afterpay_checkout_steps_1 {
36-
background-image: url(https://static.afterpay.com/checkout/[email protected]);
37-
}
38-
.afterpay_checkout_steps_2 {
39-
background-image: url(https://static.afterpay.com/checkout/[email protected]);
40-
}
41-
.afterpay_checkout_steps_3 {
42-
background-image: url(https://static.afterpay.com/checkout/[email protected]);
43-
}
44-
.afterpay_checkout_steps_4 {
45-
background-image: url(https://static.afterpay.com/checkout/[email protected]);
46-
}
47-
}
48-
}
498
}
509
.payment-method-content {
5110
overflow: hidden;

0 commit comments

Comments
 (0)