Skip to content

Commit

Permalink
Merge pull request #594 from mollie/release/2.20.0
Browse files Browse the repository at this point in the history
Release/2.20.0
  • Loading branch information
Marvin-Magmodules committed Dec 7, 2022
2 parents 1313d52 + 717aa5f commit 7fe08fa
Show file tree
Hide file tree
Showing 32 changed files with 374 additions and 237 deletions.
19 changes: 19 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class Config
{
const EXTENSION_CODE = 'Mollie_Payment';
const GENERAL_ENABLED = 'payment/mollie_general/enabled';
const GENERAL_APIKEY_LIVE = 'payment/mollie_general/apikey_live';
const GENERAL_APIKEY_TEST = 'payment/mollie_general/apikey_test';
const GENERAL_AUTOMATICALLY_SEND_SECOND_CHANCE_EMAILS = 'payment/mollie_general/automatically_send_second_chance_emails';
Expand Down Expand Up @@ -65,6 +66,7 @@ class Config
const PAYMENT_PAYMENTLINK_NEW_STATUS = 'payment/mollie_methods_paymentlink/order_status_new';
const PAYMENT_VOUCHER_CATEGORY = 'payment/mollie_methods_voucher/category';
const PAYMENT_VOUCHER_CUSTOM_ATTRIBUTE = 'payment/mollie_methods_voucher/custom_attribute';
const CURRENCY_OPTIONS_DEFAULT = 'currency/options/default';

/**
* @var ScopeConfigInterface
Expand Down Expand Up @@ -171,6 +173,23 @@ public function getMagentoEdition(): string
return $this->productMetadata->getEdition();
}

/**
* @param null|int|string $storeId
* @return string
*/
public function getStoreCurrency($storeId = null): ?string
{
return $this->getPath(static::CURRENCY_OPTIONS_DEFAULT, null);
}

/**
* @return bool
*/
public function isModuleEnabled($storeId = null): bool
{
return $this->isSetFlag(static::GENERAL_ENABLED, $storeId);
}

/**
* Returns API key
*
Expand Down
1 change: 1 addition & 0 deletions GraphQL/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function getData(array $data): array
return [
'selected_issuer' => $data['mollie_selected_issuer'] ?? null,
'card_token' => $data['mollie_card_token'] ?? null,
'applepay_payment_token' => $data['mollie_applepay_payment_token'] ?? null,
];
}
}
27 changes: 27 additions & 0 deletions GraphQL/Resolver/Checkout/ApplePay/ApplePayValidation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Mollie\Payment\GraphQL\Resolver\Checkout\ApplePay;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Mollie\Payment\Service\Mollie\ApplePay\Validation;

class ApplePayValidation implements ResolverInterface
{
/**
* @var Validation
*/
private $validation;

public function __construct(
Validation $validation
) {
$this->validation = $validation;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
return ['response' => $this->validation->execute($args['validationUrl'], $args['domain'] ?? null)];
}
}
3 changes: 1 addition & 2 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class General extends AbstractHelper
const XML_PATH_LOCALE = 'payment/mollie_general/locale';
const XML_PATH_IMAGES = 'payment/mollie_general/payment_images';
const XML_PATH_USE_BASE_CURRENCY = 'payment/mollie_general/currency';
const XML_PATH_SHOW_TRANSACTION_DETAILS = 'payment/mollie_general/transaction_details';
const XML_PATH_ADD_QR = 'payment/mollie_methods_ideal/add_qr';
const XML_PATH_PAYMENTLINK_ADD_MESSAGE = 'payment/mollie_methods_paymentlink/add_message';
const XML_PATH_PAYMENTLINK_MESSAGE = 'payment/mollie_methods_paymentlink/message';
Expand Down Expand Up @@ -256,7 +255,7 @@ public function __construct(
*/
public function isAvailable($storeId)
{
$active = $this->getStoreConfig(self::XML_PATH_MODULE_ACTIVE, $storeId);
$active = $this->config->isModuleEnabled($storeId);
if (!$active) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use Magento\Framework\Data\OptionSourceInterface;

class AppleyPayIntegrationType implements OptionSourceInterface
class ApplePayIntegrationType implements OptionSourceInterface
{
const EXTERNAL = 'external';
const DIRECT = 'direct';
Expand All @@ -26,4 +26,4 @@ public function toOptionArray()
],
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace Mollie\Payment\Model\Client\Orders\Processors;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Mollie\Api\Resources\Order;
use Mollie\Payment\Config;
use Mollie\Payment\Model\Client\OrderProcessorInterface;
use Mollie\Payment\Model\Client\ProcessTransactionResponse;
use Mollie\Payment\Model\Client\ProcessTransactionResponseFactory;
use Mollie\Payment\Service\Order\SendOrderEmails;

class SendConfirmationEmailForBanktransfer implements OrderProcessorInterface
{
Expand All @@ -27,18 +27,18 @@ class SendConfirmationEmailForBanktransfer implements OrderProcessorInterface
private $processTransactionResponseFactory;

/**
* @var OrderSender
* @var SendOrderEmails
*/
private $orderSender;
private $sendOrderEmails;

public function __construct(
Config $config,
ProcessTransactionResponseFactory $processTransactionResponseFactory,
OrderSender $orderSender
SendOrderEmails $sendOrderEmails
) {
$this->config = $config;
$this->processTransactionResponseFactory = $processTransactionResponseFactory;
$this->orderSender = $orderSender;
$this->sendOrderEmails = $sendOrderEmails;
}

public function process(
Expand All @@ -58,19 +58,14 @@ public function process(
return $response;
}

try {
$this->orderSender->send($order);
$message = __('New order email sent');
} catch (\Throwable $exception) {
$message = __('Unable to send the new order email: %1', $exception->getMessage());
}

if (!$statusPending = $this->config->statusPendingBanktransfer($order->getStoreId())) {
$statusPending = $order->getStatus();
}

$order->setStatus($statusPending);
$order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT);
$order->addStatusToHistory($statusPending, $message, true);

$this->sendOrderEmails->sendOrderConfirmation($order);

return $response;
}
Expand Down
68 changes: 18 additions & 50 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\OrderRepository;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Payment as MolliePayment;
use Mollie\Api\Types\PaymentStatus;
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Service\Mollie\DashboardUrl;
use Mollie\Payment\Service\Mollie\TransactionDescription;
use Mollie\Payment\Service\Order\BuildTransaction;
use Mollie\Payment\Service\Order\OrderAmount;
use Mollie\Payment\Service\Order\CancelOrder;
use Mollie\Payment\Service\Order\OrderCommentHistory;
use Mollie\Payment\Service\Order\SendOrderEmails;
use Mollie\Payment\Service\Order\Transaction;
use Mollie\Payment\Service\Order\TransactionProcessor;
use Mollie\Payment\Service\PaymentToken\PaymentTokenForOrder;
Expand All @@ -48,14 +46,6 @@ class Payments extends AbstractModel
* @var OrderRepository
*/
private $orderRepository;
/**
* @var OrderSender
*/
private $orderSender;
/**
* @var InvoiceSender
*/
private $invoiceSender;
/**
* @var CheckoutSession
*/
Expand All @@ -68,10 +58,6 @@ class Payments extends AbstractModel
* @var BuildTransaction
*/
private $buildTransaction;
/**
* @var Config
*/
private $config;
/**
* @var DashboardUrl
*/
Expand Down Expand Up @@ -110,51 +96,50 @@ class Payments extends AbstractModel
*/
private $paymentTokenForOrder;

/**
* @var SendOrderEmails
*/
private $sendOrderEmails;

/**
* Payments constructor.
*
* @param OrderSender $orderSender
* @param InvoiceSender $invoiceSender
* @param OrderRepository $orderRepository
* @param CheckoutSession $checkoutSession
* @param MollieHelper $mollieHelper
* @param OrderCommentHistory $orderCommentHistory
* @param BuildTransaction $buildTransaction
* @param Config $config
* @param DashboardUrl $dashboardUrl
* @param Transaction $transaction
* @param TransactionProcessor $transactionProcessor
* @param CancelOrder $cancelOrder
* @param EventManager $eventManager
* @param OrderAmount $orderAmount
* @param TransactionDescription $transactionDescription
* @param CancelOrder $cancelOrder
* @param PaymentTokenForOrder $paymentTokenForOrder
* @param SendOrderEmails $sendOrderEmails
* @param EventManager $eventManager
*/
public function __construct(
OrderSender $orderSender,
InvoiceSender $invoiceSender,
OrderRepository $orderRepository,
CheckoutSession $checkoutSession,
MollieHelper $mollieHelper,
OrderCommentHistory $orderCommentHistory,
BuildTransaction $buildTransaction,
Config $config,
DashboardUrl $dashboardUrl,
Transaction $transaction,
TransactionProcessor $transactionProcessor,
OrderAmount $orderAmount,
TransactionDescription $transactionDescription,
CancelOrder $cancelOrder,
PaymentTokenForOrder $paymentTokenForOrder,
SendOrderEmails $sendOrderEmails,
EventManager $eventManager
) {
$this->orderSender = $orderSender;
$this->invoiceSender = $invoiceSender;
$this->orderRepository = $orderRepository;
$this->checkoutSession = $checkoutSession;
$this->mollieHelper = $mollieHelper;
$this->orderCommentHistory = $orderCommentHistory;
$this->buildTransaction = $buildTransaction;
$this->config = $config;
$this->dashboardUrl = $dashboardUrl;
$this->transaction = $transaction;
$this->transactionProcessor = $transactionProcessor;
Expand All @@ -163,6 +148,7 @@ public function __construct(
$this->transactionDescription = $transactionDescription;
$this->cancelOrder = $cancelOrder;
$this->paymentTokenForOrder = $paymentTokenForOrder;
$this->sendOrderEmails = $sendOrderEmails;
}

/**
Expand Down Expand Up @@ -351,25 +337,11 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
$sendInvoice = $this->mollieHelper->sendInvoice($storeId);

if (!$order->getEmailSent()) {
try {
$this->orderSender->send($order);
$message = __('New order email sent');
$this->orderCommentHistory->add($order, $message, true);
} catch (\Throwable $exception) {
$message = __('Unable to send the new order email: %1', $exception->getMessage());
$this->orderCommentHistory->add($order, $message, false);
}
$this->sendOrderEmails->sendOrderConfirmation($order);
}

if ($invoice && !$invoice->getEmailSent() && $sendInvoice) {
try {
$this->invoiceSender->send($invoice);
$message = __('Notified customer about invoice #%1', $invoice->getIncrementId());
$this->orderCommentHistory->add($order, $message, true);
} catch (\Throwable $exception) {
$message = __('Unable to send the invoice: %1', $exception->getMessage());
$this->orderCommentHistory->add($order, $message, true);
}
$this->sendOrderEmails->sendInvoiceEmail($invoice);
}
}

Expand All @@ -385,19 +357,15 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
}
if ($status == 'open') {
if ($paymentData->method == 'banktransfer' && !$order->getEmailSent()) {
try {
$this->orderSender->send($order);
$message = __('New order email sent');
} catch (\Throwable $exception) {
$message = __('Unable to send the new order email: %1', $exception->getMessage());
}

if (!$statusPending = $this->mollieHelper->getStatusPendingBanktransfer($storeId)) {
$statusPending = $order->getStatus();
}

$order->setStatus($statusPending);
$order->setState(Order::STATE_PENDING_PAYMENT);
$this->sendOrderEmails->sendOrderConfirmation($order);

$this->transactionProcessor->process($order, null, $paymentData);
$order->addStatusToHistory($statusPending, $message, true);
$this->orderRepository->save($order);
}
$msg = ['success' => true, 'status' => 'open', 'order_id' => $orderId, 'type' => $type];
Expand Down
Loading

0 comments on commit 7fe08fa

Please sign in to comment.