Skip to content

Commit

Permalink
Merge pull request #400 from mollie/1.26.1
Browse files Browse the repository at this point in the history
1.26.1
  • Loading branch information
Marvin-Magmodules authored Jun 16, 2021
2 parents 972140e + 286c3eb commit c79def2
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: Codesniffer with the Magento EcgM2 standard
on: push
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Run codesniffer
run:
docker run
--volume $(pwd)/:/app/data
michielgerritsen/magento-coding-standard:latest
--severity=10
--ignore-annotations
10 changes: 6 additions & 4 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Integration Tests

on: push
on: [push, pull_request]

jobs:
build:
Expand All @@ -17,13 +16,16 @@ jobs:
MAGENTO_VERSION: 2.4.2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Start Docker
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker-compose -f .github/workflows/templates/docker-compose.yml up -d

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2 @dev
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch

- name: Enable developer mode
run: docker exec magento-project-community-edition php bin/magento deploy:mode:set developer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint PHP files
on: push
on: [push, pull_request]

jobs:
php-70:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: phpstan

on: [push, pull_request]

jobs:
Expand All @@ -20,11 +19,14 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/

- name: Install the extensions in Magento
run: docker exec magento-project-community-edition composer require mollie/magento2:@dev fooman/phpstan-magento2-magic-methods:^0.7
run: docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch fooman/phpstan-magento2-magic-methods:^0.7

- name: Run PHPStan
run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse -c /data/extensions/*/phpstan.neon /data/extensions"
6 changes: 4 additions & 2 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: setup:di:compile

on: [push, pull_request]

jobs:
Expand All @@ -20,11 +19,14 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/

- name: Install the extension in Magento
run: docker exec magento-project-community-edition composer require mollie/magento2:@dev
run: docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch

- name: Run setup:di:compile
run: docker exec magento-project-community-edition php bin/magento setup:di:compile
7 changes: 5 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Unit Tests
on: push
on: [push, pull_request]

jobs:
build:
Expand All @@ -19,8 +19,11 @@ jobs:
- name: Start Docker
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker-compose -f .github/workflows/templates/docker-compose.yml up -d

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2 @dev
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch

- name: Run tests
run: docker exec magento-project-community-edition bash -c "vendor/bin/phpunit extensions/*/Test/Unit"
1 change: 1 addition & 0 deletions GraphQL/DataProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
Expand Down
17 changes: 17 additions & 0 deletions GraphQL/Replaces/AdditionalDataProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Cart\Payment;

/**
* This class is available in default Magento 2.3.3 versions and higher. But due to Composer replace techniques, this
* class is sometimes missing. So check if it's available, and if not, create an empty variant. It's then only used
* for class generation in the setup:di:compile process.
*/
if (!interface_exists(AdditionalDataProviderInterface::class)) {
interface AdditionalDataProviderInterface {}
}
37 changes: 37 additions & 0 deletions Service/Order/Lines/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function get(OrderInterface $order)
$orderLines[] = $this->paymentFee->getOrderLine($order, $this->forceBaseCurrency);
}

if ($adjustment = $this->getAdjustment($order, $orderLines)) {
$orderLines[] = $adjustment;
}

$this->saveOrderLines($orderLines, $order);
foreach ($orderLines as &$orderLine) {
unset($orderLine['item_id']);
Expand Down Expand Up @@ -325,4 +329,37 @@ private function getProductUrl(OrderItemInterface $item)

return $url;
}

private function getAdjustment(OrderInterface $order, array $orderLines)
{
$orderLinesTotal = 0;
foreach ($orderLines as $orderLine) {
$orderLinesTotal += $orderLine['totalAmount']['value'];
}

$grandTotal = $order->getGrandTotal();
if ($this->forceBaseCurrency) {
$grandTotal = $order->getBaseGrandTotal();
}

$max = $orderLinesTotal + 0.05;
$min = $orderLinesTotal - 0.05;
if (($min <= $grandTotal) && ($grandTotal <= $max)) {
$difference = $grandTotal - $orderLinesTotal;

return [
'item_id' => '',
'type' => 'discount',
'name' => 'Adjustment',
'quantity' => 1,
'unitPrice' => $this->mollieHelper->getAmountArray($this->currency, $difference),
'totalAmount' => $this->mollieHelper->getAmountArray($this->currency, $difference),
'vatRate' => sprintf("%.2f", 0),
'vatAmount' => $this->mollieHelper->getAmountArray($this->currency, 0),
'sku' => 'adjustment',
];
}

return false;
}
}
67 changes: 67 additions & 0 deletions Test/Integration/Service/Order/Lines/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,71 @@ public function testTheSkuGetsTruncated()
$line = array_shift($result);
$this->assertEquals(substr($sku, 0, 64), $line['sku']);
}

/**
* @dataProvider adjustmentsDataProvider
* @magentoDataFixture Magento/Sales/_files/order_with_bundle.php
*/
public function testAddsAdjustmentsWhenTheTotalIsOff($adjustment)
{
$order = $this->loadOrderById('100000001');
$order->setBaseGrandTotal($order->getBaseGrandTotal() + $adjustment);

foreach ($order->getItems() as $item) {
$item->setBaseRowTotal(50);
}

/** @var Subject $instance */
$instance = $this->objectManager->get(Subject::class);

$result = $instance->get($order);
$lastLine = end($result);

$this->assertEquals('discount', $lastLine['type']);
$this->assertEquals($adjustment, $lastLine['totalAmount']['value']);

$total = 0;
foreach ($result as $orderLine) {
$total += $orderLine['totalAmount']['value'];
}

$this->assertEquals($order->getBaseGrandTotal(), $total);
}

/**
* @magentoDataFixture Magento/Sales/_files/order_with_bundle.php
*/
public function testDoesNotAddTheAdjustmentsWhenTheTotalIsMoreThanFiveCents()
{
$order = $this->loadOrderById('100000001');
$order->setBaseGrandTotal($order->getBaseGrandTotal() + 0.06);

foreach ($order->getItems() as $item) {
$item->setBaseRowTotal(50);
}

/** @var Subject $instance */
$instance = $this->objectManager->get(Subject::class);

$result = $instance->get($order);
$lastLine = end($result);

$this->assertNotEquals('discount', $lastLine['type']);
}

public function adjustmentsDataProvider(): array
{
return [
[-0.05],
[-0.04],
[-0.03],
[-0.02],
[-0.01],
[0.01],
[0.02],
[0.03],
[0.04],
[0.05],
];
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mollie/magento2",
"description": "Mollie Payment Module for Magento 2",
"version": "1.26.0",
"version": "1.26.1",
"keywords": [
"mollie",
"payment",
Expand Down Expand Up @@ -56,7 +56,8 @@
],
"autoload": {
"files": [
"registration.php"
"registration.php",
"GraphQL/Replaces/AdditionalDataProviderInterface.php"
],
"psr-4": {
"Mollie\\Payment\\": ""
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<default>
<payment>
<mollie_general>
<version>v1.26.0</version>
<version>v1.26.1</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
15 changes: 15 additions & 0 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<policies>
<policy id="script-src">
<values>
<value id="mollie-components" type="host">js.mollie.com</value>
</values>
</policy>
<policy id="img-src">
<values>
<value id="mollie-images" type="host">https://www.mollie.com</value>
</values>
</policy>
</policies>
</csp_whitelist>

0 comments on commit c79def2

Please sign in to comment.