Skip to content

Commit

Permalink
Merge branch 'release-week-01' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jan 22, 2024
2 parents 6758f13 + 460e16d commit ed13b7e
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/templates/e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cypress/included:12.1.0
FROM cypress/included:13.6.2

WORKDIR /e2e

Expand Down
50 changes: 35 additions & 15 deletions Block/Info/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

namespace Mollie\Payment\Block\Info;

use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Payment\Block\Info;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Stdlib\DateTime;
use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Methods\Billie;
use Mollie\Payment\Model\Methods\Klarna;
Expand All @@ -21,7 +24,6 @@

class Base extends Info
{

/**
* @var string
*/
Expand All @@ -42,26 +44,36 @@ class Base extends Info
* @var PriceCurrencyInterface
*/
private $price;

/**
* Base constructor.
*
* @param Context $context
* @param MollieHelper $mollieHelper
* @param Registry $registry
* @param PriceCurrencyInterface $price
* @var EncryptorInterface
*/
private $encryptor;
/**
* @var Config
*/
private $config;
/**
* @var UrlInterface
*/
private $urlBuilder;

public function __construct(
Context $context,
Config $config,
MollieHelper $mollieHelper,
Registry $registry,
PriceCurrencyInterface $price
PriceCurrencyInterface $price,
EncryptorInterface $encryptor,
UrlInterface $urlBuilder
) {
parent::__construct($context);
$this->mollieHelper = $mollieHelper;
$this->timezone = $context->getLocaleDate();
$this->registry = $registry;
$this->price = $price;
$this->encryptor = $encryptor;
$this->config = $config;
$this->urlBuilder = $urlBuilder;
}

public function getCheckoutType(): ?string
Expand All @@ -87,16 +99,24 @@ public function getExpiresAt(): ?string
return null;
}

/**
* @param mixed $storeId
*/
public function getPaymentLink($storeId = null): ?string
{
if ($checkoutUrl = $this->getCheckoutUrl()) {
return $this->mollieHelper->getPaymentLinkMessage($checkoutUrl, $storeId);
if (!$this->config->addPaymentLinkMessage($storeId)) {
return null;
}

return null;
return str_replace(
'%link%',
$this->getPaymentLinkUrl(),
$this->config->paymentLinkMessage($storeId)
);
}

public function getPaymentLinkUrl(): string
{
return $this->urlBuilder->getUrl('mollie/checkout/paymentlink', [
'order' => base64_encode($this->encryptor->encrypt($this->getInfo()->getParentId())),
]);
}

public function getCheckoutUrl(): ?string
Expand Down
18 changes: 18 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Config
const PAYMENT_METHOD_PAYMENT_TITLE = 'payment/mollie_methods_%s/title';
const PAYMENT_PAYMENTLINK_ALLOW_MARK_AS_PAID = 'payment/mollie_methods_paymentlink/allow_mark_as_paid';
const PAYMENT_PAYMENTLINK_NEW_STATUS = 'payment/mollie_methods_paymentlink/order_status_new';
const PAYMENT_PAYMENTLINK_ADD_MESSAGE = 'payment/mollie_methods_paymentlink/add_message';
const PAYMENT_PAYMENTLINK_MESSAGE = 'payment/mollie_methods_paymentlink/message';
const PAYMENT_POINTOFSALE_ALLOWED_CUSTOMER_GROUPS = 'payment/mollie_methods_pointofsale/allowed_customer_groups';
const PAYMENT_VOUCHER_CATEGORY = 'payment/mollie_methods_voucher/category';
const PAYMENT_VOUCHER_CUSTOM_ATTRIBUTE = 'payment/mollie_methods_voucher/custom_attribute';
Expand Down Expand Up @@ -495,6 +497,22 @@ public function statusNewPaymentLink($storeId = null)
);
}

public function addPaymentLinkMessage($storeId = null): string
{
return (string)$this->getPath(
static::PAYMENT_PAYMENTLINK_ADD_MESSAGE,
$storeId
);
}

public function paymentLinkMessage($storeId = null): string
{
return (string)$this->getPath(
static::PAYMENT_PAYMENTLINK_MESSAGE,
$storeId
);
}

/**
* @param string $method
* @param int|null $storeId
Expand Down
99 changes: 99 additions & 0 deletions Controller/Checkout/PaymentLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Controller\Checkout;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Mollie\Payment\Model\Mollie;

class PaymentLink implements HttpGetActionInterface
{
/**
* @var RequestInterface
*/
private $request;
/**
* @var EncryptorInterface
*/
private $encryptor;
/**
* @var ResultFactory
*/
private $resultFactory;
/**
* @var ManagerInterface
*/
private $messageManager;
/**
* @var OrderRepositoryInterface
*/
private $orderRepository;
/**
* @var Mollie
*/
private $mollie;

public function __construct(
RequestInterface $request,
EncryptorInterface $encryptor,
ResultFactory $resultFactory,
ManagerInterface $messageManager,
OrderRepositoryInterface $orderRepository,
Mollie $mollie
) {
$this->request = $request;
$this->encryptor = $encryptor;
$this->resultFactory = $resultFactory;
$this->messageManager = $messageManager;
$this->orderRepository = $orderRepository;
$this->mollie = $mollie;
}

public function execute()
{
$orderKey = $this->request->getParam('order');
if (!$orderKey) {
return $this->returnStatusCode(400);
}

$id = $this->encryptor->decrypt(base64_decode($orderKey));

if (empty($id)) {
return $this->returnStatusCode(404);
}

try {
$order = $this->orderRepository->get($id);
} catch (NoSuchEntityException $exception) {
return $this->returnStatusCode(404);
}

if (in_array($order->getState(), [Order::STATE_PROCESSING, Order::STATE_COMPLETE])) {
$this->messageManager->addSuccessMessage(__('Your order has already been paid.'));

return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setUrl('/');
}

$url = $this->mollie->startTransaction($order);

return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setUrl($url);
}

public function returnStatusCode(int $code): ResultInterface
{
return $this->resultFactory->create(ResultFactory::TYPE_RAW)->setHttpResponseCode($code);
}
}
1 change: 1 addition & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public function sendInvoice($storeId = 0)
* @param int|null $storeId
*
* @return mixed
* @deprecated since 2.34.0
*/
public function getPaymentLinkMessage($checkoutUrl, $storeId = null)
{
Expand Down

This file was deleted.

7 changes: 6 additions & 1 deletion Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module.exports = defineConfig({
require('./cypress/plugins/index.js')(on, config);
require('./cypress/plugins/disable-successful-videos.js')(on, config);

// If we're running in CI, we need to set the CI env variable
if (process.env.CI) {
config.env.CI = true
}

// Retrieve available method
await new Promise((resolve, reject) => {
var https = require('follow-redirects').https;
Expand All @@ -27,7 +32,7 @@ module.exports = defineConfig({

const query = `
query {
molliePaymentMethods(input:{amount:100, currency:null}) {
molliePaymentMethods(input:{amount:50, currency:"EUR"}) {
methods {
code
image
Expand Down
59 changes: 30 additions & 29 deletions Test/End-2-end/cypress/e2e/magento/backend/paymentlink.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,46 @@ const ordersCreatePage = new OrdersCreatePage();
const cookies = new Cookies();

describe('Placing orders from the backend', () => {
// Skipped for now as it keeps failing on CI for unknown reasons.
it.skip('C895380: Validate that the ecommerce admin can submit an order in the backend and mark as "Paid" ', () => {
cy.backendLogin();
// This fails in CI, but works locally. Not sure why.
if (!Cypress.env('CI')) {
it('C895380: Validate that the ecommerce admin can submit an order in the backend and mark as "Paid" ', () => {
cy.backendLogin();

ordersCreatePage.createNewOrderFor('Veronica Costello');
ordersCreatePage.createNewOrderFor('Veronica Costello');

ordersCreatePage.addFirstSimpleProduct();
ordersCreatePage.addFirstSimpleProduct();

ordersCreatePage.selectShippingMethod('Fixed');
ordersCreatePage.selectShippingMethod('Fixed');

// 2.3.7 needs a double click to select the payment method, not sure why.
cy.get('[for="p_method_mollie_methods_paymentlink"]').click().click();
// 2.3.7 needs a double click to select the payment method, not sure why.
cy.get('[for="p_method_mollie_methods_paymentlink"]').click().click();

cy.get('#mollie_methods_paymentlink_methods').select([
'banktransfer',
'creditcard',
'ideal',
]);
cy.get('#mollie_methods_paymentlink_methods').select([
'banktransfer',
'creditcard',
'ideal',
]);

cookies.disableSameSiteCookieRestrictions();
cookies.disableSameSiteCookieRestrictions();

ordersCreatePage.submitOrder();
ordersCreatePage.submitOrder();

cy.get('.mollie-checkout-url .mollie-copy-url')
.invoke('attr', 'data-url')
.then(href => {
cy.visit(href);
});
cy.get('.mollie-checkout-url .mollie-copy-url')
.invoke('attr', 'data-url')
.then(href => {
cy.visit(href);
});

mollieHostedPaymentPage.selectPaymentMethod('iDEAL');
mollieHostedPaymentPage.selectFirstIssuer();
mollieHostedPaymentPage.selectStatus('paid');
mollieHostedPaymentPage.selectPaymentMethod('Overboeking');
mollieHostedPaymentPage.selectStatus('paid');

checkoutSuccessPage.assertThatOrderSuccessPageIsShown();
checkoutSuccessPage.assertThatOrderSuccessPageIsShown();

cy.get('@order-id').then((orderId) => {
ordersPage.openOrderById(orderId);
});
cy.get('@order-id').then((orderId) => {
ordersPage.openOrderById(orderId);
});

ordersPage.assertOrderStatusIs('Processing');
});
ordersPage.assertOrderStatusIs('Processing');
});
}
});
Loading

0 comments on commit ed13b7e

Please sign in to comment.