Skip to content

Commit

Permalink
Merge pull request #47 from MONEI/next
Browse files Browse the repository at this point in the history
Support php 7.4
  • Loading branch information
jimmyn authored Apr 9, 2024
2 parents fa3b784 + 6f946ac commit 7bd3d48
Show file tree
Hide file tree
Showing 31 changed files with 420 additions and 82 deletions.
37 changes: 36 additions & 1 deletion Api/Config/MoneiPaymentModuleConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ interface MoneiPaymentModuleConfigInterface

public const PRODUCTION_URL = 'payment/monei/production_url';

public const ACCOUNT_ID = 'payment/monei/account_id';
public const TEST_ACCOUNT_ID = 'payment/monei/test_account_id';

public const PRODUCTION_ACCOUNT_ID = 'payment/monei/production_account_id';

public const TEST_API_KEY = 'payment/monei/test_api_key';

Expand Down Expand Up @@ -60,6 +62,14 @@ public function isEnabled($storeId = null): bool;
*/
public function getMode($storeId = null): int;

/**
* Get test URL
*
* @param null $storeId
* @return string
*/
public function getUrl($storeId = null): string;

/**
* Get test URL
*
Expand All @@ -84,6 +94,31 @@ public function getProductionUrl($storeId = null): string;
*/
public function getAccountId(int $storeId = null): string;

/**
* Get test account id
*
* @param int|null $storeId
* @return string
*/
public function getTestAccountId(int $storeId = null): string;

/**
* Get production account id
*
* @param int|null $storeId
* @return string
*/
public function getProductionAccountId(int $storeId = null): string;


/**
* Get test API key
*
* @param null $storeId
* @return string
*/
public function getApiKey($storeId = null): string;

/**
* Get test API key
*
Expand Down
37 changes: 25 additions & 12 deletions Controller/Payment/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,33 @@
class Callback implements CsrfAwareActionInterface, HttpPostActionInterface
{
private string $errorMessage = '';
private Context $context;
private SerializerInterface $serializer;
private MoneiPaymentModuleConfigInterface $moduleConfig;
private Logger $logger;
private StoreManagerInterface $storeManager;
private GenerateInvoiceInterface $generateInvoiceService;
private SetOrderStatusAndStateInterface $setOrderStatusAndStateService;
private MagentoRedirect $resultRedirectFactory;

public function __construct(
private readonly Context $context,
private readonly SerializerInterface $serializer,
private readonly MoneiPaymentModuleConfigInterface $moduleConfig,
private readonly Logger $logger,
private readonly StoreManagerInterface $storeManager,
private readonly GenerateInvoiceInterface $generateInvoiceService,
private readonly SetOrderStatusAndStateInterface $setOrderStatusAndStateService,
private readonly MagentoRedirect $resultRedirectFactory
Context $context,
SerializerInterface $serializer,
MoneiPaymentModuleConfigInterface $moduleConfig,
Logger $logger,
StoreManagerInterface $storeManager,
GenerateInvoiceInterface $generateInvoiceService,
SetOrderStatusAndStateInterface $setOrderStatusAndStateService,
MagentoRedirect $resultRedirectFactory
) {
$this->resultRedirectFactory = $resultRedirectFactory;
$this->setOrderStatusAndStateService = $setOrderStatusAndStateService;
$this->generateInvoiceService = $generateInvoiceService;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->moduleConfig = $moduleConfig;
$this->serializer = $serializer;
$this->context = $context;
}

/**
Expand Down Expand Up @@ -132,11 +148,8 @@ private function verifySignature(string $body, array $header): void
private function getApiKey(): string
{
$currentStoreId = $this->storeManager->getStore()->getId();
if ($this->moduleConfig->getMode($currentStoreId) === Mode::MODE_TEST) {
return $this->moduleConfig->getTestApiKey($currentStoreId);
}

return $this->moduleConfig->getProductionApiKey($currentStoreId);
return $this->moduleConfig->getApiKey($currentStoreId);
}

private function splitMoneiSignature(string $signature): array
Expand Down
4 changes: 3 additions & 1 deletion Controller/Payment/Complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Complete implements ActionInterface
* @var OrderSender
*/
protected $orderSender;
private CreateVaultPayment $createVaultPayment;

/**
* @param Context $context
Expand All @@ -97,8 +98,9 @@ public function __construct(
MagentoRedirect $resultRedirectFactory,
PendingOrderFactory $pendingOrderFactory,
PendingOrderResource $pendingOrderResource,
private readonly CreateVaultPayment $createVaultPayment
CreateVaultPayment $createVaultPayment
) {
$this->createVaultPayment = $createVaultPayment;
$this->context = $context;
$this->orderRepository = $orderRepository;
$this->orderSender = $orderSender;
Expand Down
9 changes: 7 additions & 2 deletions Controller/Payment/FailLastOrderByStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
*/
class FailLastOrderByStatus extends Fail
{
private Context $context;
private Session $checkoutSession;

public function __construct(
private readonly Context $context,
private readonly Session $checkoutSession,
Context $context,
Session $checkoutSession,
OrderInterfaceFactory $orderFactory,
SetOrderStatusAndStateInterface $setOrderStatusAndStateService,
ManagerInterface $messageManager,
MagentoRedirect $resultRedirectFactory
) {
$this->checkoutSession = $checkoutSession;
$this->context = $context;
parent::__construct($context, $checkoutSession, $orderFactory, $setOrderStatusAndStateService, $messageManager, $resultRedirectFactory);

}
Expand Down
23 changes: 18 additions & 5 deletions Model/CheckoutConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,32 @@
class CheckoutConfigProvider implements ConfigProviderInterface
{

private UrlInterface $urlBuilder;
private MoneiPaymentModuleConfigInterface $moneiPaymentConfig;
private MoneiCardPaymentModuleConfigInterface $moneiCardPaymentConfig;
private MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentConfig;
private StoreManagerInterface $storeManager;

public function __construct(
private readonly UrlInterface $urlBuilder,
private readonly MoneiPaymentModuleConfigInterface $moneiPaymentConfig,
private readonly MoneiCardPaymentModuleConfigInterface $moneiCardPaymentConfig,
private readonly MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentConfig,
private readonly StoreManagerInterface $storeManager,
UrlInterface $urlBuilder,
MoneiPaymentModuleConfigInterface $moneiPaymentConfig,
MoneiCardPaymentModuleConfigInterface $moneiCardPaymentConfig,
MoneiGoogleApplePaymentModuleConfigInterface $moneiGoogleApplePaymentConfig,
StoreManagerInterface $storeManager
)
{
$this->moneiGoogleApplePaymentConfig = $moneiGoogleApplePaymentConfig;
$this->moneiCardPaymentConfig = $moneiCardPaymentConfig;
$this->moneiPaymentConfig = $moneiPaymentConfig;
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
}

public function getConfig(): array
{
return [
'moneiAccountId' => $this->moneiPaymentConfig->getAccountId($this->getStoreId()),
'moneiApiKey' => $this->moneiPaymentConfig->getApiKey($this->getStoreId()),
'payment' => [
Monei::CODE => [
'redirectUrl' => $this->urlBuilder->getUrl('monei/payment/redirect'),
Expand Down
5 changes: 4 additions & 1 deletion Model/Config/MoneiBizumPaymentModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
class MoneiBizumPaymentModuleConfig implements MoneiBizumPaymentModuleConfigInterface
{
private ScopeConfigInterface $scopeConfig;

public function __construct(
private readonly ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Model/Config/MoneiCardPaymentModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
class MoneiCardPaymentModuleConfig implements MoneiCardPaymentModuleConfigInterface
{
private ScopeConfigInterface $scopeConfig;

public function __construct(
private readonly ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Model/Config/MoneiGoogleApplePaymentModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
class MoneiGoogleApplePaymentModuleConfig implements MoneiGoogleApplePaymentModuleConfigInterface
{
private ScopeConfigInterface $scopeConfig;

public function __construct(
private readonly ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
Expand Down
50 changes: 48 additions & 2 deletions Model/Config/MoneiPaymentModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
use Monei\MoneiPayment\Api\Config\MoneiPaymentModuleConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Monei\MoneiPayment\Model\Config\Source\Mode;

/**
* Get Monei payment method configuration class.
*/
class MoneiPaymentModuleConfig implements MoneiPaymentModuleConfigInterface
{
private ScopeConfigInterface $scopeConfig;

public function __construct(
private readonly ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
Expand All @@ -47,6 +51,16 @@ public function getMode($storeId = null): int
);
}

/**
* @inheritDoc
*/
public function getUrl($storeId = null): string
{
return $this->getMode($storeId) === Mode::MODE_TEST
? $this->getTestUrl($storeId)
: $this->getProductionUrl($storeId);
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -75,14 +89,46 @@ public function getProductionUrl($storeId = null): string
* @inheritDoc
*/
public function getAccountId(int $storeId = null): string
{
return $this->getMode($storeId) === Mode::MODE_TEST
? $this->getTestAccountId($storeId)
: $this->getProductionAccountId($storeId);
}

/**
* @inheritDoc
*/
public function getTestAccountId(int $storeId = null): string
{
return (string) $this->scopeConfig->getValue(
self::ACCOUNT_ID,
self::TEST_ACCOUNT_ID,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @inheritDoc
*/
public function getProductionAccountId(int $storeId = null): string
{
return (string) $this->scopeConfig->getValue(
self::PRODUCTION_ACCOUNT_ID,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @inheritDoc
*/
public function getApiKey($storeId = null): string
{
return $this->getMode($storeId) === Mode::MODE_TEST
? $this->getTestApiKey($storeId)
: $this->getProductionApiKey($storeId);
}

/**
* @inheritDoc
*/
Expand Down
8 changes: 6 additions & 2 deletions Model/OrderLockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

class OrderLockManager implements OrderLockManagerInterface
{
private LockManagerInterface $lockManager;

public function __construct(
private readonly LockManagerInterface $lockManager
) {}
LockManagerInterface $lockManager
) {
$this->lockManager = $lockManager;
}

public function lock(string $incrementId): bool
{
Expand Down
5 changes: 4 additions & 1 deletion Model/Ui/Card/TokenUiComponentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
class TokenUiComponentProvider implements TokenUiComponentProviderInterface
{

private TokenUiComponentInterfaceFactory $componentFactory;

public function __construct(
private readonly TokenUiComponentInterfaceFactory $componentFactory
TokenUiComponentInterfaceFactory $componentFactory
)
{
$this->componentFactory = $componentFactory;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Observer/SaveOrderBeforeSalesModelQuoteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

class SaveOrderBeforeSalesModelQuoteObserver implements ObserverInterface
{
public function __construct(private readonly Copy $objectCopyService)
private Copy $objectCopyService;

public function __construct(Copy $objectCopyService)
{
$this->objectCopyService = $objectCopyService;
}

/**
Expand Down
Loading

0 comments on commit 7bd3d48

Please sign in to comment.