Skip to content

Commit

Permalink
Merge branch 'main' of github.com:MONEI/MONEI-AdobeCommerce-Magento2 …
Browse files Browse the repository at this point in the history
…into php74

# Conflicts:
#	build/package.json
#	composer.json
#	etc/module.xml
  • Loading branch information
jimmyn committed Dec 23, 2024
2 parents be4e6a6 + b8aaede commit 4e02c0f
Show file tree
Hide file tree
Showing 72 changed files with 1,124 additions and 14,742 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.composer.lock

# Yarn
/build/.pnp.*
/build/.yarn/*
!/build/.yarn/patches
!/build/.yarn/plugins
Expand Down
25 changes: 25 additions & 0 deletions Api/Config/AllMoneiPaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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

declare(strict_types=1);

namespace Monei\MoneiPayment\Api\Config;

/**
* Get payment method configuration interface.
*/
interface AllMoneiPaymentModuleConfigInterface
{

/**
* Check if any payment methods is enabled
*
* @param null $storeId
* @return bool
*/
public function isAnyPaymentEnabled($storeId = null): bool;
}
10 changes: 10 additions & 0 deletions Api/Config/MoneiBizumPaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface MoneiBizumPaymentModuleConfigInterface

public const SORT_ORDER = 'payment/monei_bizum/sort_order';

public const JSON_STYLE = 'payment/monei_bizum/json_style';

/**
* Check if payment method is enabled
*
Expand Down Expand Up @@ -63,4 +65,12 @@ public function getSpecificCountries(int $storeId = null): string;
* @return int
*/
public function getSortOrder(int $storeId = null): int;

/**
* Get json style for payment method
*
* @param int|null $storeId
* @return array
*/
public function getJsonStyle(int $storeId = null): array;
}
10 changes: 10 additions & 0 deletions Api/Config/MoneiCardPaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface MoneiCardPaymentModuleConfigInterface

public const SORT_ORDER = 'payment/monei_card/sort_order';

public const JSON_STYLE = 'payment/monei_card/json_style';

/**
* Check if payment method is enabled
*
Expand Down Expand Up @@ -73,4 +75,12 @@ public function getSpecificCountries(int $storeId = null): string;
* @return int
*/
public function getSortOrder(int $storeId = null): int;

/**
* Get json style for payment method
*
* @param int|null $storeId
* @return array
*/
public function getJsonStyle(int $storeId = null): array;
}
10 changes: 10 additions & 0 deletions Api/Config/MoneiGoogleApplePaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface MoneiGoogleApplePaymentModuleConfigInterface

public const SORT_ORDER = 'payment/monei_google_apple/sort_order';

public const JSON_STYLE = 'payment/monei_google_apple/json_style';

/**
* Check if payment method is enabled
*
Expand Down Expand Up @@ -83,4 +85,12 @@ public function getSpecificCountries(int $storeId = null): string;
* @return int
*/
public function getSortOrder(int $storeId = null): int;

/**
* Get json style for payment method
*
* @param int|null $storeId
* @return array
*/
public function getJsonStyle(int $storeId = null): array;
}
10 changes: 10 additions & 0 deletions Api/Config/MoneiPaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface MoneiPaymentModuleConfigInterface

public const PRODUCTION_API_KEY = 'payment/monei/production_api_key';

public const LANGUAGE = 'payment/monei/language';

public const TITLE = 'payment/monei/title';

public const DESCRIPTION = 'payment/monei/description';
Expand Down Expand Up @@ -135,6 +137,14 @@ public function getTestApiKey($storeId = null): string;
*/
public function getProductionApiKey($storeId = null): string;

/**
* Get language
*
* @param int|null $storeId
* @return string
*/
public function getLanguage(int $storeId = null): string;

/**
* Get payment method title
*
Expand Down
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
28 changes: 26 additions & 2 deletions Controller/Payment/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\App\ActionInterface;
use Magento\Framework\Controller\Result\Redirect as MagentoRedirect;
use Magento\Sales\Api\Data\OrderInterface;
use Monei\MoneiPayment\Service\Shared\GetMoneiPaymentCodesByMagentoPaymentCodeRedirect;

/**
* Monei payment redirect controller
Expand All @@ -35,6 +36,11 @@ class Redirect implements ActionInterface
*/
private $resultRedirectFactory;

/**
* @var GetMoneiPaymentCodesByMagentoPaymentCodeRedirect
*/
private $getMoneiPaymentCodesByMagentoPaymentCodeRedirect;

/**
* @param Session $checkoutSession
* @param CreatePaymentInterface $createPayment
Expand All @@ -43,11 +49,13 @@ class Redirect implements ActionInterface
public function __construct(
Session $checkoutSession,
CreatePaymentInterface $createPayment,
MagentoRedirect $resultRedirectFactory
MagentoRedirect $resultRedirectFactory,
GetMoneiPaymentCodesByMagentoPaymentCodeRedirect $getMoneiPaymentCodesByMagentoPaymentCodeRedirect
) {
$this->checkoutSession = $checkoutSession;
$this->createPayment = $createPayment;
$this->resultRedirectFactory = $resultRedirectFactory;
$this->getMoneiPaymentCodesByMagentoPaymentCodeRedirect = $getMoneiPaymentCodesByMagentoPaymentCodeRedirect;
}

/**
Expand All @@ -59,15 +67,21 @@ public function execute()
* @var $order OrderInterface
*/
$order = $this->checkoutSession->getLastRealOrder();

$data = [
"amount" => $order->getBaseGrandTotal() * 100,
"orderId" => (string) $order->getIncrementId(),
"currency" => $order->getBaseCurrencyCode(),
"customer" => $this->getCustomerDetails($order),
"billingDetails" => $this->getAddressDetails($order->getBillingAddress()),
"shippingDetails" => $this->getAddressDetails($order->getShippingAddress()),
"shippingDetails" => $this->getAddressDetails($order->getShippingAddress())
];

$allowedPaymentMethods = $this->getAllowedPaymentMethods($order);
if($allowedPaymentMethods){
$data['allowedPaymentMethods'] = $allowedPaymentMethods;
}

$result = $this->createPayment->execute($data);
if (!isset($result['error']) && isset($result['nextAction']['redirectUrl'])) {
$this->resultRedirectFactory->setUrl($result['nextAction']['redirectUrl']);
Expand Down Expand Up @@ -149,4 +163,14 @@ private function getAddressDetails($address)

return $moneiAddress;
}

private function getAllowedPaymentMethods(OrderInterface $order): array
{
$payment = $order->getPayment();
$paymentCode = $payment ? $payment->getMethod() : null;

return $paymentCode
? $this->getMoneiPaymentCodesByMagentoPaymentCodeRedirect->execute($paymentCode)
: [];
}
}
32 changes: 24 additions & 8 deletions Model/CheckoutConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Monei\MoneiPayment\Api\Config\AllMoneiPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiBizumPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiCardPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiGoogleApplePaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiPaymentModuleConfigInterface;
use Monei\MoneiPayment\Block\Monei\Customer\CardRenderer;
use Monei\MoneiPayment\Model\Config\AllMoneiPaymentModuleConfig;
use Monei\MoneiPayment\Model\Config\Source\Mode;
use Monei\MoneiPayment\Model\Payment\Monei;
use Monei\MoneiPayment\Service\Shared\IsEnabledApplePayInMoneiAccount;
use Monei\MoneiPayment\Service\Shared\IsEnabledGooglePayInMoneiAccount;
Expand All @@ -31,21 +35,26 @@ class CheckoutConfigProvider implements ConfigProviderInterface
private MoneiPaymentModuleConfigInterface $moneiPaymentConfig;
private MoneiCardPaymentModuleConfigInterface $moneiCardPaymentConfig;
private MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentConfig;
private MoneiBizumPaymentModuleConfigInterface $moneiBizumPaymentModuleConfig;
private StoreManagerInterface $storeManager;
private IsEnabledGooglePayInMoneiAccount $isEnabledGooglePayInMoneiAccount;
private IsEnabledApplePayInMoneiAccount $isEnabledApplePayInMoneiAccount;

public function __construct(
UrlInterface $urlBuilder,
AllMoneiPaymentModuleConfigInterface $allMoneiPaymentModuleConfig,
MoneiPaymentModuleConfigInterface $moneiPaymentConfig,
MoneiCardPaymentModuleConfigInterface $moneiCardPaymentConfig,
MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentConfig,
MoneiBizumPaymentModuleConfigInterface $moneiBizumPaymentModuleConfig,
IsEnabledGooglePayInMoneiAccount $isEnabledGooglePayInMoneiAccount,
IsEnabledApplePayInMoneiAccount $isEnabledApplePayInMoneiAccount,
StoreManagerInterface $storeManager
)
{
$this->allMoneiPaymentModuleConfig = $allMoneiPaymentModuleConfig;
$this->moneiGoogleApplePaymentConfig = $moneiGoogleApplePaymentConfig;
$this->moneiBizumPaymentModuleConfig = $moneiBizumPaymentModuleConfig;
$this->moneiCardPaymentConfig = $moneiCardPaymentConfig;
$this->isEnabledGooglePayInMoneiAccount = $isEnabledGooglePayInMoneiAccount;
$this->isEnabledApplePayInMoneiAccount = $isEnabledApplePayInMoneiAccount;
Expand All @@ -56,9 +65,13 @@ public function __construct(

public function getConfig(): array
{
$storeId = $this->getStoreId();
return [
'moneiAccountId' => $this->moneiPaymentConfig->getAccountId($this->getStoreId()),
'moneiApiKey' => $this->moneiPaymentConfig->getApiKey($this->getStoreId()),
'moneiAccountId' => $this->moneiPaymentConfig->getAccountId($storeId),
'moneiApiKey' => $this->moneiPaymentConfig->getApiKey($storeId),
'moneiPaymentIsEnabled' => $this->allMoneiPaymentModuleConfig->isAnyPaymentEnabled($storeId),
'isMoneiTestMode' => $this->moneiPaymentConfig->getMode($storeId) === Mode::MODE_TEST,
'moneiLanguage' => $this->moneiPaymentConfig->getLanguage($storeId),
'payment' => [
Monei::CODE => [
'redirectUrl' => $this->urlBuilder->getUrl('monei/payment/redirect'),
Expand All @@ -79,9 +92,10 @@ public function getConfig(): array
Monei::ORDER_STATUS_CANCELED,
Monei::ORDER_STATUS_FAILED,
],
'accountId' => $this->moneiPaymentConfig->getAccountId($this->getStoreId()),
'isEnabledTokenization' => $this->moneiCardPaymentConfig->isEnabledTokenization($this->getStoreId()),
'accountId' => $this->moneiPaymentConfig->getAccountId($storeId),
'isEnabledTokenization' => $this->moneiCardPaymentConfig->isEnabledTokenization($storeId),
'ccVaultCode' => Monei::CC_VAULT_CODE,
'jsonStyle' => $this->moneiCardPaymentConfig->getJsonStyle($storeId)
],
Monei::BIZUM_CODE => [
'redirectUrl' => $this->urlBuilder->getUrl('monei/payment/redirect'),
Expand All @@ -92,13 +106,14 @@ public function getConfig(): array
Monei::ORDER_STATUS_CANCELED,
Monei::ORDER_STATUS_FAILED,
],
'accountId' => $this->moneiPaymentConfig->getAccountId($this->getStoreId())
'accountId' => $this->moneiPaymentConfig->getAccountId($storeId),
'jsonStyle' =>$this->moneiBizumPaymentModuleConfig->getJsonStyle($storeId)
],
Monei::GOOGLE_APPLE_CODE => [
'isEnabledGooglePay' => $this->isEnabledGooglePayInMoneiAccount->execute(),
'isEnabledApplePay' => $this->isEnabledApplePayInMoneiAccount->execute(),
'googleTitle' => $this->moneiGoogleApplePaymentConfig->getGoogleTitle($this->getStoreId()),
'appleTitle' => $this->moneiGoogleApplePaymentConfig->getAppleTitle($this->getStoreId()),
'googleTitle' => $this->moneiGoogleApplePaymentConfig->getGoogleTitle($storeId),
'appleTitle' => $this->moneiGoogleApplePaymentConfig->getAppleTitle($storeId),
'redirectUrl' => $this->urlBuilder->getUrl('monei/payment/redirect'),
'cancelOrderUrl' => $this->urlBuilder->getUrl('monei/payment/cancel'),
'failOrderUrl' => $this->urlBuilder->getUrl('monei/payment/faillastorderbystatus'),
Expand All @@ -107,7 +122,8 @@ public function getConfig(): array
Monei::ORDER_STATUS_CANCELED,
Monei::ORDER_STATUS_FAILED,
],
'accountId' => $this->moneiPaymentConfig->getAccountId($this->getStoreId())
'accountId' => $this->moneiPaymentConfig->getAccountId($storeId),
'jsonStyle' =>$this->moneiGoogleApplePaymentConfig->getJsonStyle($storeId)
],
],
'vault' => [
Expand Down
49 changes: 49 additions & 0 deletions Model/Config/AllMoneiPaymentModuleConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

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

declare(strict_types=1);

namespace Monei\MoneiPayment\Model\Config;

use Monei\MoneiPayment\Api\Config\AllMoneiPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiBizumPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiCardPaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiGoogleApplePaymentModuleConfigInterface;
use Monei\MoneiPayment\Api\Config\MoneiPaymentModuleConfigInterface;

class AllMoneiPaymentModuleConfig implements AllMoneiPaymentModuleConfigInterface
{

private MoneiPaymentModuleConfigInterface $moneiPaymentModuleConfig;
private MoneiCardPaymentModuleConfigInterface $moneiCardPaymentModuleConfig;
private MoneiBizumPaymentModuleConfigInterface $moneiBizumPaymentModuleConfig;
private MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentModuleConfig;

public function __construct(
MoneiPaymentModuleConfigInterface $moneiPaymentModuleConfig,
MoneiCardPaymentModuleConfigInterface $moneiCardPaymentModuleConfig,
MoneiBizumPaymentModuleConfigInterface $moneiBizumPaymentModuleConfig,
MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentModuleConfig,
) {

$this->moneiPaymentModuleConfig = $moneiPaymentModuleConfig;
$this->moneiCardPaymentModuleConfig = $moneiCardPaymentModuleConfig;
$this->moneiBizumPaymentModuleConfig = $moneiBizumPaymentModuleConfig;
$this->moneiGoogleApplePaymentModuleConfig = $moneiGoogleApplePaymentModuleConfig;
}

/**
* @inheritDoc
*/
public function isAnyPaymentEnabled($storeId = null): bool
{
return (bool) $this->moneiPaymentModuleConfig->isEnabled($storeId)
|| (bool) $this->moneiCardPaymentModuleConfig->isEnabled($storeId)
|| (bool) $this->moneiBizumPaymentModuleConfig->isEnabled($storeId)
|| (bool) $this->moneiGoogleApplePaymentModuleConfig->isEnabled($storeId);
}
}
Loading

0 comments on commit 4e02c0f

Please sign in to comment.