Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #715

Merged
merged 19 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c03b4ec
Bugfix: Set a default for the issuer list type #710
michielgerritsen Oct 26, 2023
916893d
Improvement: Added E2E test for refunds
michielgerritsen Oct 26, 2023
26257fb
PIMAG-503: Fix CC locales
fjbender Nov 2, 2023
04fd5da
Resolve issue where changing shipping method in ApplePay does not cor…
james-windandkite Nov 3, 2023
e703b45
Fix typo
fjbender Nov 6, 2023
d04fe1f
Re-add Shipping Method Management
fjbender Nov 6, 2023
99e6343
Re-add checkout session
fjbender Nov 6, 2023
cf5e5b8
Bugfix: Show the payment fee tax when the product has a different tax…
michielgerritsen Nov 6, 2023
d577ade
BUGFIX - Fix issue where this.applePayPaymentToken may not be defined…
Nov 6, 2023
8d59ed7
Merge branch 'pr-713' into release-week-45
michielgerritsen Nov 6, 2023
3ff1049
Merge branch 'pr-712' into release-week-45
michielgerritsen Nov 6, 2023
fe64777
Merge branch 'pr-711' into release-week-45
michielgerritsen Nov 6, 2023
321339e
Merge branch 'improvement/add-test-for-refunds' into release-week-45
michielgerritsen Nov 6, 2023
b8e4830
Merge branch 'bugfix/show-the-payment-fee-tax' into release-week-45
michielgerritsen Nov 6, 2023
c4b4c46
Merge branch 'bugfix/issuer-list-type-default' into release-week-45
michielgerritsen Nov 6, 2023
7ec19ce
Bugfix: Get the grand total by code
michielgerritsen Nov 9, 2023
ed0bd92
Bugfix: Link all Mollie urls to the backend mollie/magento2-scandipwa#20
michielgerritsen Nov 13, 2023
b09e519
Merge branch 'bugfix/scandipwa-paths' into release-week-45
michielgerritsen Nov 13, 2023
d6e3d75
Merge branch 'bugfix/get-the-grand-total' into release-week-45
michielgerritsen Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading