Skip to content

Commit

Permalink
Merge pull request #458 from mollie/release/2.3.0
Browse files Browse the repository at this point in the history
Release/2.3.0
  • Loading branch information
Marvin-Magmodules authored Nov 9, 2021
2 parents a3c211c + 3f3f880 commit 926e132
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
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-continuous-integration-test-branch 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 phpstan/phpstan:0.*

- name: Run PHPStan
run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse -c /data/extensions/*/phpstan.neon /data/extensions"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\GraphQL\Plugin\Quote\PaymentMethodManagement;

use Magento\Quote\Api\PaymentMethodManagementInterface;
use Mollie\Payment\Model\Methods\CreditcardVault;

class HideNonGrahpQlMethods
{
public function afterGetList(PaymentMethodManagementInterface $subject, array $result)
{
return array_filter($result, function ($method) {
return !$method instanceof CreditcardVault;
});
}
}
28 changes: 14 additions & 14 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ class General extends AbstractHelper
const CURRENCIES_WITHOUT_DECIMAL = ['JPY'];
const SUPPORTED_LOCAL = [
'en_US',
'nl_NL',
'nl_BE',
'fr_FR',
'fr_BE',
'de_DE',
'ca_ES',
'da_DK',
'de_AT',
'de_CH',
'de_DE',
'es_ES',
'ca_ES',
'pt_PT',
'it_IT',
'nb_NO',
'sv_SE',
'fi_FI',
'da_DK',
'is_IS',
'fr_BE',
'fr_FR',
'hu_HU',
'pl_PL',
'it_IT',
'is_IS',
'lv_LV',
'lt_LT'
'lt_LT',
'nb_NO',
'nl_NL',
'nl_BE',
'pl_PL',
'pt_PT',
'sv_SE',
];

const XML_PATH_MODULE_ACTIVE = 'payment/mollie_general/enabled';
Expand Down
2 changes: 1 addition & 1 deletion Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function initialize($paymentAction, $stateObject)
}

/**
* @param Order $order
* @param Order|OrderInterface $order
*
* @return bool|void
* @throws LocalizedException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Observer\CheckoutSubmitAllAfter;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\InstantPurchase\Model\QuoteManagement\PaymentConfiguration;
use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Model\Methods\CreditcardVault;
use Mollie\Payment\Model\Mollie;

class StartTransactionForInstantPurchaseOrders implements ObserverInterface
{
/**
* @var Mollie
*/
private $mollie;

public function __construct(
Mollie $mollie
) {
$this->mollie = $mollie;
}

public function execute(Observer $observer)
{
/** @var OrderInterface $order */
$order = $observer->getData('order');

$payment = $order->getPayment();
$instantPurchase = $payment->getAdditionalInformation(PaymentConfiguration::MARKER);
if (!$instantPurchase || $instantPurchase != 'true') {
return;
}

$method = $payment->getMethodInstance();
if (!$method instanceof CreditcardVault) {
return;
}

$this->mollie->startTransaction($order);
}
}
28 changes: 28 additions & 0 deletions Service/InstantPurchase/AvailabilityCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\InstantPurchase;

use Mollie\Payment\Config;

class AvailabilityCheck implements \Magento\InstantPurchase\PaymentMethodIntegration\AvailabilityCheckerInterface
{
/**
* @var Config
*/
private $config;

public function __construct(
Config $config
) {
$this->config = $config;
}

public function isAvailable(): bool
{
return $this->config->isMagentoVaultEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\GraphQL\Resolver\Checkout;

use Magento\Framework\Encryption\Encryptor;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote;
use Mollie\Payment\Test\Integration\GraphQLTestCase;

class AvailablePaymentMethodsTest extends GraphQLTestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/quote.php
* @magentoDataFixture Magento/Sales/_files/order.php
* @throws \Exception
* @magentoAppArea graphql
*
* @magentoConfigFixture default_store payment/mollie_general/enabled 1
* @magentoConfigFixture default_store payment/mollie_methods_creditcard_vault/active 1
*/
public function testHidesTheVaultMethod()
{
$encryptorMock = $this->createMock(Encryptor::class);
$encryptorMock->method('decrypt')->willReturn('test_dummyapikeywhichmustbe30characterslong');

$this->objectManager->addSharedInstance($encryptorMock, Encryptor::class);

/** @var CartInterface $cart */
$cart = $this->objectManager->create(Quote::class);
$cart->load('test01', 'reserved_order_id');
$cart->setIsMultiShipping(false);
$cart->save();

$maskedQuoteId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class)->execute('test01');

$result = $this->graphQlQuery('query {
cart(cart_id: "' . $maskedQuoteId . '") {
available_payment_methods {
code
title
mollie_meta {
image
}
mollie_available_issuers {
name
code
image
svg
}
}
}
}');

$this->assertFalse(in_array(
'mollie_methods_creditcard_vault',
array_column($result['cart']['available_payment_methods'], 'code')
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Observer\CheckoutSubmitAllAfter;

use Magento\Framework\Event\Observer;
use Magento\InstantPurchase\Model\QuoteManagement\PaymentConfiguration;
use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Model\Methods\CreditcardVault;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForInstantPurchaseOrders;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class StartTransactionForInstantPurchaseOrdersTest extends IntegrationTestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testCallsTheStartTransactionMethod()
{
$mollieMock = $this->createMock(Mollie::class);
$mollieMock->expects($this->once())->method('startTransaction');

$order = $this->loadOrderById('100000001');

// Method must be "mollie_methods_creditcard_vault"
$order->getPayment()->setMethod(CreditcardVault::CODE);

// Additional information "instant-purchase" must be "true".
$order->getPayment()->setAdditionalInformation(PaymentConfiguration::MARKER, 'true');

$observer = $this->objectManager->create(Observer::class);
$observer->setData('order', $order);

/** @var StartTransactionForInstantPurchaseOrders $instance */
$instance = $this->objectManager->create(StartTransactionForInstantPurchaseOrders::class, [
'mollie' => $mollieMock,
]);

$instance->execute($observer);
}
}
2 changes: 1 addition & 1 deletion 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": "2.2.0",
"version": "2.3.0",
"keywords": [
"mollie",
"payment",
Expand Down
3 changes: 2 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@
<label>Language Payment Page</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\Locale</source_model>
<config_path>payment/mollie_general/locale</config_path>
<comment><![CDATA[Let Mollie automatically detect the language or force the language from the store view.]]></comment>
<comment><![CDATA[<strong>Autodetect:</strong> Let Mollie detect the locale depending on the user. However, the locale from the current store view is used when using the Orders API for the used payment method.<br>
<strong>Store Locale</strong>: Use the locale active in the current store or fall back to English if this can't be determined.]]></comment>
</field>
<field id="transaction_details" translate="label" type="select" sortOrder="80" showInDefault="1"
showInWebsite="0" showInStore="0">
Expand Down
6 changes: 5 additions & 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>v2.2.0</version>
<version>v2.3.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down Expand Up @@ -133,6 +133,10 @@
<can_cancel>1</can_cancel>
<can_authorize>0</can_authorize>
<can_authorize_vault>1</can_authorize_vault>
<instant_purchase>
<supported>1</supported>
<available>Mollie\Payment\Service\InstantPurchase\AvailabilityCheck</available>
</instant_purchase>
</mollie_methods_creditcard>
<mollie_methods_creditcard_vault>
<title>Stored Card (Mollie)</title>
Expand Down
6 changes: 6 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@
</arguments>
</type>

<type name="Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForInstantPurchaseOrders">
<arguments>
<argument name="mollie" xsi:type="object">Mollie\Payment\Model\Mollie\Proxy</argument>
</arguments>
</type>

<!-- Payment methods configuration start -->
<!-- ApplePay -->
<type name="Mollie\Payment\Model\Methods\ApplePay">
Expand Down
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@
<event name="checkout_allow_guest">
<observer name="mollie_force_customer_login_when_ordering_a_recurring_product" instance="Mollie\Payment\Observer\CheckoutAllowGuest\ForceCustomerLoginWhenSubscriptionItemInCart" />
</event>
<event name="checkout_submit_all_after">
<observer name="mollie_startransaction_for_instant_purchase_orders" instance="Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForInstantPurchaseOrders" />
</event>
</config>
4 changes: 4 additions & 0 deletions etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
<type name="Magento\QuoteGraphQl\Model\Resolver\PlaceOrder">
<plugin name="mollie_set_the_redirect_url" type="Mollie\Payment\GraphQL\Plugin\PlaceOrder\SetTheRedirectUrl" />
</type>

<type name="Magento\Quote\Api\PaymentMethodManagementInterface">
<plugin name="mollie_hide_non_graphql_methods" type="Mollie\Payment\GraphQL\Plugin\Quote\PaymentMethodManagement\HideNonGrahpQlMethods" />
</type>
</config>
1 change: 1 addition & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ enum PaymentStatusEnum {
REFUNDED
ERROR
FAILED
OPEN
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function ($, Component, Mollie) {
};

data['additional_data'] = _.extend(data['additional_data'], this.additionalData);
this.vaultEnabler.visitAdditionalData(data);
this.getVaultEnabler().visitAdditionalData(data);

return data;
},
Expand Down

0 comments on commit 926e132

Please sign in to comment.