Skip to content

Commit

Permalink
Merge pull request #716 from mollie/release/2.32.3
Browse files Browse the repository at this point in the history
Release/2.32.3
  • Loading branch information
Marvin-Magmodules committed Nov 14, 2023
2 parents 0603caf + 7d2cdb8 commit 296a5a2
Show file tree
Hide file tree
Showing 29 changed files with 1,274 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/end-2-end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ jobs:
MAGENTO_URL=$(docker exec magento-project-community-edition /bin/bash -c "curl -s ngrok:4040/api/tunnels |jq -r \".tunnels[0].public_url\"")
echo "magento_url=$MAGENTO_URL" >> $GITHUB_ENV
# Note the `mollie-pwa.html` file, as it is copied to the pub folder. This is so that it can be accessed by Cypress.
- name: Upload the code into the docker container
run: |
sed -i '/version/d' ./composer.json && \
docker cp $(pwd) magento-project-community-edition:/data/extensions/ && \
docker cp $(pwd)/Test/End-2-end/cypress/fixtures/mollie-pwa.html magento-project-community-edition:/data/pub/opt/ && \
docker exec magento-project-community-edition ./install-composer-package mollie/magento2:@dev
- name: Activate the extension
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/templates/e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM cypress/included:12.1.0

WORKDIR /e2e

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
RUN npm i @cypress/webpack-preprocessor cypress-mollie cypress-testrail --save-dev

CMD tail -f /dev/null
Expand Down
16 changes: 16 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Config
const PAYMENT_CREDITCARD_USE_COMPONENTS = 'payment/mollie_methods_creditcard/use_components';
const PAYMENT_CREDITCARD_ENABLE_CUSTOMERS_API = 'payment/mollie_methods_creditcard/enable_customers_api';
const PAYMENT_BANKTRANSFER_STATUS_PENDING = 'payment/mollie_methods_banktransfer/order_status_pending';
const PAYMENT_METHOD_ISSUER_LIST_TYPE = 'payment/mollie_methods_%s/issuer_list_type';
const PAYMENT_METHOD_PAYMENT_ACTIVE = 'payment/mollie_methods_%s/active';
const PAYMENT_METHOD_PAYMENT_DESCRIPTION = 'payment/mollie_methods_%s/payment_description';
const PAYMENT_METHOD_PAYMENT_SURCHARGE_FIXED_AMOUNT = 'payment/mollie_methods_%s/payment_surcharge_fixed_amount';
Expand All @@ -73,6 +74,7 @@ class Config
const PAYMENT_VOUCHER_CUSTOM_ATTRIBUTE = 'payment/mollie_methods_voucher/custom_attribute';
const CURRENCY_OPTIONS_DEFAULT = 'currency/options/default';


/**
* @var ScopeConfigInterface
*/
Expand Down Expand Up @@ -726,6 +728,20 @@ public function encryptPaymentDetails($storeId = null): bool
return $this->isSetFlag(static::GENERAL_ENCRYPT_PAYMENT_DETAILS, $storeId);
}

/**
* @param string $method
* @param null|int|string $storeId
*
* @return string
*/
public function getIssuerListType(string $method, $storeId = null): string
{
return $this->getPath(
$this->addMethodToPath(static::PAYMENT_METHOD_ISSUER_LIST_TYPE, $method),
$storeId
) ?? 'none';
}

/**
* @param $method
* @return string
Expand Down
95 changes: 19 additions & 76 deletions Controller/ApplePay/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\AddressInterfaceFactory;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Api\Data\PaymentInterfaceFactory;
use Magento\Quote\Api\GuestCartRepositoryInterface;
use Magento\Quote\Api\PaymentMethodManagementInterface;
use Magento\Quote\Api\ShippingMethodManagementInterface;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address\Total as AddressTotal;

class ShippingMethods extends Action
Expand All @@ -33,47 +30,25 @@ class ShippingMethods extends Action
private $guestCartRepository;

/**
* @var AddressInterfaceFactory
*/
private $addressFactory;

/**
* @var PaymentMethodManagementInterface
*/
private $paymentMethodManagement;

/**
* @var PaymentInterfaceFactory
* @var ShippingMethodManagementInterface
*/
private $paymentInterfaceFactory;
private $shippingMethodManagement;

/**
* @var CheckoutSession
*/
private $checkoutSession;

/**
* @var ShippingMethodManagementInterface
*/
private $shippingMethodManagement;

public function __construct(
Context $context,
CartRepositoryInterface $cartRepository,
GuestCartRepositoryInterface $guestCartRepository,
ShippingMethodManagementInterface $shippingMethodManagement,
AddressInterfaceFactory $addressFactory,
PaymentMethodManagementInterface $paymentMethodManagement,
PaymentInterfaceFactory $paymentInterfaceFactory,
CheckoutSession $checkoutSession
CheckoutSession $checkoutSession,
GuestCartRepositoryInterface $guestCartRepository
) {
parent::__construct($context);

$this->guestCartRepository = $guestCartRepository;
$this->shippingMethodManagement = $shippingMethodManagement;
$this->addressFactory = $addressFactory;
$this->paymentMethodManagement = $paymentMethodManagement;
$this->paymentInterfaceFactory = $paymentInterfaceFactory;
$this->guestCartRepository = $guestCartRepository;
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
}
Expand All @@ -82,28 +57,25 @@ public function execute()
{
$cart = $this->getCart();

$address = $this->addressFactory->create();
/**
* @var Address $address
*/
$address = $cart->getShippingAddress();
$address->setData(null);
$address->setCountryId($this->getRequest()->getParam('countryCode'));
$address->setPostcode($this->getRequest()->getParam('postalCode'));

$cart->setShippingAddress($address);

$cart->collectTotals();
$this->cartRepository->save($cart);

if ($this->getRequest()->getParam('shippingMethod')) {
$this->addShippingMethod($cart, $this->getRequest()->getParam('shippingMethod')['identifier']);
$address->setCollectShippingRates(true);
$address->setShippingMethod($this->getRequest()->getParam('shippingMethod')['identifier']);
}

$methods = $this->shippingMethodManagement->getList($cart->getId());
$this->setDefaultShippingMethod($cart, $methods);

/** @var PaymentInterface $payment */
$payment = $this->paymentInterfaceFactory->create();
$payment->setMethod('mollie_methods_applepay');
$this->paymentMethodManagement->set($cart->getId(), $payment);
$cart = $this->cartRepository->get($cart->getId());
$cart->setPaymentMethod('mollie_methods_applepay');
$cart->getPayment()->importData(['method' => 'mollie_methods_applepay']);
$this->cartRepository->save($cart);
$cart->collectTotals();

$methods = $this->shippingMethodManagement->getList($cart->getId());
$response = $this->resultFactory->create(ResultFactory::TYPE_JSON);

return $response->setData([
Expand All @@ -118,43 +90,14 @@ public function execute()
'totals' => array_map(function (AddressTotal $total) {
return [
'type' => 'final',
'code' => $total->getCode(),
'label' => $total->getData('title'),
'amount' => number_format($total->getData('value'), 2, '.', ''),
];
}, array_values($cart->getTotals()))
]);
}

/**
* @param CartInterface $cart
* @param \Magento\Quote\Api\Data\ShippingMethodInterface[] $methods
*/
private function setDefaultShippingMethod(CartInterface $cart, array $methods)
{
if ($cart->getShippingAddress()->getShippingMethod()) {
return;
}

$method = array_shift($methods);
if (!$method) {
return;
}

$this->addShippingMethod($cart, $method->getCarrierCode() . '_' . $method->getMethodCode());
$this->cartRepository->save($cart);
}

private function addShippingMethod(CartInterface $cart, string $identifier)
{
$address = $cart->getShippingAddress();

$address->setShippingMethod($identifier);
$address->setCollectShippingRates(true);
$address->save();

$address->collectShippingRates();
}

/**
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return CartInterface
Expand Down
4 changes: 3 additions & 1 deletion Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,16 @@ public function useImage($storeId = null)
}

/**
* @deprecated See \Mollie\Payment\Config::getIssuerListType instead
*
* @param string $method
*
* @return mixed
*/
public function getIssuerListType(string $method): string
{
$methodXpath = str_replace('%method%', $method, self::XPATH_ISSUER_LIST_TYPE);
return $this->getStoreConfig($methodXpath);
return $this->getStoreConfig($methodXpath) ?? 'none';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function getActiveMethods(MollieApiClient $mollieApi, CartInterface $cart
*/
private function getIssuers(MollieApiClient $mollieApi, string $code, array $config): array
{
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$issuerListType = $this->config->getIssuerListType($code, $this->storeManager->getStore()->getId());
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->getIssuers->execute($mollieApi, $code, $issuerListType);

Expand Down
88 changes: 75 additions & 13 deletions Model/PaymentFee/Quote/Address/Total/PaymentFeeTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@

namespace Mollie\Payment\Model\PaymentFee\Quote\Address\Total;

use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement;
use Magento\Customer\Api\Data\AddressInterfaceFactory as CustomerAddressFactory;
use Magento\Customer\Api\Data\RegionInterfaceFactory as CustomerAddressRegionFactory;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Address\Total;
use Magento\Quote\Model\Quote\Address\Total\AbstractTotal;
use Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory;
use Magento\Tax\Api\Data\QuoteDetailsItemExtensionInterfaceFactory;
use Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory;
use Magento\Tax\Api\Data\TaxClassKeyInterface;
use Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory;
use Magento\Tax\Api\TaxCalculationInterface;
use Magento\Tax\Helper\Data as TaxHelper;
use Magento\Tax\Model\Config as TaxConfig;
use Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector;
use Mollie\Payment\Config;
use Mollie\Payment\Exceptions\UnknownPaymentFeeType;
use Mollie\Payment\Service\Config\PaymentFee as PaymentFeeConfig;
use Mollie\Payment\Service\PaymentFee\Calculate;
use Mollie\Payment\Service\PaymentFee\Result;

class PaymentFeeTax extends AbstractTotal
class PaymentFeeTax extends CommonTaxCollector
{
/**
* @var PaymentFeeConfig
*/
private $paymentFeeConfig;

/**
* @var PriceCurrencyInterface
*/
Expand All @@ -41,14 +46,55 @@ class PaymentFeeTax extends AbstractTotal
private $config;

public function __construct(
PaymentFeeConfig $paymentFeeConfig,
PriceCurrencyInterface $priceCurrency,
TaxConfig $taxConfig,
TaxCalculationInterface $taxCalculationService,
QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory,
QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory,
TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory,
CustomerAddressFactory $customerAddressFactory,
CustomerAddressRegionFactory $customerAddressRegionFactory,
Calculate $calculate,
Config $config
PriceCurrencyInterface $priceCurrency,
Config $config,
TaxHelper $taxHelper = null,
QuoteDetailsItemExtensionInterfaceFactory $quoteDetailsItemExtensionInterfaceFactory = null,
?CustomerAccountManagement $customerAccountManagement = null
) {
$this->paymentFeeConfig = $paymentFeeConfig;
$this->priceCurrency = $priceCurrency;
$parent = new \ReflectionClass(parent::class);
$parentConstructor = $parent->getConstructor();

// The parent call fails when running setup:di:compile in 2.4.3 and lower due to an extra parameter.
if ($parentConstructor->getNumberOfParameters() == 9) {
// @phpstan-ignore-next-line
parent::__construct(
$taxConfig,
$taxCalculationService,
$quoteDetailsDataObjectFactory,
$quoteDetailsItemDataObjectFactory,
$taxClassKeyDataObjectFactory,
$customerAddressFactory,
$customerAddressRegionFactory,
$taxHelper,
$quoteDetailsItemExtensionInterfaceFactory
);
} else {
// @phpstan-ignore-next-line
parent::__construct(
$taxConfig,
$taxCalculationService,
$quoteDetailsDataObjectFactory,
$quoteDetailsItemDataObjectFactory,
$taxClassKeyDataObjectFactory,
$customerAddressFactory,
$customerAddressRegionFactory,
$taxHelper,
$quoteDetailsItemExtensionInterfaceFactory,
$customerAccountManagement
);
}

$this->calculate = $calculate;
$this->priceCurrency = $priceCurrency;
$this->config = $config;
}

Expand All @@ -74,10 +120,26 @@ public function collect(Quote $quote, ShippingAssignmentInterface $shippingAssig

$this->addAssociatedTaxable($shippingAssignment, $result, $quote);

$feeDataObject = $this->quoteDetailsItemDataObjectFactory->create()
->setType('mollie_payment_fee')
->setCode('mollie_payment_fee')
->setQuantity(1);

$feeDataObject->setUnitPrice($result->getRoundedAmount());
$feeDataObject->setTaxClassKey(
$this->taxClassKeyDataObjectFactory->create()
->setType(TaxClassKeyInterface::TYPE_ID)
->setValue(4)
);
$feeDataObject->setIsTaxIncluded(true);

$quoteDetails = $this->prepareQuoteDetails($shippingAssignment, [$feeDataObject]);

$this->taxCalculationService->calculateTax($quoteDetails, $quote->getStoreId());

parent::collect($quote, $shippingAssignment, $total);

$extensionAttributes = $quote->getExtensionAttributes();

if (!$extensionAttributes) {
return $this;
}
Expand Down

0 comments on commit 296a5a2

Please sign in to comment.