Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions Block/Customer/CardRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Block\AbstractCardRenderer;
use PMNTS\Gateway\Helper\Data;

/**
* @api
Expand All @@ -15,55 +16,60 @@ class CardRenderer extends AbstractCardRenderer
* Can render specified token
*
* @param PaymentTokenInterface $token
* @return boolean
* @since 100.1.0
* @return bool
*/
public function canRender(PaymentTokenInterface $token)
public function canRender(PaymentTokenInterface $token): bool
{
return $token->getPaymentMethodCode() === \PMNTS\Gateway\Helper\Data::METHOD_CODE;
return $token->getPaymentMethodCode() === Data::METHOD_CODE;
}

/**
* Get Number Last 4 Digits
*
* @return string
* @since 100.1.0
*/
public function getNumberLast4Digits()
public function getNumberLast4Digits(): string
{
return $this->getTokenDetails()['maskedCC'];
return $this->getTokenDetails()['maskedCC'] ?? '';
}

/**
* Get expire data
*
* @return string
* @since 100.1.0
*/
public function getExpDate()
public function getExpDate(): string
{
return $this->getTokenDetails()['expirationDate'];
return $this->getTokenDetails()['expirationDate'] ?? '';
}

/**
* Get Icon url
*
* @return string
* @since 100.1.0
*/
public function getIconUrl()
public function getIconUrl(): string
{
return $this->getIconForType($this->getTokenDetails()['type'])['url'];
return $this->getIconForType($this->getTokenDetails()['type'])['url'] ?? '';
}

/**
* Get Icon height
*
* @return int
* @since 100.1.0
*/
public function getIconHeight()
public function getIconHeight(): int
{
return $this->getIconForType($this->getTokenDetails()['type'])['height'];
return $this->getIconForType($this->getTokenDetails()['type'])['height'] ?? 0;
}

/**
* Get Icon width
*
* @return int
* @since 100.1.0
*/
public function getIconWidth()
public function getIconWidth(): int
{
return $this->getIconForType($this->getTokenDetails()['type'])['width'];
return $this->getIconForType($this->getTokenDetails()['type'])['width'] ?? 0;
}
}
68 changes: 44 additions & 24 deletions Gateway/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
<?php
declare(strict_types=1);

namespace PMNTS\Gateway\Gateway;

abstract class AbstractCommand implements \Magento\Payment\Gateway\CommandInterface
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Payment\Gateway\CommandInterface;
use PMNTS\Gateway\Helper\Data;
use PMNTS\Gateway\Model\GatewayFactory;
use PMNTS\Gateway\Model\Gateway;
use Psr\Log\LoggerInterface;

abstract class AbstractCommand implements CommandInterface
{
/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/** @var \PMNTS\Gateway\Helper\Data */
/**
* @var Data
*/
protected $pmntsHelper;

/** @var \PMNTS\Gateway\Model\GatewayFactory */
/**
* @var GatewayFactory
*/
protected $gatewayFactory;

/** @var \Psr\Log\LoggerInterface */
/**
* @var LoggerInterface
*/
protected $logger;

/**
* AbstractCommand constructor.
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \PMNTS\Gateway\Helper\Data $pmntsHelper
* @param \PMNTS\Gateway\Model\GatewayFactory $gatewayFactory
* @param \Psr\Log\LoggerInterface $logger
*
* @param ScopeConfigInterface $scopeConfig
* @param Data $pmntsHelper
* @param GatewayFactory $gatewayFactory
* @param LoggerInterface $logger
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\PMNTS\Gateway\Helper\Data $pmntsHelper,
\PMNTS\Gateway\Model\GatewayFactory $gatewayFactory,
\Psr\Log\LoggerInterface $logger
ScopeConfigInterface $scopeConfig,
Data $pmntsHelper,
GatewayFactory $gatewayFactory,
LoggerInterface $logger
) {
$this->scopeConfig = $scopeConfig;
$this->pmntsHelper = $pmntsHelper;
Expand All @@ -36,33 +54,35 @@ public function __construct(
}

/**
* @param $storeId
* @return \Pmnts\Gateway\Model\Gateway
* Get Gateway
*
* @param string|int|null $storeId
* @return Gateway
*/
public function getGateway($storeId)
public function getGateway($storeId): Gateway
{
$username = $this->scopeConfig->getValue(
\PMNTS\Gateway\Helper\Data::CONFIG_PATH_PMNTS_USERNAME,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Data::CONFIG_PATH_PMNTS_USERNAME,
ScopeInterface::SCOPE_STORE,
$storeId
);

$token = $this->scopeConfig->getValue(
\PMNTS\Gateway\Helper\Data::CONFIG_PATH_PMNTS_TOKEN,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Data::CONFIG_PATH_PMNTS_TOKEN,
ScopeInterface::SCOPE_STORE,
$storeId
);

$sandbox = (bool)$this->scopeConfig->getValue(
\PMNTS\Gateway\Helper\Data::CONFIG_PATH_PMNTS_SANDBOX,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Data::CONFIG_PATH_PMNTS_SANDBOX,
ScopeInterface::SCOPE_STORE,
$storeId
);

return $this->gatewayFactory->create([
'username' => $username,
'token' => $token,
'test_mode' => $sandbox
'testMode' => $sandbox
]);
}
}
}
Loading