-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLUG-106: Add custom error type that is always deduplicated and inval…
…idates frontend cache
- Loading branch information
Showing
7 changed files
with
111 additions
and
26 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
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,38 @@ | ||
<?php | ||
/** | ||
* Copyright © TrueLayer Ltd. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace TrueLayer\Connect\Service\Order; | ||
|
||
use Magento\Framework\Message\ManagerInterface; | ||
use Magento\Framework\Message\MessageInterface; | ||
|
||
class PaymentErrorMessageManager | ||
{ | ||
private ManagerInterface $messageManager; | ||
|
||
/** | ||
* @param ManagerInterface $messageManager | ||
*/ | ||
public function __construct(ManagerInterface $messageManager) | ||
{ | ||
$this->messageManager = $messageManager; | ||
} | ||
|
||
/** | ||
* Add a unique message using our custom truelayer payment error template | ||
* This will trigger a cart and checkout-data refresh on the frontend | ||
* @param string $text | ||
*/ | ||
public function addMessage(string $text): void | ||
{ | ||
$message = $this->messageManager | ||
->createMessage(MessageInterface::TYPE_ERROR, 'truelayer_payment_error') | ||
->setData(['text' => $text]); | ||
|
||
$this->messageManager->addUniqueMessages([ $message ]); | ||
} | ||
} |
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,15 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool"> | ||
<arguments> | ||
<argument name="configurationsMap" xsi:type="array"> | ||
<item name="truelayer_payment_error" xsi:type="array"> | ||
<item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item> | ||
<item name="data" xsi:type="array"> | ||
<item name="template" xsi:type="string">TrueLayer_Connect::checkout/payment_error_message.phtml</item> | ||
</item> | ||
</item> | ||
</argument> | ||
</arguments> | ||
</type> | ||
</config> |
26 changes: 26 additions & 0 deletions
26
view/frontend/templates/checkout/payment_error_message.phtml
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,26 @@ | ||
<?php | ||
|
||
use Magento\Framework\Escaper; | ||
|
||
/** | ||
* @var Escaper $escaper | ||
*/ | ||
?> | ||
|
||
<span class="truelayer-payment-error"> | ||
<?=$escaper->escapeHtml(__($block->getData('text')));?> | ||
</span> | ||
|
||
<script type="text/x-magento-init"> | ||
{ | ||
".truelayer-payment-error": { | ||
"Magento_Ui/js/core/app": { | ||
"components": { | ||
"truelayer-pending": { | ||
"component": "TrueLayer_Connect/js/cart_refresh" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</script> |
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,18 @@ | ||
/** | ||
* Copyright © TrueLayer Ltd, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define(['Magento_Customer/js/customer-data', 'uiComponent'], function (customerData, Component) { | ||
'use strict'; | ||
|
||
return Component.extend({ | ||
initialize() { | ||
this._super(); | ||
|
||
var sections = ['cart', 'checkout-data']; | ||
customerData.invalidate(sections); | ||
customerData.reload(sections, true); | ||
}, | ||
}); | ||
}); |
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