58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\OceanpaymentKlarna\Model;
|
|
|
|
use Magento\Framework\DataObject;
|
|
use Magento\Payment\Model\Method\AbstractMethod;
|
|
use Magento\Quote\Api\Data\CartInterface;
|
|
use Magento\Sales\Model\Order;
|
|
|
|
class PaymentMethod extends AbstractMethod
|
|
{
|
|
protected $_code = Config::METHOD_CODE;
|
|
protected $_isGateway = true;
|
|
protected $_isOffline = false;
|
|
protected $_canUseInternal = false;
|
|
protected $_canUseCheckout = true;
|
|
protected $_isInitializeNeeded = true;
|
|
protected $_debugReplacePrivateDataKeys = [
|
|
'sandbox_account',
|
|
'sandbox_terminal',
|
|
'sandbox_secure_code',
|
|
'sandbox_public_key',
|
|
'production_account',
|
|
'production_terminal',
|
|
'production_secure_code',
|
|
'production_public_key',
|
|
'signValue',
|
|
'itemList',
|
|
];
|
|
|
|
public function initialize($paymentAction, $stateObject): self
|
|
{
|
|
if ($stateObject instanceof DataObject) {
|
|
$stateObject->setState(Order::STATE_PENDING_PAYMENT);
|
|
$stateObject->setStatus(
|
|
$this->getConfigData('new_order_status') ?: Order::STATE_PENDING_PAYMENT
|
|
);
|
|
$stateObject->setIsNotified(false);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isAvailable(?CartInterface $quote = null): bool
|
|
{
|
|
if (!parent::isAvailable($quote)) {
|
|
return false;
|
|
}
|
|
|
|
$prefix = $this->getConfigData('sandbox') ? 'sandbox_' : 'production_';
|
|
|
|
return trim((string)$this->getConfigData($prefix . 'account')) !== ''
|
|
&& trim((string)$this->getConfigData($prefix . 'terminal')) !== ''
|
|
&& trim((string)$this->getConfigData($prefix . 'secure_code')) !== '';
|
|
}
|
|
}
|