-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/custom-template-option-for-payment-link' into r…
…elease-week-11
- Loading branch information
Showing
14 changed files
with
461 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Plugin/Sales/Model/Order/Email/Sender/SendPaymentLinkConfirmation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Plugin\Sales\Model\Order\Email\Sender; | ||
|
||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\Email\Sender\OrderSender; | ||
use Mollie\Payment\Service\Order\PaymentLinkConfirmationEmail; | ||
|
||
class SendPaymentLinkConfirmation | ||
{ | ||
/** | ||
* @var \Mollie\Payment\Config | ||
*/ | ||
private $config; | ||
/** | ||
* @var PaymentLinkConfirmationEmail | ||
*/ | ||
private $paymentLinkConfirmationEmail; | ||
|
||
public function __construct( | ||
\Mollie\Payment\Config $config, | ||
PaymentLinkConfirmationEmail $paymentLinkConfirmationEmail | ||
) { | ||
$this->config = $config; | ||
$this->paymentLinkConfirmationEmail = $paymentLinkConfirmationEmail; | ||
} | ||
|
||
public function aroundSend(OrderSender $subject, callable $proceed, Order $order, $forceSyncMode = false) | ||
{ | ||
// When the `send()` method of the OrderSender is called, we want to call our own class instead. | ||
// But this class is also based on the OrderSender, so we need to check if we are not already in our own class. | ||
if ($order->getPayment()->getMethod() == 'mollie_methods_paymentlink' && | ||
$this->config->paymentLinkUseCustomEmailTemplate((int)$order->getStoreId()) && | ||
!($subject instanceof $this->paymentLinkConfirmationEmail) | ||
) { | ||
return $this->paymentLinkConfirmationEmail->send($order); | ||
} | ||
|
||
return $proceed($order, $forceSyncMode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Order\Email; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Sales\Model\Order\Email\Container\OrderIdentity; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Mollie\Payment\Config; | ||
|
||
class PaymentLinkOrderIdentity extends OrderIdentity | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
StoreManagerInterface $storeManager, | ||
Config $config | ||
) { | ||
parent::__construct($scopeConfig, $storeManager); | ||
|
||
$this->config = $config; | ||
} | ||
|
||
public function isEnabled() | ||
{ | ||
return $this->config->paymentLinkUseCustomEmailTemplate(); | ||
} | ||
|
||
public function getTemplateId() | ||
{ | ||
return $this->config->paymentLinkEmailTemplate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Order; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\Mail\Template\SenderResolverInterface; | ||
use Magento\Framework\Mail\Template\TransportBuilder; | ||
use Magento\Payment\Helper\Data as PaymentHelper; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\Address\Renderer; | ||
use Magento\Sales\Model\Order\Email\Container\OrderIdentity; | ||
use Magento\Sales\Model\Order\Email\Container\Template; | ||
use Magento\Sales\Model\Order\Email\Sender\OrderSender; | ||
use Magento\Sales\Model\Order\Email\SenderBuilderFactory; | ||
use Magento\Sales\Model\ResourceModel\Order as OrderResource; | ||
use Mollie\Payment\Config; | ||
use Mollie\Payment\Service\Magento\PaymentLinkUrl; | ||
use Mollie\Payment\Service\Order\Email\PaymentLinkOrderIdentity; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class PaymentLinkConfirmationEmail extends OrderSender | ||
{ | ||
/** | ||
* @var PaymentLinkUrl | ||
*/ | ||
private $paymentLinkUrl; | ||
|
||
public function __construct( | ||
Template $templateContainer, | ||
SenderBuilderFactory $senderBuilderFactory, | ||
LoggerInterface $logger, | ||
Renderer $addressRenderer, | ||
PaymentHelper $paymentHelper, | ||
OrderResource $orderResource, | ||
ScopeConfigInterface $globalConfig, | ||
ManagerInterface $eventManager, | ||
PaymentLinkOrderIdentity $identityContainer, | ||
PaymentLinkUrl $paymentLinkUrl | ||
) { | ||
parent::__construct( | ||
$templateContainer, | ||
$identityContainer, | ||
$senderBuilderFactory, | ||
$logger, | ||
$addressRenderer, | ||
$paymentHelper, | ||
$orderResource, | ||
$globalConfig, | ||
$eventManager | ||
); | ||
|
||
$this->paymentLinkUrl = $paymentLinkUrl; | ||
} | ||
|
||
protected function prepareTemplate(Order $order) | ||
{ | ||
parent::prepareTemplate($order); | ||
|
||
$transportObject = new DataObject($this->templateContainer->getTemplateVars()); | ||
$transportObject->setData('mollie_payment_link', $this->paymentLinkUrl->execute((int)$order->getEntityId())); | ||
|
||
$this->eventManager->dispatch( | ||
'mollie_email_paymenlink_order_set_template_vars_before', | ||
['sender' => $this, 'transportObject' => $transportObject] | ||
); | ||
|
||
$this->templateContainer->setTemplateVars($transportObject->getData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Test\Fakes\Service\Magento; | ||
|
||
use Mollie\Payment\Service\Magento\PaymentLinkUrl; | ||
|
||
class PaymentLinkUrlFake extends PaymentLinkUrl | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $url = null; | ||
|
||
private $shouldNotBeCalled = false; | ||
|
||
public function setUrl(string $url) | ||
{ | ||
$this->url = $url; | ||
} | ||
|
||
public function shouldNotBeCalled() | ||
{ | ||
$this->shouldNotBeCalled = true; | ||
} | ||
|
||
public function execute(int $orderId): string | ||
{ | ||
if ($this->shouldNotBeCalled === true) { | ||
throw new \Exception('This method should not be called'); | ||
} | ||
|
||
if ($this->url !== null) { | ||
return $this->url; | ||
} | ||
|
||
return parent::execute($orderId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.