Skip to content

Commit

Permalink
Merge pull request #10 from michielgerritsen/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Marvin-Magmodules authored May 23, 2024
2 parents 95340df + 839a5af commit 3f34f26
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Run codesniffer
run:
Expand Down
28 changes: 6 additions & 22 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,23 @@ jobs:
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.5
- PHP_VERSION: php83-fpm
MAGENTO_VERSION: 2.4.7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Public repository
- uses: actions/checkout@v2
if: "!contains(github.repository, 'magmodules')"
with:
repository: mollie/magento2
path: mollie-base
ref: master

# Internal repository
- uses: actions/checkout@v2
if: "contains(github.repository, 'magmodules')"
with:
repository: magmodules/mollie-magento2
path: mollie-base
ssh-key: ${{ secrets.MAGMODULES_MOLLIE_MAGENTO2_KEY }}
- uses: actions/checkout@v4

- 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: Remove version from composer.json
run: sed -i '/version/d' ./composer.json && sed -i '/version/d' ./mollie-base/composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd)/mollie-base/ magento-project-community-edition:/data/extensions/mollie-magento2/ && rm -rf mollie-base/ && docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/

- name: Install Mollie and Mollie Multishipping extensions
run: docker exec magento-project-community-edition composer require mollie/magento2:"dev-master as 2.99.99" mollie/magento2-multishipping:@dev -vvv
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-multishipping:@dev

- name: Enable modules
run: docker exec magento-project-community-edition bash -c "php bin/magento module:enable Mollie_Payment Mollie_Multishipping && php bin/magento setup:upgrade"
Expand Down
24 changes: 8 additions & 16 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ name: Lint PHP files
on: [push, pull_request]

jobs:
php-71:
php-73:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-72:
php-74:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-73:
php-81:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-74:
php-82:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]
28 changes: 6 additions & 22 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,23 @@ jobs:
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.5
- PHP_VERSION: php83-fpm
MAGENTO_VERSION: 2.4.7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Public repository
- uses: actions/checkout@v2
if: "!contains(github.repository, 'magmodules')"
with:
repository: mollie/magento2
path: mollie-base
ref: master

# Internal repository
- uses: actions/checkout@v2
if: "contains(github.repository, 'magmodules')"
with:
repository: magmodules/mollie-magento2
path: mollie-base
ssh-key: ${{ secrets.MAGMODULES_MOLLIE_MAGENTO2_KEY }}
- uses: actions/checkout@v4

- 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: Remove version from composer.json
run: sed -i '/version/d' ./composer.json && sed -i '/version/d' ./mollie-base/composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd)/mollie-base/ magento-project-community-edition:/data/extensions/mollie-magento2/ && rm -rf mollie-base/ && docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/

- name: Install Mollie and Mollie Multishipping extensions
run: docker exec magento-project-community-edition composer require mollie/magento2:"dev-master as 2.99.99" mollie/magento2-multishipping:@dev
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-multishipping:@dev

- name: Run PHPStan
run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse -c /data/extensions/mollie-magento2-multishipping/phpstan.neon /data/extensions/mollie-magento2-multishipping"
28 changes: 6 additions & 22 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,23 @@ jobs:
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.5
- PHP_VERSION: php83-fpm
MAGENTO_VERSION: 2.4.7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Public repository
- uses: actions/checkout@v2
if: "!contains(github.repository, 'magmodules')"
with:
repository: mollie/magento2
path: mollie-base
ref: master

# Internal repository
- uses: actions/checkout@v2
if: "contains(github.repository, 'magmodules')"
with:
repository: magmodules/mollie-magento2
path: mollie-base
ssh-key: ${{ secrets.MAGMODULES_MOLLIE_MAGENTO2_KEY }}
- uses: actions/checkout@v4

- 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: Remove version from composer.json
run: sed -i '/version/d' ./composer.json && sed -i '/version/d' ./mollie-base/composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd)/mollie-base/ magento-project-community-edition:/data/extensions/mollie-magento2/ && rm -rf mollie-base/ && docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/mollie-magento2-multishipping/

- name: Install Mollie and Mollie Multishipping extensions
run: docker exec magento-project-community-edition composer require mollie/magento2:"dev-master as 2.99.99" mollie/magento2-multishipping:@dev
run: docker exec magento-project-community-edition ./install-composer-package mollie/magento2 mollie/magento2-multishipping:@dev

- name: Run setup:di:compile
run: docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile"
44 changes: 36 additions & 8 deletions PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Mollie\Payment\Model\Client\Payments;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Order\BuildTransaction;
use Mollie\Payment\Service\Order\MethodCode;
use Mollie\Payment\Service\Order\Transaction;
use Mollie\Payment\Service\PaymentToken\PaymentTokenForOrder;

Expand Down Expand Up @@ -75,6 +76,10 @@ class PlaceOrder implements PlaceOrderInterface
* @var PaymentTokenForOrder
*/
private $paymentTokenForOrder;
/**
* @var MethodCode
*/
private $methodCode;

public function __construct(
OrderManagementInterface $orderManagement,
Expand All @@ -86,7 +91,8 @@ public function __construct(
BuildTransaction $buildTransaction,
CheckoutUrl $checkoutUrl,
TransactionDescription $transactionDescription,
PaymentTokenForOrder $paymentTokenForOrder
PaymentTokenForOrder $paymentTokenForOrder,
MethodCode $methodCode
) {
$this->orderManagement = $orderManagement;
$this->mollieModel = $mollieModel;
Expand All @@ -98,6 +104,7 @@ public function __construct(
$this->checkoutUrl = $checkoutUrl;
$this->transactionDescription = $transactionDescription;
$this->paymentTokenForOrder = $paymentTokenForOrder;
$this->methodCode = $methodCode;
}

/**
Expand All @@ -107,13 +114,24 @@ public function __construct(
public function place(array $orderList): array
{
try {
$mollieOrders = [];
foreach ($orderList as $order) {
$this->orderManagement->place($order);
if (substr($order->getPayment()->getMethod(), 0, 6) === 'mollie') {
// Only process Mollie orders; some orders _could_ have been paid with 'free' method.
$mollieOrders[] = $order;
}
}

$firstOrder = reset($orderList);
if (count($mollieOrders) === 0) {
// This situation should not happen, as the quote would then have 'free' payment method.
// This class will then never be called. But to be sure...
return $this->errorList;
}

$firstOrder = reset($mollieOrders);
$storeId = $firstOrder->getStoreId();
$paymentData = $this->buildPaymentData($orderList, $storeId);
$paymentData = $this->buildPaymentData($mollieOrders, $storeId);

$paymentData = $this->mollieHelper->validatePaymentData($paymentData);
$this->mollieHelper->addTolog('request', $paymentData);
Expand All @@ -133,7 +151,7 @@ public function place(array $orderList): array
return $errorList;
}

foreach ($orderList as $order) {
foreach ($mollieOrders as $order) {
try {
$this->molliePaymentsApi->processResponse($order, $paymentResponse);
} catch (\Exception $exception) {
Expand Down Expand Up @@ -171,21 +189,21 @@ private function getTotalAmount(array $orderList)
private function buildPaymentData(array $orderList, $storeId): array
{
$firstOrder = reset($orderList);
$paymentToken = $this->paymentTokenForOrder->execute($firstOrder);
$method = $this->mollieHelper->getMethodCode($firstOrder);
$paymentTokens = $this->getPaymentTokens($orderList);
$method = $this->methodCode->execute($firstOrder);
$orderIds = array_map(function (OrderInterface $order) { return $order->getEntityId(); }, $orderList);

$paymentData = [
'amount' => $this->getTotalAmount($orderList),
'description' => $this->transactionDescription->forMultishippingTransaction($storeId),
'billingAddress' => $this->molliePaymentsApi->getAddressLine($firstOrder->getBillingAddress()),
'redirectUrl' => $this->multishippingTransaction->getRedirectUrl($orderList, $paymentToken),
'redirectUrl' => $this->multishippingTransaction->getRedirectUrl($orderList, $paymentTokens),
'webhookUrl' => $this->transaction->getWebhookUrl($orderList),
'method' => $method,
'metadata' => [
'order_ids' => implode(', ', $orderIds),
'store_id' => $storeId,
'payment_token' => $paymentToken
'payment_token' => implode(', ', $paymentTokens),
],
'locale' => $this->mollieHelper->getLocaleCode($storeId, Payments::CHECKOUT_TYPE),
];
Expand All @@ -201,4 +219,14 @@ private function buildPaymentData(array $orderList, $storeId): array

return $this->buildTransaction->execute($firstOrder, Payments::CHECKOUT_TYPE, $paymentData);
}

public function getPaymentTokens(array $orders): array
{
$output = [];
foreach ($orders as $order) {
$output[] = $this->paymentTokenForOrder->execute($order);
}

return $output;
}
}
8 changes: 4 additions & 4 deletions Service/Order/MultishippingTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function __construct(

/**
* @param OrderInterface[] $orders
* @param string $paymentToken
* @throws \Exception
* @param array $paymentTokens
* @return string
*@throws \Exception
*/
public function getRedirectUrl(array $orders, string $paymentToken): string
public function getRedirectUrl(array $orders, array $paymentTokens): string
{
if (!$orders) {
throw new \Exception('The provided order array is empty');
Expand All @@ -50,7 +50,7 @@ public function getRedirectUrl(array $orders, string $paymentToken): string
$orderIds = array_map( function (OrderInterface $order) { return $order->getId(); }, $orders);
$parameters = http_build_query([
'order_ids' => $orderIds,
'payment_token' => $paymentToken,
'payment_tokens' => $paymentTokens,
'utm_nooverride' => 1,
]);

Expand Down
35 changes: 35 additions & 0 deletions Test/Integration/Configuration/DiXmlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
*
* * Copyright Magmodules.eu. All rights reserved.
* * See COPYING.txt for license details.
*
*/

declare(strict_types=1);

namespace Mollie\Multishipping\Test\Integration\Xml;

use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderPool;
use Mollie\Payment\Service\Mollie\PaymentMethods;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class DiXmlTest extends IntegrationTestCase
{
/**
* @magentoAppArea frontend
* @return void
*/
public function testPlaceOrderPoolHasAllMollieMethods(): void
{
/** @var PlaceOrderPool $instance */
$instance = $this->objectManager->get(PlaceOrderPool::class);

foreach ($this->objectManager->get(PaymentMethods::class)->getCodes() as $code) {
$this->assertNotNull(
$instance->get($code),
sprintf('An instance should be returned for "%s"', $code)
);
}
}
}
Loading

0 comments on commit 3f34f26

Please sign in to comment.