Skip to content

Commit

Permalink
Merge pull request #489 from mollie/release/2.6.0
Browse files Browse the repository at this point in the history
Release/2.6.0
  • Loading branch information
Marvin-Magmodules authored Feb 8, 2022
2 parents c9a52c3 + 854efda commit bc94f54
Show file tree
Hide file tree
Showing 34 changed files with 1,365 additions and 969 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Run codesniffer
run:
docker run
--volume $(pwd)/:/app/data
--volume $(pwd)/:/app/workdir
michielgerritsen/magento-coding-standard:latest
--severity=10
--ignore-annotations
-s
38 changes: 31 additions & 7 deletions GraphQL/Resolver/Cart/ResetCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@

use Magento\Framework\App\ObjectManager;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;

class ResetCart implements ResolverInterface
{
/**
* @var MaskedQuoteIdToQuoteIdInterface
*/
private $maskedQuoteIdToQuoteId;

/**
* @var CartRepositoryInterface
*/
private $cartRepository;

public function __construct(
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
CartRepositoryInterface $cartRepository
) {
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
$this->cartRepository = $cartRepository;
}

Expand All @@ -35,14 +45,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

$maskedCartId = $args['input']['cart_id'];

$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId);
$cart = $this->cartRepository->get($cartId);

/**
* Use the ObjectManager to prevent setup:di:compile errors when people replace the GraphQL modules.
*/
/** @var GetCartForUser $getCartForUser */
$getCartForUser = ObjectManager::getInstance()->get(GetCartForUser::class);
$cart = $getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
$this->validateCartOwnership($cart, $context->getUserId(), $maskedCartId);

$cart->setIsActive(1);
$this->cartRepository->save($cart);
Expand All @@ -53,4 +59,22 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
],
];
}

private function validateCartOwnership(CartInterface $cart, int $customerId, string $cartHash): void
{
$cartCustomerId = (int)$cart->getCustomerId();
/* Guest cart, allow operations */
if (0 === $cartCustomerId && (null === $customerId || 0 === $customerId)) {
return;
}

if ($cartCustomerId !== $customerId) {
throw new GraphQlAuthorizationException(
__(
'The current user cannot perform operations on cart "%masked_cart_id"',
['masked_cart_id' => $cartHash]
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ class StartTransactionForInstantPurchaseOrders implements ObserverInterface
*/
private $mollie;

/**
* @var null|string
*/
private $redirectUrl = null;

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

public function execute(Observer $observer)
public function getRedirectUrl(): ?string
{
return $this->redirectUrl;
}

public function execute(Observer $observer): void
{
if (!$observer->hasData('order')) {
return;
Expand All @@ -46,6 +56,6 @@ public function execute(Observer $observer)
return;
}

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

namespace Mollie\Payment\Plugin\InstantPurchase\Button;

use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\InstantPurchase\Controller\Button\PlaceOrder;
use Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForInstantPurchaseOrders;

class PlaceOrderAddRedirectUrl
{
/**
* @var ResponseInterface
*/
private $response;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* @var ResultFactory
*/
private $resultFactory;

/**
* @var StartTransactionForInstantPurchaseOrders
*/
private $startTransaction;

public function __construct(
ResponseInterface $response,
SerializerInterface $serializer,
ResultFactory $resultFactory,
StartTransactionForInstantPurchaseOrders $startTransaction
) {
$this->response = $response;
$this->serializer = $serializer;
$this->resultFactory = $resultFactory;
$this->startTransaction = $startTransaction;
}

public function afterExecute(PlaceOrder $subject, Json $result)
{
$redirectUrl = $this->startTransaction->getRedirectUrl();
if (!$redirectUrl) {
return $result;
}

$result->renderResult($this->response);

$body = $this->serializer->unserialize($this->response->getContent());

$body['mollie_redirect_url'] = $redirectUrl;

$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$result->setData($body);

return $result;
}
}
46 changes: 46 additions & 0 deletions Service/Order/Lines/Generator/MageWorxRewardPoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Order\Lines\Generator;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Helper\General;

class MageWorxRewardPoints implements GeneratorInterface
{
/**
* @var General
*/
private $mollieHelper;

public function __construct(
General $mollieHelper
) {
$this->mollieHelper = $mollieHelper;
}

public function process(OrderInterface $order, array $orderLines): array
{
if (!$order->getMwRwrdpointsAmnt()) {
return $orderLines;
}

$forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId());
$currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode();

$orderLines[] = [
'type' => 'surcharge',
'name' => 'Reward Points',
'quantity' => 1,
'unitPrice' => $this->mollieHelper->getAmountArray($currency, -$order->getMwRwrdpointsAmnt()),
'totalAmount' => $this->mollieHelper->getAmountArray($currency, -$order->getMwRwrdpointsAmnt()),
'vatRate' => 0,
'vatAmount' => $this->mollieHelper->getAmountArray($currency, 0.0),
];

return $orderLines;
}
}
17 changes: 15 additions & 2 deletions Service/Order/TransactionPart/UseSavedPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@
namespace Mollie\Payment\Service\Order\TransactionPart;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Model\Client\Orders;
use Mollie\Payment\Model\Client\Payments;
use Mollie\Payment\Service\Order\TransactionPartInterface;

class UseSavedPaymentMethod implements TransactionPartInterface
{
/**
* @var Config
*/
private $config;

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

public function process(OrderInterface $order, $apiMethod, array $transaction)
{
if (
!$this->config->isMagentoVaultEnabled($order->getStoreId()) ||
!$order->getPayment() ||
!$order->getPayment()->getExtensionAttributes() ||
!$order->getPayment()->getExtensionAttributes()->getVaultPaymentToken()
Expand All @@ -29,12 +42,12 @@ public function process(OrderInterface $order, $apiMethod, array $transaction)
}

if ($apiMethod == Payments::CHECKOUT_TYPE) {
$transaction['sequenceType'] = 'recurring';
$transaction['sequenceType'] = 'oneoff';
$transaction['mandateId'] = $paymentToken->getGatewayToken();
}

if ($apiMethod == Orders::CHECKOUT_TYPE) {
$transaction['payment']['sequenceType'] = 'recurring';
$transaction['payment']['sequenceType'] = 'oneoff';
$transaction['payment']['mandateId'] = $paymentToken->getGatewayToken();
}

Expand Down
50 changes: 0 additions & 50 deletions Setup/InstallData.php

This file was deleted.

60 changes: 0 additions & 60 deletions Setup/InstallSchema.php

This file was deleted.

Loading

0 comments on commit bc94f54

Please sign in to comment.