diff --git a/Controller/Redirect/In.php b/Controller/Redirect/In.php index 10feaed2..00f2164e 100644 --- a/Controller/Redirect/In.php +++ b/Controller/Redirect/In.php @@ -167,7 +167,9 @@ public function execute() $rvvupData = $this->paymentDataGet->execute($rvvupId); if ($rvvupData['status'] != $rvvupData['payments'][0]['status']) { - $this->processorPool->getProcessor($rvvupData['status'])->execute($order, $rvvupData); + if ($rvvupData['payments'][0]['status'] !== Method::STATUS_AUTHORIZED) { + $this->processorPool->getProcessor($rvvupData['status'])->execute($order, $rvvupData); + } } $result = $this->processorPool->getProcessor($rvvupData['payments'][0]['status']) diff --git a/Gateway/Command/CreatePayment.php b/Gateway/Command/CreatePayment.php index a719e46a..e3a50364 100644 --- a/Gateway/Command/CreatePayment.php +++ b/Gateway/Command/CreatePayment.php @@ -54,6 +54,10 @@ public function execute(array $commandSubject) ] ]; + if ($captureType = $payment->getMethodInstance()->getCaptureType()) { + $data['input']['captureType'] = $captureType; + } + return $this->sdkProxy->createPayment( $data ); diff --git a/Gateway/Method.php b/Gateway/Method.php index ee33913e..8dbd8857 100644 --- a/Gateway/Method.php +++ b/Gateway/Method.php @@ -52,6 +52,8 @@ class Method extends Adapter public const STATUS_EXPIRED = 'EXPIRED'; public const STATUS_PENDING = 'PENDING'; public const STATUS_REQUIRES_ACTION = 'REQUIRES_ACTION'; + public const STATUS_AUTHORIZED = "AUTHORIZED"; + public const STATUS_AUTHORIZATION_EXPIRED = "AUTHORIZATION_EXPIRED"; public const STATUS_SUCCEEDED = 'SUCCEEDED'; /** @@ -64,6 +66,9 @@ class Method extends Adapter /** @var string */ private $title; + + /** @var string */ + private $captureType; /** @var array */ private $limits; /** @var StoreManagerInterface */ @@ -84,6 +89,7 @@ class Method extends Adapter * @param string $infoBlockType * @param StoreManagerInterface $storeManager * @param LoggerInterface|RvvupLog $logger // Set via di.xml + * @param string $captureType * @param CommandPoolInterface|null $commandPool * @param ValidatorPoolInterface|null $validatorPool * @param CommandManagerInterface|null $commandExecutor @@ -99,6 +105,7 @@ public function __construct( string $infoBlockType, StoreManagerInterface $storeManager, LoggerInterface $logger, + string $captureType = '', CommandPoolInterface $commandPool = null, ValidatorPoolInterface $validatorPool = null, CommandManagerInterface $commandExecutor = null, @@ -119,6 +126,7 @@ public function __construct( $this->title = $title; $this->limits = $limits; + $this->captureType = $captureType; $this->storeManager = $storeManager; $this->logger = $logger; } @@ -178,4 +186,12 @@ public function getMaxOrderTotal(string $currencyCode): ?string { return $this->limits[$currencyCode]['max'] ?? null; } + + /** + * @return string + */ + public function getCaptureType(): string + { + return $this->captureType; + } } diff --git a/Model/Config.php b/Model/Config.php index f4d079bb..2cbf7fbe 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -2,15 +2,16 @@ namespace Rvvup\Payments\Model; -use Exception; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use stdClass; class Config implements ConfigInterface { /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ private $scopeConfig; @@ -20,12 +21,20 @@ class Config implements ConfigInterface private $jwt; /** - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @return void + * @var StoreManagerInterface */ - public function __construct(ScopeConfigInterface $scopeConfig) - { + private $storeManager; + + /** + * @param ScopeConfigInterface $scopeConfig + * @param StoreManagerInterface $storeManager + */ + public function __construct( + ScopeConfigInterface $scopeConfig, + StoreManagerInterface $storeManager + ) { $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; } /** @@ -37,11 +46,11 @@ public function __construct(ScopeConfigInterface $scopeConfig) */ public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool { - if (!$this->getActiveConfig($scopeType, $scopeCode)) { + if (!$this->getActiveConfig($scopeType)) { return false; } - $jwt = $this->getJwt($scopeType, $scopeCode); + $jwt = $this->getJwt($scopeType); return (bool)$jwt; } @@ -49,11 +58,11 @@ public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE, string * Get the active value from the config. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * @return bool */ - public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool + public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE): bool { + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return (bool) $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_ACTIVE, $scopeType, $scopeCode); } @@ -61,11 +70,12 @@ public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE, * Get the JWT value from the config. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return string|null */ - public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): ?string + public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE): ?string { + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; + $value = $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_JWT, $scopeType, $scopeCode); if ($value === null) { @@ -90,12 +100,11 @@ public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE, st * Get the endpoint URL. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * @return string */ - public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string + public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE): string { - $jwt = $this->getJwt($scopeType, $scopeCode); + $jwt = $this->getJwt($scopeType); return $jwt === null ? '' : (string) $jwt->aud; } @@ -104,12 +113,11 @@ public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE, str * Get the Merchant ID. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * @return string */ - public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string + public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE): string { - $jwt = $this->getJwt($scopeType, $scopeCode); + $jwt = $this->getJwt($scopeType); return $jwt === null ? '' : (string) $jwt->merchantId; } @@ -118,12 +126,11 @@ public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE, s * Get the Authorization Token. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * @return string */ - public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string + public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE): string { - $jwt = $this->getJwt($scopeType, $scopeCode); + $jwt = $this->getJwt($scopeType); if ($jwt === null) { return ''; @@ -136,11 +143,11 @@ public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE, st * Check whether debug mode is enabled. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * @return bool */ - public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool + public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE): bool { + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return (bool) $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_DEBUG, $scopeType, $scopeCode); } @@ -148,14 +155,13 @@ public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE, * Get a standard class by decoding the config JWT. * * @param string $scopeType - * @param string|null $scopeCode The store's code or ID as a string * * @return \stdClass|null */ - private function getJwt(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): ?stdClass + private function getJwt(string $scopeType = ScopeInterface::SCOPE_STORE): ?stdClass { - if (!$this->jwt || $scopeType !== ScopeInterface::SCOPE_STORE || $scopeCode !== null) { - $jwt = $this->getJwtConfig($scopeType, $scopeCode); + if (!$this->jwt) { + $jwt = $this->getJwtConfig($scopeType); if ($jwt === null) { $this->jwt = null; @@ -190,24 +196,23 @@ public function getPaypalBlockStyling(string $config): string public function getPayPalBlockConfig( string $config, - string $scopeType = ScopeInterface::SCOPE_STORE, - string $scopeCode = null + string $scopeType = ScopeInterface::SCOPE_STORE ): string { - $config = self::RVVUP_CONFIG . self::XML_PATH_PAYPAL_BLOCK . $config; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return $this->scopeConfig->getValue($config, $scopeType, $scopeCode); } /** * @param string $scopeType - * @param string|null $scopeCode * @return bool + * @throws NoSuchEntityException */ public function getValidProductTypes( - string $scopeType = ScopeInterface::SCOPE_STORE, - string $scopeCode = null + string $scopeType = ScopeInterface::SCOPE_STORE ): array { + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; $path = self::RVVUP_CONFIG . self::PRODUCT_RESTRICTIONS . self::XML_PATH_PRODUCT_TYPES_ENABLED; $types = $this->scopeConfig->getValue($path, $scopeType, $scopeCode); return explode(',', $types); diff --git a/Model/ConfigInterface.php b/Model/ConfigInterface.php index cb63c851..1a0c6fe4 100644 --- a/Model/ConfigInterface.php +++ b/Model/ConfigInterface.php @@ -25,64 +25,57 @@ interface ConfigInterface * Validate whether Rvvup module & payment methods are active. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return bool */ - public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool; + public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE): bool; /** * Get the active value from the config. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return bool */ - public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool; + public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE): bool; /** * Get the JWT value from the config. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return string|null */ - public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): ?string; + public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE): ?string; /** * Get the endpoint URL. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return string */ - public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string; + public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE): string; /** * Get the Merchant ID. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return string */ - public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string; + public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE): string; /** * Get the Authorization Token. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return string */ - public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string; + public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE): string; /** * Check whether debug mode is enabled. * * @param string $scopeType - * @param string|null $scopeCode The store's code or storeId as a string * @return bool */ - public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): bool; + public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE): bool; /** * Get style for paypal button @@ -94,11 +87,9 @@ public function getPaypalBlockStyling(string $config): string; /** * Get valid product types * @param string $scopeType - * @param string|null $scopeCode * @return array */ public function getValidProductTypes( - string $scopeType = ScopeInterface::SCOPE_STORE, - string $scopeCode = null + string $scopeType = ScopeInterface::SCOPE_STORE ): array; } diff --git a/Model/ProcessOrder/Processing.php b/Model/ProcessOrder/Processing.php index 564cfdd0..5391ddfc 100644 --- a/Model/ProcessOrder/Processing.php +++ b/Model/ProcessOrder/Processing.php @@ -13,6 +13,7 @@ use Rvvup\Payments\Controller\Redirect\In; use Rvvup\Payments\Exception\PaymentValidationException; use Rvvup\Payments\Gateway\Method; +use Magento\Framework\Stdlib\DateTime\DateTime; class Processing implements ProcessorInterface { @@ -27,23 +28,28 @@ class Processing implements ProcessorInterface /** @var LoggerInterface|RvvupLog */ private $logger; + /** @var DateTime */ + private $dateTime; + /** * @param EventManager $eventManager * @param OrderRepositoryInterface $orderRepository * @param ProcessOrderResultInterfaceFactory $processOrderResultFactory * @param LoggerInterface $logger - * @return void + * @param DateTime $dateTime */ public function __construct( EventManager $eventManager, OrderRepositoryInterface $orderRepository, ProcessOrderResultInterfaceFactory $processOrderResultFactory, - LoggerInterface $logger + LoggerInterface $logger, + DateTime $dateTime ) { $this->eventManager = $eventManager; $this->orderRepository = $orderRepository; $this->processOrderResultFactory = $processOrderResultFactory; $this->logger = $logger; + $this->dateTime = $dateTime; } /** @@ -71,10 +77,26 @@ public function execute(OrderInterface $order, array $rvvupData): ProcessOrderRe $order = $this->changeNewOrderStatus($order); + $eventMessage = 'Rvvup Payment is being processed.'; + + $payment = $rvvupData['payments'][0]; + if ($this->inAuthorizedManualPayment($payment)) { + $formattedExpirationDate = $this->dateTime->date( + "jS M Y H:i:s T", + strtotime($payment["authorizationExpiresAt"]) + ); + + $eventMessage = "Payment authorization expires at " . + $formattedExpirationDate . + ". Please navigate to the Rvvup dashboard to manually capture the payment. " . + "When the authorization expires, the order will be cancelled " . + "and the funds will be returned to the customer."; + } + $this->eventManager->dispatch('rvvup_payments_process_order_processing_after', [ 'payment_process_type' => self::TYPE, 'payment_process_result' => true, - 'event_message' => 'Rvvup Payment is being processed.', + 'event_message' => $eventMessage, 'order_id' => $order->getEntityId(), 'rvvup_id' => $rvvupData['id'] ?? null, 'original_order_state' => $originalOrderState, @@ -124,4 +146,11 @@ private function changeNewOrderStatus(OrderInterface $order): OrderInterface return $this->orderRepository->save($order); } + + private function inAuthorizedManualPayment(array $payment): bool + { + return isset($payment["authorizationExpiresAt"]) && + $payment["captureType"] === "MANUAL" && + $payment['status'] == Method::STATUS_AUTHORIZED; + } } diff --git a/Model/Queue/Handler/Handler.php b/Model/Queue/Handler/Handler.php index 52ceb2cb..70f3d313 100644 --- a/Model/Queue/Handler/Handler.php +++ b/Model/Queue/Handler/Handler.php @@ -69,17 +69,6 @@ public function execute(int $id) try { $webhook = $this->webhookRepository->getById($id); $payload = $this->serializer->unserialize($webhook->getPayload()); - // Ensure required params are present - - // Ensure configured merchant_id matches request - if ($payload['merchant_id'] !== $this->config->getMerchantId()) { - /** - * The configuration in Magento is different from the webhook. We don't want Rvvup's backend to - * continually make repeated calls so return a 200 and log the issue. - */ - $this->logger->warning("`merchant_id` from webhook does not match configuration"); - return; - } $rvvupOrderId = $payload['order_id']; diff --git a/Model/SessionMessagesGet.php b/Model/SessionMessagesGet.php index f6f51152..6387374d 100644 --- a/Model/SessionMessagesGet.php +++ b/Model/SessionMessagesGet.php @@ -5,12 +5,8 @@ namespace Rvvup\Payments\Model; use LogicException; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\View\Element\Message\InterpretationStrategyInterface; -use Magento\Store\Api\Data\StoreInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; use Rvvup\Payments\Api\Data\SessionMessageInterface; use Rvvup\Payments\Api\Data\SessionMessageInterfaceFactory; @@ -19,57 +15,49 @@ class SessionMessagesGet implements SessionMessagesGetInterface { /** - * @var \Magento\Framework\Message\ManagerInterface + * @var ManagerInterface */ private $messageManager; /** - * @var \Magento\Framework\View\Element\Message\InterpretationStrategyInterface + * @var InterpretationStrategyInterface */ private $messageInterpretationStrategy; /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - private $storeManager; - - /** - * @var \Rvvup\Payments\Api\Data\SessionMessageInterfaceFactory + * @var SessionMessageInterfaceFactory */ private $sessionMessageFactory; /** - * @var \Rvvup\Payments\Model\ConfigInterface + * @var ConfigInterface */ private $config; /** * Set via di.xml * - * @var \Psr\Log\LoggerInterface|RvvupLog + * @var LoggerInterface|RvvupLog */ private $logger; /** - * @param \Magento\Framework\Message\ManagerInterface $messageManager - * @param \Magento\Framework\View\Element\Message\InterpretationStrategyInterface $messageInterpretationStrategy - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Rvvup\Payments\Api\Data\SessionMessageInterfaceFactory $sessionMessageFactory - * @param \Rvvup\Payments\Model\ConfigInterface $config - * @param \Psr\Log\LoggerInterface $logger + * @param ManagerInterface $messageManager + * @param InterpretationStrategyInterface $messageInterpretationStrategy + * @param SessionMessageInterfaceFactory $sessionMessageFactory + * @param ConfigInterface $config + * @param LoggerInterface $logger * @return void */ public function __construct( ManagerInterface $messageManager, InterpretationStrategyInterface $messageInterpretationStrategy, - StoreManagerInterface $storeManager, SessionMessageInterfaceFactory $sessionMessageFactory, ConfigInterface $config, LoggerInterface $logger ) { $this->messageManager = $messageManager; $this->messageInterpretationStrategy = $messageInterpretationStrategy; - $this->storeManager = $storeManager; $this->sessionMessageFactory = $sessionMessageFactory; $this->config = $config; $this->logger = $logger; @@ -78,18 +66,14 @@ public function __construct( /** * Get the Rvvup Payments session messages. * - * @return \Rvvup\Payments\Api\Data\SessionMessageInterface[] + * @return SessionMessageInterface[] */ public function execute(): array { $messages = []; - $store = $this->getStore(); // If module not active for store, return empty array. - if (!$this->config->getActiveConfig( - ScopeInterface::SCOPE_STORE, - $store === null ? null : $store->getCode() - )) { + if (!$this->config->getActiveConfig()) { return $messages; } @@ -103,17 +87,14 @@ public function execute(): array foreach ($messageCollection->getItems() as $message) { try { - /** @var \Rvvup\Payments\Api\Data\SessionMessageInterface $sessionMessage */ + /** @var SessionMessageInterface $sessionMessage */ $sessionMessage = $this->sessionMessageFactory->create(); $sessionMessage->setType($message->getType()); $sessionMessage->setText($this->messageInterpretationStrategy->interpret($message)); $messages[] = $sessionMessage; } catch (LogicException $ex) { - if (!$this->config->isDebugEnabled( - ScopeInterface::SCOPE_STORE, - $store === null ? null : $store->getCode() - )) { + if (!$this->config->isDebugEnabled()) { continue; } @@ -123,18 +104,4 @@ public function execute(): array return $messages; } - - /** - * Get current store. - * - * @return \Magento\Store\Api\Data\StoreInterface|null - */ - private function getStore(): ?StoreInterface - { - try { - return $this->storeManager->getStore(); - } catch (LocalizedException $ex) { - return null; - } - } } diff --git a/Observer/ConfigSaveObserver.php b/Observer/ConfigSaveObserver.php index c25f5b32..aa16a9c0 100644 --- a/Observer/ConfigSaveObserver.php +++ b/Observer/ConfigSaveObserver.php @@ -3,14 +3,13 @@ namespace Rvvup\Payments\Observer; use Exception; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\State; use Magento\Framework\Event; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\UrlInterface; -use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface; use Rvvup\Payments\Model\ConfigInterface; use Rvvup\Payments\Model\SdkProxy; @@ -20,6 +19,7 @@ class ConfigSaveObserver implements ObserverInterface /** @var State */ private $appState; /** @var UrlInterface */ + private $urlBuilder; /** @@ -29,6 +29,7 @@ class ConfigSaveObserver implements ObserverInterface /** @var SdkProxy */ private $sdkProxy; + /** @var ManagerInterface */ private $messageManager; @@ -39,14 +40,19 @@ class ConfigSaveObserver implements ObserverInterface */ private $logger; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * @param State $appState * @param UrlInterface $urlBuilder - * @param \Rvvup\Payments\Model\ConfigInterface $config + * @param ConfigInterface $config * @param SdkProxy $sdkProxy * @param ManagerInterface $messageManager - * @param \Psr\Log\LoggerInterface $logger - * @return void + * @param StoreManagerInterface $storeManager + * @param LoggerInterface $logger */ public function __construct( State $appState, @@ -54,6 +60,7 @@ public function __construct( ConfigInterface $config, SdkProxy $sdkProxy, ManagerInterface $messageManager, + StoreManagerInterface $storeManager, LoggerInterface $logger ) { $this->appState = $appState; @@ -61,6 +68,7 @@ public function __construct( $this->config = $config; $this->sdkProxy = $sdkProxy; $this->messageManager = $messageManager; + $this->storeManager = $storeManager; $this->logger = $logger; } @@ -100,11 +108,10 @@ private function sendApiDataOnMethodDisabled(Event $event): void )) { return; } - - $scope = $this->mapScope($event); + $scope = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; // No action if it was activated. - if ($this->config->getActiveConfig($scope['scopeType'], $scope['scopeCode']) === true) { + if ($this->config->getActiveConfig() === true) { return; } @@ -113,44 +120,10 @@ private function sendApiDataOnMethodDisabled(Event $event): void $this->sdkProxy->createEvent( 'MERCHANT_PLUGIN_DEACTIVATED', 'Magento Payment method deactivated', - $scope + [$scope] ); } catch (Exception $ex) { $this->logger->error('Failed to send create event API request to Rvvup with message: ' . $ex->getMessage()); } } - - /** - * Get the relevant scope from the event data - * - * @param \Magento\Framework\Event $event - * @return array - */ - private function mapScope(Event $event): array - { - $website = is_string($event->getData('website')) ? $event->getData('website') : ''; - $store = is_string($event->getData('store')) ? $event->getData('store') : ''; - - // If no value for either website or store, return default scope config. - if (empty($website) && empty($store)) { - return [ - 'scopeType' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 'scopeCode' => null - ]; - } - - // Otherwise, it's either website (if store is empty) - if (empty($store)) { - return [ - 'scopeType' => ScopeInterface::SCOPE_WEBSITE, - 'scopeCode' => $website - ]; - } - - // Or store if not empty. - return [ - 'scopeType' => ScopeInterface::SCOPE_STORE, - 'scopeCode' => $store - ]; - } } diff --git a/Observer/Model/ProcessOrder/AddOrderHistoryCommentObserver.php b/Observer/Model/ProcessOrder/AddOrderHistoryCommentObserver.php index 322b6b2b..d92fb778 100644 --- a/Observer/Model/ProcessOrder/AddOrderHistoryCommentObserver.php +++ b/Observer/Model/ProcessOrder/AddOrderHistoryCommentObserver.php @@ -98,7 +98,7 @@ private function addEventMessageComment(Observer $observer, OrderInterface $orde // Prepare comment. $comment = is_string($eventMessage) ? trim($eventMessage) : 'Rvvup Order Process was performed.'; - $comment .= $rvvupId !== null ? ' Rvvup Payment ID: ' . $rvvupId : ' Rvvup Payment ID: N/A'; + $comment .= $rvvupId !== null ? ' Rvvup Order ID: ' . $rvvupId : ' Rvvup Payment ID: N/A'; $orderStatusHistory = $this->createNewOrderStatusHistoryObject($order); $orderStatusHistory->setComment($comment); diff --git a/Plugin/JsLayout.php b/Plugin/JsLayout.php index 5ceb2f02..1cca2007 100644 --- a/Plugin/JsLayout.php +++ b/Plugin/JsLayout.php @@ -57,10 +57,7 @@ public function __construct( */ public function beforeProcess(LayoutProcessor $subject, $jsLayout): array { - if ($this->config->isActive( - ScopeInterface::SCOPE_STORE, - $this->getStore() === null ? null : $this->getStore()->getCode() - )) { + if ($this->config->isActive()) { // Add payment methods. $renders = &$jsLayout["components"]["checkout"]["children"]["steps"]["children"]["billing-step"]["children"] ["payment"]["children"]["renders"]["children"]; diff --git a/Plugin/LoadMethodInstances.php b/Plugin/LoadMethodInstances.php index 2ba66d39..e3848177 100644 --- a/Plugin/LoadMethodInstances.php +++ b/Plugin/LoadMethodInstances.php @@ -67,24 +67,20 @@ public function aroundGetMethodInstance(\Magento\Payment\Helper\Data $subject, c if (isset($this->processed[$code])) { $method = $this->processed[$code]; - } else { - $method = [ - 'code' => $code - ]; + /** @var Method $instance */ + $instance = $this->methodFactory->create( + 'RvvupFacade', + [ + 'code' => $code, + 'title' => $method['title'] ?? 'Rvvup', + 'summary_url' => $method['summaryUrl'] ?? '', + 'logo_url' => $method['logoUrl'] ?? '', + 'limits' => $method['limits'] ?? null, + 'captureType' => $method['captureType'] ?? '', + ] + ); + return $instance; } - - /** @var Method $instance */ - $instance = $this->methodFactory->create( - 'RvvupFacade', - [ - 'code' => $code, - 'title' => $method['title'] ?? 'Rvvup', - 'summary_url' => $method['summaryUrl'] ?? '', - 'logo_url' => $method['logoUrl'] ?? '', - 'limits' => $method['limits'] ?? null, - ] - ); - return $instance; } return $proceed($code); } diff --git a/Test/Unit/Model/Config.php b/Test/Unit/Model/Config.php index 7ab89921..d793a1c9 100644 --- a/Test/Unit/Model/Config.php +++ b/Test/Unit/Model/Config.php @@ -6,6 +6,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use PHPUnit\Framework\TestCase; use Rvvup\Payments\Model\ConfigInterface; @@ -14,6 +15,9 @@ class Config extends TestCase /** @var ScopeConfigInterface */ private $scopeConfigMock; + /** @var StoreManagerInterface */ + private $storeManagerMock; + /** @var \Rvvup\Payments\Model\Config */ private $config; @@ -22,7 +26,11 @@ protected function setUp(): void $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->disableOriginalConstructor()->getMock(); - $this->config = new \Rvvup\Payments\Model\Config($this->scopeConfigMock); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->disableOriginalConstructor()->getMock(); + $this->storeManagerMock->method('getStore')->willReturn(null); + + $this->config = new \Rvvup\Payments\Model\Config($this->scopeConfigMock, $this->storeManagerMock); } public function testPaypalBlockDefaultStyling() diff --git a/Traits/LoadMethods.php b/Traits/LoadMethods.php index 202e8f1b..73ee9227 100644 --- a/Traits/LoadMethods.php +++ b/Traits/LoadMethods.php @@ -23,6 +23,7 @@ protected function processMethods(array $methods): array $processed[$code]['summaryUrl'] = $method['summaryUrl']; $processed[$code]['logoUrl'] = $method['logoUrl'] ?? ''; $processed[$code]['limits'] = $this->processLimits($method['limits']['total'] ?? []); + $processed[$code]['captureType'] = $method['captureType'] ?? ''; } $this->processed = $processed; } diff --git a/etc/di.xml b/etc/di.xml index ee2ca570..e37adfb6 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -174,9 +174,6 @@ - - - @@ -283,8 +280,10 @@ Rvvup\Payments\Model\ProcessOrder\Cancel Rvvup\Payments\Model\ProcessOrder\Cancel Rvvup\Payments\Model\ProcessOrder\Cancel + Rvvup\Payments\Model\ProcessOrder\Cancel Rvvup\Payments\Model\ProcessOrder\Processing Rvvup\Payments\Model\ProcessOrder\Processing + Rvvup\Payments\Model\ProcessOrder\Processing Rvvup\Payments\Model\ProcessOrder\Complete Rvvup\Payments\Model\ProcessOrder\UpdateOrder diff --git a/view/frontend/web/js/view/payment/messages.js b/view/frontend/web/js/view/payment/messages.js index df76c1a3..14e608dd 100644 --- a/view/frontend/web/js/view/payment/messages.js +++ b/view/frontend/web/js/view/payment/messages.js @@ -5,7 +5,8 @@ define([ 'mage/storage', 'mage/translate', 'Magento_Checkout/js/model/url-builder', - 'Magento_Ui/js/model/messageList' + 'Magento_Ui/js/model/messageList', + 'domReady!', ], function (Component, $, _, storage, $t, urlBuilder, globalMessages) { return Component.extend({ /**