Skip to content

Commit

Permalink
Merge main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-onufriichuk committed Jan 3, 2024
2 parents 9975a6d + bd3ab2c commit b3c6330
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 182 deletions.
4 changes: 3 additions & 1 deletion Controller/Redirect/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
4 changes: 4 additions & 0 deletions Gateway/Command/CreatePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function execute(array $commandSubject)
]
];

if ($captureType = $payment->getMethodInstance()->getCaptureType()) {
$data['input']['captureType'] = $captureType;
}

return $this->sdkProxy->createPayment(
$data
);
Expand Down
16 changes: 16 additions & 0 deletions Gateway/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -64,6 +66,9 @@ class Method extends Adapter

/** @var string */
private $title;

/** @var string */
private $captureType;
/** @var array */
private $limits;
/** @var StoreManagerInterface */
Expand All @@ -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
Expand All @@ -99,6 +105,7 @@ public function __construct(
string $infoBlockType,
StoreManagerInterface $storeManager,
LoggerInterface $logger,
string $captureType = '',
CommandPoolInterface $commandPool = null,
ValidatorPoolInterface $validatorPool = null,
CommandManagerInterface $commandExecutor = null,
Expand All @@ -119,6 +126,7 @@ public function __construct(

$this->title = $title;
$this->limits = $limits;
$this->captureType = $captureType;
$this->storeManager = $storeManager;
$this->logger = $logger;
}
Expand Down Expand Up @@ -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;
}
}
71 changes: 38 additions & 33 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand All @@ -37,35 +46,36 @@ 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;
}

/**
* 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);
}

/**
* 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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 '';
Expand All @@ -136,26 +143,25 @@ 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);
}

/**
* 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;
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 8 additions & 17 deletions Model/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Loading

0 comments on commit b3c6330

Please sign in to comment.