Skip to content

Commit

Permalink
Merge pull request #71 from moneimagento/hotfix/moneiProjects
Browse files Browse the repository at this point in the history
Hotfix/monei projects
  • Loading branch information
jimmyn authored Dec 12, 2024
2 parents 099d740 + 9bfa90c commit 5c0db93
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Block/Info/Monei.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

class Monei extends Info
{
private const INFO_PAY_ALLOWED = [
'last4',
'brand',
'phoneNumber',
];

/**
* Monei template
*
Expand Down Expand Up @@ -82,4 +88,9 @@ public function getPaymentTitle()

return null;
}

public function getInfoPayAllowed(): array
{
return self::INFO_PAY_ALLOWED;
}
}
2 changes: 1 addition & 1 deletion Controller/Payment/Complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function execute()
$this->orderRepository->save($order);

// send Order email
if ($order->getCanSendNewEmailFlag()) {
if ($order->getCanSendNewEmailFlag() && !$order->getEmailSent()) {
try {
$this->orderSender->send($order);
} catch (\Exception $e) {
Expand Down
5 changes: 5 additions & 0 deletions Observer/SaveOrderBeforeSalesModelQuoteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\Quote;
use Magento\Sales\Model\Order;
use Monei\MoneiPayment\Model\Payment\Monei;

class SaveOrderBeforeSalesModelQuoteObserver implements ObserverInterface
{
Expand All @@ -37,6 +38,10 @@ public function execute(Observer $observer): SaveOrderBeforeSalesModelQuoteObser

$this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $quote, $order);

if (in_array($order->getPayment()->getMethod(), Monei::PAYMENT_METHODS_MONEI)) {
$order->setCanSendNewEmailFlag(false);
}

return $this;
}
}
36 changes: 36 additions & 0 deletions Observer/SaveQuoteSubmitSuccessObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @author Monei Team
* @copyright Copyright © Monei (https://monei.com)
*/

declare(strict_types=1);

namespace Monei\MoneiPayment\Observer;

use Magento\Framework\DataObject\Copy;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\Quote;
use Magento\Sales\Model\Order;
use Monei\MoneiPayment\Model\Payment\Monei;

class SaveQuoteSubmitSuccessObserver implements ObserverInterface
{
/**
* @param Observer $observer
* @return SaveQuoteSubmitSuccessObserver
*/
public function execute(Observer $observer): SaveQuoteSubmitSuccessObserver
{
/* @var Order $order */
$order = $observer->getEvent()->getData('order');

if (in_array($order->getPayment()->getMethod(), Monei::PAYMENT_METHODS_MONEI)) {
$order->setCanSendNewEmailFlag(true);
}

return $this;
}
}
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<event name="sales_model_service_quote_submit_before">
<observer name="Monei\MoneiPayment\Observer\SaveOrderBeforeSalesModelQuoteObserver" instance="Monei\MoneiPayment\Observer\SaveOrderBeforeSalesModelQuoteObserver" />
</event>
<event name="sales_model_service_quote_submit_success">
<observer name="Monei\MoneiPayment\Observer\SaveQuoteSubmitSuccessObserver" instance="Monei\MoneiPayment\Observer\SaveQuoteSubmitSuccessObserver" />
</event>
<!-- <event name="sales_order_creditmemo_refund">-->
<!-- <observer name="set_monei_order_status_and_state_after_refund" instance="Monei\MoneiPayment\Observer\SetOrderStatusAfterRefund"/>-->
<!-- </event>-->
Expand Down
4 changes: 4 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
"%1 should be numeric value","%1 should be numeric value"
"Refund reason","Refund reason"
"Pay with Monei","Pay with MONEI"
"method:","Method:"
"last4:","Last 4 digits:"
"brand:","Brand:"
"phoneNumber:","Phone number:"
4 changes: 4 additions & 0 deletions i18n/es_ES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
"Multibanco payment method is not available in your Monei account. Please enable it in your Monei account to use it.","El método de pago de Multibanco no está disponible en su cuenta de Monei. Por favor, habilítelo en su cuenta de Monei para poder usarlo."
"MBWay payment method is not available in your Monei account. Please enable it in your Monei account to use it.","El método de pago de MBWay no está disponible en su cuenta de Monei. Por favor, habilítelo en su cuenta de Monei para poder usarlo."
"(Test Mode)","(Modo de Prueba)"
"method:","Método:"
"last4:","Últimos 4 digitos:"
"brand:","Tipo:"
"phoneNumber:","Teléfono:"
23 changes: 19 additions & 4 deletions view/frontend/templates/info/monei.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,28 @@
*/
$paymentTitle = $block->getPaymentTitle();
$paymentInfo = $block->getPaymentInfo();
$infoCard = '';
?>
<?= $block->escapeHtml($paymentTitle) ?>
<?php if (is_array($paymentInfo)) : ?>
<?php foreach ($paymentInfo as $payKey => $payValue) { ?>
<?php foreach ($paymentInfo as $payKey => $payValue): ?>
<?php if (in_array($payKey, $block->getInfoPayAllowed(), true)) : ?>
<?php if($payKey === 'last4') : ?>
<?php $infoCard = $infoCard . '···· '. $payValue; ?>
<?php continue; ?>
<?php endif; ?>
<?php if($payKey === 'brand') : ?>
<?php $infoCard = ucfirst($payValue) . ' '. $infoCard; ?>
<?php continue; ?>
<?php endif; ?>
<div class="admin__page-section-item-content">
<span class="payment_details"><?= $block->escapeHtml($payValue) ?></span>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php if($infoCard) : ?>
<div class="admin__page-section-item-content">
<strong><?= $block->escapeHtml(__($payKey . ':')) ?></strong>
<span class="payment_details"><?= $block->escapeHtml($payValue) ?></span>
<span class="payment_details"><?= $block->escapeHtml($infoCard) ?></span>
</div>
<?php } ?>
<?php endif; ?>
<?php endif; ?>

0 comments on commit 5c0db93

Please sign in to comment.