Skip to content

Commit

Permalink
Merge pull request #406 from mollie/1.27.0
Browse files Browse the repository at this point in the history
1.27.0
  • Loading branch information
Marvin-Magmodules authored Jun 23, 2021
2 parents c79def2 + 2b128ed commit b72abaa
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 16 deletions.
56 changes: 56 additions & 0 deletions GraphQL/Resolver/Cart/ResetCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\GraphQL\Resolver\Cart;

use Magento\Framework\GraphQl\Config\Element\Field;
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\QuoteGraphQl\Model\Cart\GetCartForUser;

class ResetCart implements ResolverInterface
{
/**
* @var GetCartForUser
*/
private $getCartForUser;

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

public function __construct(
GetCartForUser $cartForUser,
CartRepositoryInterface $cartRepository
) {
$this->getCartForUser = $cartForUser;
$this->cartRepository = $cartRepository;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}

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

$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);

$cart->setIsActive(1);
$this->cartRepository->save($cart);

return [
'cart' => [
'model' => $cart,
],
];
}
}
84 changes: 84 additions & 0 deletions GraphQL/Resolver/General/MolliePaymentMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\GraphQL\Resolver\General;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\Data\CartInterfaceFactory;
use Mollie\Api\Resources\Method;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\MethodParameters;

class MolliePaymentMethods implements ResolverInterface
{
/**
* @var Mollie
*/
private $mollie;

/**
* @var MethodParameters
*/
private $methodParameters;

/**
* @var CartInterfaceFactory
*/
private $cartFactory;

public function __construct(
Mollie $mollie,
MethodParameters $methodParameters,
CartInterfaceFactory $cartFactory
) {
$this->mollie = $mollie;
$this->methodParameters = $methodParameters;
$this->cartFactory = $cartFactory;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$amount = 10;
$currency = 'EUR';

if (isset($args['input'], $args['input']['amount'])) {
$amount = $args['input']['amount'];
}

if (isset($args['input'], $args['input']['currency'])) {
$currency = $args['input']['currency'];
}

$parameters = [
'amount[value]' => number_format($amount, 2, '.', ''),
'amount[currency]' => $currency,
'resource' => 'orders',
'includeWallets' => 'applepay',
];

$parameters = $this->methodParameters->enhance($parameters, $this->cartFactory->create());
$storeId = $context->getExtensionAttributes()->getStore()->getId();
$apiMethods = $this->mollie->getMollieApi($storeId)->methods->allActive($parameters);

$methods = [];
/** @var Method $method */
foreach ($apiMethods as $method) {
$methods[] = [
'code' => $method->id,
'name' => $method->description,
'image' => $method->image->svg,
];
}

return [
'methods' => $methods,
];
}
}
18 changes: 16 additions & 2 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Order as MollieOrder;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Types\OrderStatus;
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
Expand Down Expand Up @@ -370,10 +371,15 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
$orderId = $order->getId();
$storeId = $order->getStoreId();
$transactionId = $order->getMollieTransactionId();
$mollieOrder = $mollieApi->orders->get($transactionId, ["embed" => "payments"]);
$mollieOrder = $mollieApi->orders->get($transactionId, ['embed' => 'payments']);
$this->mollieHelper->addTolog($type, $mollieOrder);
$status = $mollieOrder->status;

// This order is refunded, do not process any further.
if ($mollieOrder->payments() && $mollieOrder->payments()->offsetGet(0) && isset($mollieOrder->payments()->offsetGet(0)->metadata->refunded)) {
return ['success' => true, 'status' => $status, 'order_id' => $orderId, 'type' => $type];
}

if ($mollieOrder->isCompleted()) {
return ['success' => true, 'status' => $status, 'order_id' => $orderId, 'type' => $type];
}
Expand Down Expand Up @@ -933,7 +939,15 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
* Sometimes we don't get the correct state when working with bundles, so manually check it.
*/
$this->orderState->check($order);
$mollieOrder = $mollieApi->orders->get($transactionId);
$mollieOrder = $mollieApi->orders->get($transactionId, ['embed' => 'payments']);

/** @var Payment $payment */
$payment = $mollieOrder->payments()->offsetGet(0);
$metadata = $payment->metadata ?? new \stdClass();
$metadata->refunded = true;
$payment->metadata = $metadata;
$payment->update();

if ($order->getState() == Order::STATE_CLOSED) {
$mollieOrder->refundAll();
} else {
Expand Down
8 changes: 4 additions & 4 deletions Service/Order/CancelOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public function execute(OrderInterface $order, $reason = null): bool
$this->config->addToLog('info', sprintf('Getting lock for key "%s"', $key));
$this->lockService->lock($key, 5 * 60);

if ($this->isAlreadyCancelled($order)) {
return false;
}

try {
if ($this->isAlreadyCancelled($order)) {
return false;
}

$comment = __('The order was canceled');
if ($reason !== null) {
$comment = __('The order was canceled, reason: payment %1', $reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@

class PaymentMethodMetaTest extends IntegrationTestCase
{
protected function setUpWithoutVoid()
{
$version = $this->objectManager->get(ProductMetadataInterface::class)->getVersion();
if (version_compare($version, '2.3', '<=')) {
$this->markTestSkipped('This test only works on Magento 2.3 and higher.');
}
}

public function testReturnsAnEmptyResponseForNonMollieMethods()
{
$instance = $this->objectManager->create(PaymentMethodMeta::class);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mollie/magento2",
"description": "Mollie Payment Module for Magento 2",
"version": "1.26.1",
"version": "1.27.0",
"keywords": [
"mollie",
"payment",
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<default>
<payment>
<mollie_general>
<version>v1.26.1</version>
<version>v1.27.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
25 changes: 25 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Mutation {
createMollieTransaction(input: MollieTransactionInput): MollieTransactionOutput @resolver(class: "\\Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\CreateMollieTransaction") @deprecated(reason: "Using the Order.mollie_redirect_url attribuut")
mollieRestoreCart(input: MollieResetCartInput): MollieResetCartOutput @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\ResetCart")
}

type Order {
Expand Down Expand Up @@ -49,4 +50,28 @@ type Query {
mollieCustomerOrder (
hash: String @doc(description: "The hash added to your custom URL")
): CustomerOrder @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\MollieCustomerOrder")
molliePaymentMethods(input: MolliePaymentMethodsInput): MolliePaymentMethodsOutput @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\General\\MolliePaymentMethods")
}

input MollieResetCartInput {
cart_id: String! @doc(description:"The unique ID that identifies the customer's cart")
}

type MollieResetCartOutput {
cart: Cart!
}

input MolliePaymentMethodsInput {
amount: Float! = 10
currency: String! = EUR
}

type MolliePaymentMethodsOutput {
methods: [MolliePaymentMethod]
}

type MolliePaymentMethod {
code: String
name: String
image: String
}

0 comments on commit b72abaa

Please sign in to comment.