Skip to content

Commit

Permalink
Merge pull request #15 from credi2/feature/release-2.4.4
Browse files Browse the repository at this point in the history
php 8.1 support
  • Loading branch information
thaitzer committed Nov 28, 2022
2 parents 413b539 + 4dfc578 commit 81febc0
Show file tree
Hide file tree
Showing 34 changed files with 180 additions and 219 deletions.
6 changes: 4 additions & 2 deletions Api/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

namespace LimeSoda\Cashpresso\Api;

use PHPUnit\Exception;

class Account extends Base
{
const METHOD_TARGET_ACCOUNTS = 'partner/targetAccounts';

protected $postData;

public function getContent()
public function getContent(): array
{
$data = [
'partnerApiKey' => $this->getPartnerApiKey(),
Expand Down Expand Up @@ -57,4 +59,4 @@ public function getTargetAccounts()

throw new \DomainException(__('cashpresso target account request error: %1', $response->getMessage()));
}
}
}
4 changes: 2 additions & 2 deletions Api/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct(Config $config,
$this->messageManager = $context->getMessageManager();
}

abstract function getContent();
abstract function getContent(): array;

/**
* @return Config
Expand All @@ -110,7 +110,7 @@ protected function getConfig()
protected function handleRespond($respond)
{
if (empty($respond['success'])) {
$errors = isset($respond['errors']) ? $respond['errors'] : [$respond['error']];
$errors = $respond['errors'] ?? [$respond['error']];

foreach ($errors as $error) {
if (!empty($error['type']) && $this->handleError($error['type'])) {
Expand Down
25 changes: 5 additions & 20 deletions Api/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ public function setVerificationHash($data)

$targetAccountId = '';

if (!empty($account) && $account != CashpressoConfig::XML_RELOAD_FLAG) {
if (!empty($account) && $account !== CashpressoConfig::XML_RELOAD_FLAG) {
$data['targetAccountId'] = $account;

if ($account != CashpressoConfig::XML_RELOAD_FLAG) {
$targetAccountId = $account;
}
$targetAccountId = $account;
}

$data['verificationHash'] = hash('sha512', $this->getHash($data['amount'], $this->order->getIncrementId(), $targetAccountId));

return $data;
}

public function getContent()
public function getContent(): array
{
$order = $this->order;
$price = $this->priceCurrency->round($order->getGrandTotal());
Expand Down Expand Up @@ -85,18 +82,6 @@ public function getContent()
$data['deliveryAddress'] = $shippingAddress;
}

$items = $order->getAllItems();

$cart = [];

/** @var Mage_Sales_Model_Order_Item $item */
foreach ($items as $item) {
$cart[] = [
'description' => $item->getName(),
'amount' => $item->getQtyOrdered()
];
}

$this->postData = $data;

return $data;
Expand All @@ -109,7 +94,7 @@ public function getContent()
* @return string
* @throws \LimeSoda\Cashpresso\Gateway\Exception
*/
public function getHash($amount, $bankUsage, $targetAccountId = '')
public function getHash($amount, $bankUsage, $targetAccountId = ''): string
{
return $this->getSecretKey() . ';' . ($amount * 100) . ';' . $this->getConfig()->getInterestFreeDay() . ';' . $bankUsage . ';' . $targetAccountId;
}
Expand Down Expand Up @@ -155,4 +140,4 @@ public function sendOrder($order)

throw new \DomainException(__('cashpresso order request error: %1', $response->getMessage()));
}
}
}
4 changes: 2 additions & 2 deletions Api/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function getPartnerInfo()
/**
* @return array
*/
public function getContent()
public function getContent(): array
{
return ['partnerApiKey' => $this->getPartnerApiKey()];
}
}
}
8 changes: 4 additions & 4 deletions Block/Adminhtml/System/Config/Form/Field/Information.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use LimeSoda\Cashpresso\Gateway\Config;
use LimeSoda\Cashpresso\Helper\Store;
use \Magento\Framework\App\RequestInterface;

class Information extends \Magento\Config\Block\System\Config\Form\Field
{
protected $csConfig;

protected $request;
protected $store;
protected Config $csConfig;
protected RequestInterface $request;
protected Store $store;

public function __construct(\Magento\Backend\Block\Template\Context $context,
Config $config,
Expand Down
4 changes: 2 additions & 2 deletions Block/Frontend/Product/RedirectFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class RedirectFlag extends Template
{
protected $config;
protected Config $config;

/**
* RedirectFlag constructor.
Expand Down Expand Up @@ -38,4 +38,4 @@ protected function _toHtml()

return '';
}
}
}
20 changes: 10 additions & 10 deletions Block/Frontend/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

class Script extends Template
{
protected $config;
protected Gateway\Config $config;

protected $available;
protected Gateway\Available $available;

protected $checkoutSession;
protected Session $checkoutSession;

protected $customer;
protected CustomerSession $customer;

protected $store;
protected Store $store;

protected $type;

protected $priceCurrency;
protected PriceCurrencyInterface $priceCurrency;

protected $registry;
protected Registry $registry;

/**
* Script constructor.
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getLocale()
*/
public function getGrandTotal()
{
return $this->priceCurrency->round($this->checkoutSession->getQuote()->getGrandTotal());
return $this->priceCurrency->round($this->checkoutSession->getQuote()->getBaseGrandTotal());
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ private function getProduct()
{
$product = $this->registry->registry('product');

return $product && $product->getId() ? true : false;
return $product && $product->getId();
}

protected function _toHtml()
Expand All @@ -120,4 +120,4 @@ public function getCheckoutCallbackStatus()
{
return $this->config->showCheckoutButton() && $this->getProduct();
}
}
}
16 changes: 4 additions & 12 deletions Catalog/Pricing/Render/CSPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class CSPriceBox extends FinalPriceBox
{
protected $available;
protected Gateway\Available $available;

protected $config;
protected Gateway\Config $config;

/**
* CSPriceBox constructor.
Expand All @@ -34,12 +34,9 @@ public function __construct(
Gateway\Available $available,
Gateway\Config $config,
array $data = []
)
{
) {
$this->config = $config;

$this->available = $available;

parent::__construct($context, $saleableItem, $price, $rendererPool, $data);
}

Expand Down Expand Up @@ -78,11 +75,6 @@ public function getCsFinalPrice()
if ($salableItem = $this->getSaleableItem()) {
if ($salableItem->getTypeId()) {
switch ($salableItem->getTypeId()) {
case 'configurable':
$finalPriceModel = $this->getPriceType('final_price');

$price = $finalPriceModel->getAmount()->getValue();
break;
case 'grouped':
$minProduct = $this->getSaleableItem()
->getPriceInfo()
Expand All @@ -106,4 +98,4 @@ public function getCsFinalPrice()

return $price;
}
}
}
36 changes: 21 additions & 15 deletions Controller/Api/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@

namespace LimeSoda\Cashpresso\Controller\Api;

use LimeSoda\Cashpresso\Logger\Logger;
use Magento\Backend\App\Action\Context;
use LimeSoda\Cashpresso\Gateway\Config;
use LimeSoda\Cashpresso\Model\OrderStatus;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\Controller\Result\ForwardFactory;

class Callback extends \Magento\Framework\App\Action\Action
{
protected $logger;
protected Logger $logger;

protected $context;
protected Context $context;

protected $orderStatus;
protected OrderStatus $orderStatus;

protected $cacheTypeListInterface;
protected TypeListInterface $cacheTypeListInterface;

protected $resultForwardFactory;
protected ForwardFactory $resultForwardFactory;

protected $config;
protected Config $config;

public function __construct(
\Magento\Backend\App\Action\Context $context,
\LimeSoda\Cashpresso\Gateway\Config $config,
\LimeSoda\Cashpresso\Logger\Logger $logger,
\LimeSoda\Cashpresso\Model\OrderStatus $orderStatus,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeListInterface,
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
)
{
Context $context,
Config $config,
Logger $logger,
OrderStatus $orderStatus,
TypeListInterface $cacheTypeListInterface,
ForwardFactory $resultForwardFactory
) {
$this->logger = $logger;

$this->context = $context;
Expand Down Expand Up @@ -62,4 +68,4 @@ public function execute()

return;
}
}
}
13 changes: 6 additions & 7 deletions Cron/PartnerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

namespace LimeSoda\Cashpresso\Cron;

use LimeSoda\Cashpresso\Model\PartnerInfo as PartnerInfoModel;

class PartnerInfo
{
protected $partnerInfo;
protected PartnerInfoModel $partnerInfo;

public function __construct(
\LimeSoda\Cashpresso\Model\PartnerInfo $partnerInfo
)
{
PartnerInfoModel $partnerInfo
) {
$this->partnerInfo = $partnerInfo;
}

public function execute()
{
$result = false;

$this->partnerInfo->generatePartnerInfo();

return $result;
}
}
}
24 changes: 9 additions & 15 deletions Gateway/Available.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Available
/**
* @var ValidatorPoolInterface
*/
protected $validatorPool;
protected ?ValidatorPoolInterface $validatorPool;

protected $registry;
protected Registry $registry;

protected $session;
protected Session $session;

protected $store;
protected Store $store;

public function __construct(
Config $config,
Expand All @@ -35,13 +35,9 @@ public function __construct(
)
{
$this->registry = $registry;

$this->validatorPool = $validatorPool;

$this->config = $config;

$this->session = $session;

$this->store = $storeHelper;
}

Expand Down Expand Up @@ -72,23 +68,21 @@ public function getValidatorPool()
protected function isProductTypeAllow()
{
if ($product = $this->getProduct()) {
return in_array($product->getTypeId(), ['virtual', 'downloadable', 'giftcard']) ? false : true;
return !in_array($product->getTypeId(), ['virtual', 'downloadable', 'giftcard'], true);
}

return true;
}

protected function checkCartItems()
protected function checkCartItems(): bool
{
$items = $this->session->getQuote()->getItems();

$status = true;

/** @var \Magento\Quote\Model\Quote\Item $item */
/** @var \Magento\Quote\Model\Quote\Item $item */
foreach ($items as $item) {
$status = in_array($item->getProduct()->getTypeId(), ['virtual', 'downloadable', 'giftcard']) ? false : true;

if (!$status){
if (in_array($item->getProduct()->getTypeId(), ['virtual', 'downloadable', 'giftcard'], true)){
$status = false;
break;
}
}
Expand Down
Loading

0 comments on commit 81febc0

Please sign in to comment.