Skip to content

Commit

Permalink
Merge pull request #420 from mollie/1.29.0
Browse files Browse the repository at this point in the history
1.29.0
  • Loading branch information
Marvin-Magmodules committed Aug 4, 2021
2 parents 67b1dc7 + 1d083b3 commit 699b7f2
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function execute()
}
} catch (Exception $exception) {
// @phpstan-ignore-next-line
$this->formatExceptionMessage($exception, $methodInstance);
$this->formatExceptionMessage($exception, $methodInstance ?? null);
$this->mollieHelper->addTolog('error', $exception->getMessage());
$this->checkoutSession->restoreQuote();
$this->cancelUnprocessedOrder($order, $exception->getMessage());
Expand Down Expand Up @@ -179,11 +179,11 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message)

/**
* @param Exception $exception
* @param MethodInterface $methodInstance
* @param MethodInterface|null $methodInstance
*/
private function formatExceptionMessage(Exception $exception, MethodInterface $methodInstance)
private function formatExceptionMessage(Exception $exception, MethodInterface $methodInstance = null)
{
if (stripos($exception->getMessage(), 'cURL error 28') !== false) {
if ($methodInstance && stripos($exception->getMessage(), 'cURL error 28') !== false) {
$this->messageManager->addErrorMessage(
__(
'A Timeout while connecting to %1 occurred, this could be the result of an outage. ' .
Expand Down
4 changes: 4 additions & 0 deletions GraphQL/Resolver/Checkout/PlaceOrderAndReturnRedirectUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
return null;
}

if (strstr($order->getPayment()->getMethod(), 'mollie_methods') === false) {
return null;
}

if ($order->getPayment()->getAdditionalInformation('checkout_url')) {
return $order->getPayment()->getAdditionalInformation('checkout_url');
}
Expand Down
93 changes: 93 additions & 0 deletions GraphQL/Resolver/Checkout/ProcessTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\GraphQL\Resolver\Checkout;

use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\NoSuchEntityException;
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 Mollie\Api\Types\PaymentStatus;
use Mollie\Payment\Api\PaymentTokenRepositoryInterface;
use Mollie\Payment\Model\Mollie;

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

/**
* @var PaymentTokenRepositoryInterface
*/
private $paymentTokenRepository;

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

/**
* @var Session
*/
private $checkoutSession;

public function __construct(
Mollie $mollie,
PaymentTokenRepositoryInterface $paymentTokenRepository,
CartRepositoryInterface $cartRepository,
Session $checkoutSession
) {
$this->mollie = $mollie;
$this->paymentTokenRepository = $paymentTokenRepository;
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['payment_token'])) {
throw new GraphQlInputException(__('Missing "payment_token" input argument'));
}

$token = $args['input']['payment_token'];
$tokenModel = $this->paymentTokenRepository->getByToken($token);

$result = $this->mollie->processTransaction($tokenModel->getOrderId(), 'success', $token);

if (isset($result['error'])) {
return ['paymentStatus' => 'ERROR'];
}

return [
'paymentStatus' => strtoupper($result['status']),
'cart' => $this->getCart($result['status'], $tokenModel->getCartId()),
];
}

private function getCart(string $status, ?string $cartId): ?array
{
if (!$cartId || !in_array($status, [
PaymentStatus::STATUS_EXPIRED,
PaymentStatus::STATUS_CANCELED,
PaymentStatus::STATUS_FAILED,
])) {
return null;
}

try {
$this->checkoutSession->restoreQuote();

return ['model' => $this->cartRepository->get($cartId)];
} catch (NoSuchEntityException $exception) {
return null;
}
}
}
13 changes: 7 additions & 6 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,19 @@ public function disableExtension()
/**
* Method code for API
*
* @param \Magento\Sales\Model\Order $order
* @param OrderInterface $order
*
* @return mixed
* @return string
*/
public function getMethodCode($order)
public function getMethodCode($order): string
{
$method = $order->getPayment()->getMethodInstance()->getCode();

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

return str_replace('mollie_methods_', '', $method);
}

/***
Expand Down
50 changes: 50 additions & 0 deletions Test/Integration/Helper/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,54 @@ public function testGetApiKeyGivesAUniqueKeyPerStore()
$this->assertEquals('keyA', $instance->getApiKey($storeA));
$this->assertEquals('keyB', $instance->getApiKey($storeB));
}

public function getMethodCodeDataProvider()
{
return [
'paymentlink' => ['mollie_methods_paymentlink', ''],
'checkmo' => ['checkmo', ''],
'free' => ['free', ''],

'applepay' => ['mollie_methods_applepay', 'applepay'],
'bancontact' => ['mollie_methods_bancontact', 'bancontact'],
'banktransfer' => ['mollie_methods_banktransfer', 'banktransfer'],
'belfius' => ['mollie_methods_belfius', 'belfius'],
'creditcard' => ['mollie_methods_creditcard', 'creditcard'],
'directdebit' => ['mollie_methods_directdebit', 'directdebit'],
'eps' => ['mollie_methods_eps', 'eps'],
'giftcard' => ['mollie_methods_giftcard', 'giftcard'],
'giropay' => ['mollie_methods_giropay', 'giropay'],
'ideal' => ['mollie_methods_ideal', 'ideal'],
'kbc' => ['mollie_methods_kbc', 'kbc'],
'klarnapaylater' => ['mollie_methods_klarnapaylater', 'klarnapaylater'],
'klarnasliceit' => ['mollie_methods_klarnasliceit', 'klarnasliceit'],
'voucher' => ['mollie_methods_voucher', 'voucher'],
'mybank' => ['mollie_methods_mybank', 'mybank'],
'paypal' => ['mollie_methods_paypal', 'paypal'],
'paysafecard' => ['mollie_methods_paysafecard', 'paysafecard'],
'przelewy24' => ['mollie_methods_przelewy24', 'przelewy24'],
'sofort' => ['mollie_methods_sofort', 'sofort'],
];
}

/**
* @dataProvider getMethodCodeDataProvider
*/
public function testGetMethodCode($input, $expected)
{
/** @var OrderInterface $order */
$order = $this->objectManager->create(OrderInterface::class);

/** @var OrderPaymentInterface $payment */
$payment = $this->objectManager->create(OrderPaymentInterface::class);
$order->setPayment($payment);

$payment->setMethod($input);

/** @var General $instance */
$instance = $this->objectManager->create(General::class);
$result = $instance->getMethodCode($order);

$this->assertEquals($expected, $result);
}
}
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.28.0",
"version": "1.29.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.28.0</version>
<version>v1.29.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
6 changes: 6 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,10 @@
<argument name="resourceConnection" xsi:type="object">Magento\Framework\App\ResourceConnection\Proxy</argument>
</arguments>
</type>

<type name="Mollie\Payment\GraphQL\Resolver\Checkout\ProcessTransaction">
<arguments>
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
</arguments>
</type>
</config>
67 changes: 45 additions & 22 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
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")
mollieProcessTransaction(input: MollieProcessTransactionInput): MollieProcessTransactionOutput @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\ProcessTransaction")
}

type Order {
mollie_redirect_url: String @resolver(class: "\\Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\PlaceOrderAndReturnRedirectUrl")
mollie_payment_token: String @resolver(class: "\\Mollie\\Payment\\GraphQL\\Resolver\\Checkout\\PaymentToken")
}

type MollieTransactionOutput {
checkout_url: String
}

type Cart {
mollie_available_issuers: [MollieIssuer!] @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\AvailableIssuersForCart") @doc(description: "Available issuers for the selected payment method")
}
Expand All @@ -25,11 +22,6 @@ type SelectedPaymentMethod {
mollie_meta: MolliePaymentMethodMeta! @resolver(class: "Mollie\\Payment\\GraphQL\\Resolver\\Cart\\PaymentMethodMeta") @doc(description: "Retrieve meta information for this payment method (image)")
}

input PaymentMethodInput {
mollie_selected_issuer: String @doc(description: "Provided the issuer chosen by the end-user")
mollie_card_token: String @doc(description: "The card token provided by Mollie Components")
}

type MollieIssuer {
name: String
code: String
Expand All @@ -41,9 +33,10 @@ type MolliePaymentMethodMeta {
image: String
}

input MollieTransactionInput {
payment_token: String!
issuer: String
type MolliePaymentMethod {
code: String
name: String
image: String
}

type Query {
Expand All @@ -53,25 +46,55 @@ type Query {
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!
}

type MolliePaymentMethodsOutput {
methods: [MolliePaymentMethod]
}

type MollieTransactionOutput {
checkout_url: String
}

type MollieProcessTransactionOutput {
paymentStatus: PaymentStatusEnum
cart: Cart @doc(description: "The cart is only available when the payment status is failed, canceled or expired.")
}

input PaymentMethodInput {
mollie_selected_issuer: String @doc(description: "Provided the issuer chosen by the end-user")
mollie_card_token: String @doc(description: "The card token provided by Mollie Components")
}

input MollieTransactionInput {
payment_token: String!
issuer: String
}

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

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

type MolliePaymentMethod {
code: String
name: String
image: String
input MollieProcessTransactionInput {
payment_token: String! @doc(description: "The payment token returned from the PlaceOrder call/added to the return URL")
}

enum PaymentStatusEnum {
CREATED
PAID
AUTHORIZED
CANCELED
SHIPPING
COMPLETED
EXPIRED
PENDING
REFUNDED
ERROR
}
47 changes: 47 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
parameters:
ignoreErrors:
-
message: "#^Method Mollie\\\\Payment\\\\Block\\\\Info\\\\Base\\:\\:getOrderId\\(\\) should return string but return statement is missing\\.$#"
count: 1
path: Block/Info/Base.php

-
message: "#^Method Mollie\\\\Payment\\\\Controller\\\\Checkout\\\\Process\\:\\:execute\\(\\) should return Magento\\\\Framework\\\\App\\\\ResponseInterface\\|Magento\\\\Framework\\\\Controller\\\\ResultInterface but return statement is missing\\.$#"
count: 1
path: Controller/Checkout/Process.php

-
message: "#^Method Mollie\\\\Payment\\\\Controller\\\\Checkout\\\\Redirect\\:\\:execute\\(\\) should return Magento\\\\Framework\\\\App\\\\ResponseInterface\\|Magento\\\\Framework\\\\Controller\\\\ResultInterface but return statement is missing\\.$#"
count: 1
path: Controller/Checkout/Redirect.php

-
message: "#^Method Mollie\\\\Payment\\\\Controller\\\\Checkout\\\\Restart\\:\\:execute\\(\\) should return Magento\\\\Framework\\\\App\\\\ResponseInterface\\|Magento\\\\Framework\\\\Controller\\\\ResultInterface but return statement is missing\\.$#"
count: 1
path: Controller/Checkout/Restart.php

-
message: "#^Method Mollie\\\\Payment\\\\Controller\\\\Checkout\\\\Success\\:\\:execute\\(\\) should return Magento\\\\Framework\\\\App\\\\ResponseInterface\\|Magento\\\\Framework\\\\Controller\\\\ResultInterface but return statement is missing\\.$#"
count: 1
path: Controller/Checkout/Success.php

-
message: "#^Method Mollie\\\\Payment\\\\Helper\\\\General\\:\\:getBanktransferDueDate\\(\\) should return string\\|false but return statement is missing\\.$#"
count: 1
path: Helper/General.php

-
message: "#^Method Mollie\\\\Payment\\\\Model\\\\Adminhtml\\\\Backend\\\\VerifiyPaymentFee\\:\\:beforeSave\\(\\) should return \\$this\\(Mollie\\\\Payment\\\\Model\\\\Adminhtml\\\\Backend\\\\VerifiyPaymentFee\\) but return statement is missing\\.$#"
count: 1
path: Model/Adminhtml/Backend/VerifiyPaymentFee.php

-
message: "#^Method Mollie\\\\Payment\\\\Model\\\\Methods\\\\Reorder\\:\\:initialize\\(\\) should return \\$this\\(Mollie\\\\Payment\\\\Model\\\\Methods\\\\Reorder\\) but return statement is missing\\.$#"
count: 1
path: Model/Methods/Reorder.php

-
message: "#^Method Mollie\\\\Payment\\\\Model\\\\Mollie\\:\\:createOrderRefund\\(\\) should return \\$this\\(Mollie\\\\Payment\\\\Model\\\\Mollie\\) but return statement is missing\\.$#"
count: 1
path: Model/Mollie.php

Loading

0 comments on commit 699b7f2

Please sign in to comment.