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 #722

Closed
wants to merge 8 commits into from
5 changes: 3 additions & 2 deletions .github/workflows/end-2-end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ 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.
# Note the `mollie-pwa-*.html` files, 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 cp $(pwd)/Test/End-2-end/cypress/fixtures/mollie-pwa-graphql.html magento-project-community-edition:/data/pub/opt/ && \
docker cp $(pwd)/Test/End-2-end/cypress/fixtures/mollie-pwa-rest.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
4 changes: 2 additions & 2 deletions Controller/ApplePay/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function execute()
return [
'identifier' => $method->getCarrierCode() . '_' . $method->getMethodCode(),
'label' => $method->getMethodTitle() . ' - ' . $method->getCarrierTitle(),
'amount' => number_format($method->getPriceInclTax(), 2, '.', ''),
'amount' => number_format($method->getPriceInclTax() ?: 0.0, 2, '.', ''),
'detail' => '',
];
}, $methods),
Expand All @@ -92,7 +92,7 @@ public function execute()
'type' => 'final',
'code' => $total->getCode(),
'label' => $total->getData('title'),
'amount' => number_format($total->getData('value'), 2, '.', ''),
'amount' => number_format($total->getData('value') ?: 0.0, 2, '.', ''),
];
}, array_values($cart->getTotals()))
]);
Expand Down
74 changes: 9 additions & 65 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Locale\Resolver;
use Magento\Framework\Math\Random as MathRandom;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderRepository;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -25,9 +22,8 @@
use Mollie\Payment\Logger\MollieLogger;
use Magento\SalesRule\Model\Coupon;
use Magento\SalesRule\Model\ResourceModel\Coupon\Usage as CouponUsage;
use Mollie\Payment\Service\Mollie\TransactionDescription;
use Mollie\Payment\Service\Order\CancelOrder;
use Mollie\Payment\Service\Order\OrderCommentHistory;
use Mollie\Payment\Service\Order\MethodCode;
use Mollie\Payment\Service\Order\Transaction;
use Mollie\Payment\Service\Order\Uncancel;

Expand Down Expand Up @@ -129,10 +125,6 @@ class General extends AbstractHelper
* @var OrderRepository
*/
private $orderRepository;
/**
* @var MathRandom
*/
private $mathRandom;
/**
* @var Coupon
*/
Expand All @@ -141,14 +133,6 @@ class General extends AbstractHelper
* @var CouponUsage
*/
private $couponUsage;
/**
* @var OrderCommentHistory
*/
private $orderCommentHistory;
/**
* @var OrderManagementInterface
*/
private $orderManagement;
/**
* @var Config
*/
Expand All @@ -162,45 +146,16 @@ class General extends AbstractHelper
*/
private $uncancel;

/**
* @var TransactionDescription
*/
private $transactionDescription;

/**
* @var CancelOrder
*/
private $cancelOrder;

/**
* @var EncryptorInterface
* @var MethodCode
*/
private $encryptor;
private $methodCode;

/**
* General constructor.
*
* @param Context $context
* @param PaymentHelper $paymentHelper
* @param OrderRepository $orderRepository
* @param StoreManagerInterface $storeManager
* @param ResourceConfig $resourceConfig
* @param ModuleListInterface $moduleList
* @param ProductMetadataInterface $metadata
* @param Resolver $resolver
* @param MathRandom $mathRandom
* @param MollieLogger $logger
* @param Coupon $coupon
* @param CouponUsage $couponUsage
* @param OrderCommentHistory $orderCommentHistory
* @param OrderManagementInterface $orderManagement
* @param Config $config
* @param Transaction $transaction
* @param Uncancel $uncancel
* @param TransactionDescription $transactionDescription
* @param CancelOrder $cancelOrder
* @param EncryptorInterface $encryptor
*/
public function __construct(
Context $context,
PaymentHelper $paymentHelper,
Expand All @@ -210,39 +165,31 @@ public function __construct(
ModuleListInterface $moduleList,
ProductMetadataInterface $metadata,
Resolver $resolver,
MathRandom $mathRandom,
MollieLogger $logger,
Coupon $coupon,
CouponUsage $couponUsage,
OrderCommentHistory $orderCommentHistory,
OrderManagementInterface $orderManagement,
Config $config,
Transaction $transaction,
Uncancel $uncancel,
TransactionDescription $transactionDescription,
CancelOrder $cancelOrder,
EncryptorInterface $encryptor
MethodCode $methodCode
) {
$this->paymentHelper = $paymentHelper;
$this->storeManager = $storeManager;
$this->resourceConfig = $resourceConfig;
$this->orderRepository = $orderRepository;
$this->urlBuilder = $context->getUrlBuilder();
$this->moduleList = $moduleList;
$this->mathRandom = $mathRandom;
$this->metadata = $metadata;
$this->resolver = $resolver;
$this->logger = $logger;
$this->coupon = $coupon;
$this->couponUsage = $couponUsage;
$this->orderCommentHistory = $orderCommentHistory;
$this->orderManagement = $orderManagement;
$this->config = $config;
$this->transaction = $transaction;
$this->uncancel = $uncancel;
$this->transactionDescription = $transactionDescription;
$this->cancelOrder = $cancelOrder;
$this->encryptor = $encryptor;
$this->methodCode = $methodCode;
parent::__construct($context);
}

Expand Down Expand Up @@ -418,16 +365,13 @@ public function disableExtension()
* @param OrderInterface $order
*
* @return string
*
* @deprecated since v2.33.0
* @see \Mollie\Payment\Service\Order\MethodCode
*/
public function getMethodCode($order): string
{
$method = $order->getPayment()->getMethodInstance()->getCode();

if ($method == 'mollie_methods_paymentlink' || strstr($method, 'mollie_methods') === false) {
return '';
}

return str_replace('mollie_methods_', '', $method);
return $this->methodCode->execute($order);
}

/***
Expand Down
50 changes: 11 additions & 39 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
use Mollie\Payment\Service\Order\BuildTransaction;
use Mollie\Payment\Service\Order\Invoice\ShouldEmailInvoice;
use Mollie\Payment\Service\Order\Lines\StoreCredit;
use Mollie\Payment\Service\Order\MethodCode;
use Mollie\Payment\Service\Order\OrderCommentHistory;
use Mollie\Payment\Service\Order\PartialInvoice;
use Mollie\Payment\Service\Order\ProcessAdjustmentFee;
use Mollie\Payment\Service\Order\Transaction;
use Mollie\Payment\Service\OrderLockService;
use Mollie\Payment\Service\PaymentToken\PaymentTokenForOrder;

/**
Expand Down Expand Up @@ -148,43 +148,15 @@ class Orders extends AbstractModel
*/
private $linkTransactionToOrder;

/**
* @var OrderLockService
*/
private $orderLockService;
/**
* @var ShouldEmailInvoice
*/
private $shouldEmailInvoice;

/**
* Orders constructor.
*
* @param OrderLines $orderLines
* @param InvoiceSender $invoiceSender
* @param OrderRepository $orderRepository
* @param CheckoutSession $checkoutSession
* @param ManagerInterface $messageManager
* @param Registry $registry
* @param MollieHelper $mollieHelper
* @param ProcessAdjustmentFee $adjustmentFee
* @param OrderCommentHistory $orderCommentHistory
* @param PartialInvoice $partialInvoice
* @param StoreCredit $storeCredit
* @param RefundUsingPayment $refundUsingPayment
* @param Expires $expires
* @param State $orderState
* @param Transaction $transaction
* @param BuildTransaction $buildTransaction
* @param PaymentTokenForOrder $paymentTokenForOrder
* @param ProcessTransaction $processTransaction
* @param \Mollie\Payment\Service\Mollie\MollieApiClient $mollieApiClient
* @param Config $config
* @param EventManager $eventManager
* @param LinkTransactionToOrder $linkTransactionToOrder
* @param OrderLockService $orderLockService
* @param ShouldEmailInvoice $shouldEmailInvoice
* @var MethodCode
*/
private $methodCode;

public function __construct(
OrderLines $orderLines,
InvoiceSender $invoiceSender,
Expand All @@ -208,8 +180,8 @@ public function __construct(
Config $config,
EventManager $eventManager,
LinkTransactionToOrder $linkTransactionToOrder,
OrderLockService $orderLockService,
ShouldEmailInvoice $shouldEmailInvoice
ShouldEmailInvoice $shouldEmailInvoice,
MethodCode $methodCode
) {
$this->orderLines = $orderLines;
$this->invoiceSender = $invoiceSender;
Expand All @@ -233,8 +205,8 @@ public function __construct(
$this->mollieApiClient = $mollieApiClient;
$this->config = $config;
$this->linkTransactionToOrder = $linkTransactionToOrder;
$this->orderLockService = $orderLockService;
$this->shouldEmailInvoice = $shouldEmailInvoice;
$this->methodCode = $methodCode;
}

/**
Expand All @@ -258,7 +230,7 @@ public function startTransaction(OrderInterface $order, $mollieApi)
}

$paymentToken = $this->paymentTokenForOrder->execute($order);
$method = $this->mollieHelper->getMethodCode($order);
$method = $this->methodCode->execute($order);
$method = str_replace('_vault', '', $method);
$orderData = [
'amount' => $this->mollieHelper->getOrderAmountByOrder($order),
Expand Down Expand Up @@ -673,7 +645,7 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
return $this;
}

$methodCode = $this->mollieHelper->getMethodCode($order);
$methodCode = $this->methodCode->execute($order);
$methods = ['klarna', 'klarnapaylater', 'klarnasliceit', 'klarnapaynow'];
if (!$order->hasShipments() && (in_array($methodCode, $methods))) {
$msg = __('Order can only be refunded after Klarna has been captured (after shipment)');
Expand Down Expand Up @@ -744,7 +716,7 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
* Check if Shipping Fee needs to be refunded.
* Throws exception if Shipping Amount of credit does not match Shipping Fee of paid orderLine.
*/
$addShippingToRefund = null;
$addShippingToRefund = false;
$shippingCostsLine = $this->orderLines->getShippingFeeItemLineOrder($orderId);
if ($shippingCostsLine->getId() && $shippingCostsLine->getQtyRefunded() == 0) {
if ($creditmemo->getShippingAmount() > 0) {
Expand All @@ -757,7 +729,7 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
}
}

$shouldRefund = $addShippingToRefund || !$creditmemo->getAllItems();
$shouldRefund = $addShippingToRefund || $creditmemo->getAllItems();
if (!$shouldRefund || $this->adjustmentFee->doNotRefundInMollie()) {
return $this;
}
Expand Down
34 changes: 9 additions & 25 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Mollie\Payment\Service\Mollie\TransactionDescription;
use Mollie\Payment\Service\Mollie\ValidateMetadata;
use Mollie\Payment\Service\Order\BuildTransaction;
use Mollie\Payment\Service\Order\MethodCode;
use Mollie\Payment\Service\Order\OrderAmount;
use Mollie\Payment\Service\Order\CancelOrder;
use Mollie\Payment\Service\Order\OrderCommentHistory;
Expand Down Expand Up @@ -137,31 +138,11 @@ class Payments extends AbstractModel
* @var CanRegisterCaptureNotification
*/
private $canRegisterCaptureNotification;

/**
* Payments constructor.
*
* @param OrderRepository $orderRepository
* @param CheckoutSession $checkoutSession
* @param MollieHelper $mollieHelper
* @param OrderCommentHistory $orderCommentHistory
* @param BuildTransaction $buildTransaction
* @param DashboardUrl $dashboardUrl
* @param Transaction $transaction
* @param TransactionProcessor $transactionProcessor
* @param OrderAmount $orderAmount
* @param TransactionDescription $transactionDescription
* @param CancelOrder $cancelOrder
* @param PaymentTokenForOrder $paymentTokenForOrder
* @param SendOrderEmails $sendOrderEmails
* @param EventManager $eventManager
* @param LinkTransactionToOrder $linkTransactionToOrder
* @param ProcessTransaction $processTransaction
* @param ValidateMetadata $validateMetadata
* @param SaveAdditionalInformationDetails $saveAdditionalInformationDetails
* @param ExpiredOrderToTransaction $expiredOrderToTransaction
* @param CanRegisterCaptureNotification $canRegisterCaptureNotification
* @var MethodCode
*/
private $methodCode;

public function __construct(
OrderRepository $orderRepository,
CheckoutSession $checkoutSession,
Expand All @@ -182,7 +163,8 @@ public function __construct(
ValidateMetadata $validateMetadata,
SaveAdditionalInformationDetails $saveAdditionalInformationDetails,
ExpiredOrderToTransaction $expiredOrderToTransaction,
CanRegisterCaptureNotification $canRegisterCaptureNotification
CanRegisterCaptureNotification $canRegisterCaptureNotification,
MethodCode $methodCode
) {
$this->orderRepository = $orderRepository;
$this->checkoutSession = $checkoutSession;
Expand All @@ -204,6 +186,7 @@ public function __construct(
$this->saveAdditionalInformationDetails = $saveAdditionalInformationDetails;
$this->expiredOrderToTransaction = $expiredOrderToTransaction;
$this->canRegisterCaptureNotification = $canRegisterCaptureNotification;
$this->methodCode = $methodCode;
}

/**
Expand All @@ -225,7 +208,8 @@ public function startTransaction(OrderInterface $order, $mollieApi)
}

$paymentToken = $this->paymentTokenForOrder->execute($order);
$method = $this->mollieHelper->getMethodCode($order);
$method = $this->methodCode->execute($order);

$paymentData = [
'amount' => $this->mollieHelper->getOrderAmountByOrder($order),
'description' => $this->transactionDescription->forRegularTransaction($order),
Expand Down
Loading
Loading