Skip to content

Commit

Permalink
Release version 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clearpayplugins committed Jan 12, 2022
1 parent e7d9866 commit eba45cb
Show file tree
Hide file tree
Showing 252 changed files with 8,656 additions and 9,038 deletions.
40 changes: 40 additions & 0 deletions Api/CheckoutManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types=1);

namespace Clearpay\Clearpay\Api;

/**
* Interface for managing Clearpay Checkout
* @api
*/
interface CheckoutManagementInterface
{
/**
* @param string $cartId
* @param \Clearpay\Clearpay\Api\Data\RedirectPathInterface $redirectPath
*
* @return \Clearpay\Clearpay\Api\Data\CheckoutInterface
*
* @throws \Magento\Framework\Validation\ValidationException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Payment\Gateway\Command\CommandException
*/
public function create(
string $cartId,
\Clearpay\Clearpay\Api\Data\RedirectPathInterface $redirectPath
): \Clearpay\Clearpay\Api\Data\CheckoutInterface;

/**
* @param string $cartId
* @param string $popupOriginUrl
*
* @return \Clearpay\Clearpay\Api\Data\CheckoutInterface
*
* @throws \Magento\Framework\Validation\ValidationException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Payment\Gateway\Command\CommandException
*/
public function createExpress(
string $cartId,
string $popupOriginUrl
): \Clearpay\Clearpay\Api\Data\CheckoutInterface;
}
51 changes: 51 additions & 0 deletions Api/Data/CheckoutInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);

namespace Clearpay\Clearpay\Api\Data;

/**
* Interface CheckoutInterface
* @api
*/
interface CheckoutInterface
{
/**#@+
* Checkout result keys
*/
const CLEARPAY_TOKEN = 'clearpay_token';
const CLEARPAY_AUTH_TOKEN_EXPIRES = 'clearpay_expires';
const CLEARPAY_REDIRECT_CHECKOUT_URL = 'clearpay_redirectCheckoutUrl';
/**#@-*/

/**
* @param string $token
* @return static
*/
public function setClearpayToken(string $token): self;

/**
* @return string
*/
public function getClearpayToken(): string;

/**
* @param string $authTokenExpires
* @return static
*/
public function setClearpayAuthTokenExpires(string $authTokenExpires): self;

/**
* @return string
*/
public function getClearpayAuthTokenExpires(): string;

/**
* @param string $redirectCheckoutUrl
* @return static
*/
public function setClearpayRedirectCheckoutUrl(string $redirectCheckoutUrl): self;

/**
* @return string
*/
public function getClearpayRedirectCheckoutUrl(): string;
}
32 changes: 32 additions & 0 deletions Api/Data/RedirectPathInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Clearpay\Clearpay\Api\Data;

/**
* Interface RedirectPathInterface
* @api
*/
interface RedirectPathInterface
{
/**
* @param string $path
* @return static
*/
public function setConfirmPath(string $path): self;

/**
* @return string
*/
public function getConfirmPath(): string;

/**
* @param string $path
* @return static
*/
public function setCancelPath(string $path): self;

/**
* @return string
*/
public function getCancelPath(): string;
}
Original file line number Diff line number Diff line change
@@ -1,54 +1,36 @@
<?php
/**
* Magento 2 extensions for Clearpay Payment
*
* @author Clearpay
* @copyright 2016-2021 Clearpay https://www.clearpay.co.uk
*/

declare(strict_types=1);

namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Button;

class Update extends \Magento\Config\Block\System\Config\Form\Field
class LimitUpdate extends \Magento\Config\Block\System\Config\Form\Field
{
/** Variable update template */
const UPDATE_TEMPLATE = 'system/config/button/update.phtml';

/**
* Prepare layout to set template
*
* @return $this
*/
const TEMPLATE = 'Clearpay_Clearpay::system/config/button/update.phtml';

public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
/** @phpstan-ignore-next-line */
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/** @inheritDoc */
protected function _prepareLayout()
{
parent::_prepareLayout();

if (!$this->getTemplate()) {
$this->setTemplate(static::UPDATE_TEMPLATE);
$this->setTemplate(static::TEMPLATE);
}

return $this;
}

/**
* Rendering the element of button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Get HTML element to set variable for Ajax request
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
/** @inheritDoc */
public function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$originalData = $element->getOriginalData();
$originalData = $element->getData('original_data');
$this->addData(
[
'button_label' => __($originalData['button_label']),
Expand Down
46 changes: 46 additions & 0 deletions Block/Adminhtml/System/Config/Fieldset/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);

namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Fieldset;

class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
{
private \Magento\Payment\Model\MethodInterface $clearpay;
private \Clearpay\Clearpay\Model\Config $config;

public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\View\Helper\Js $jsHelper,
\Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer,
\Magento\Payment\Model\MethodInterface $clearpay,
\Clearpay\Clearpay\Model\Config $config,
array $data = []
) {
parent::__construct($context, $authSession, $jsHelper, $data, $secureRenderer);
$this->clearpay = $clearpay;
$this->config = $config;
}

public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element): string
{
$allowedMerchantCountries = explode(',', $this->clearpay->getConfigData('allowed_merchant_countries'));
if (in_array($this->getMerchantCountry(), $allowedMerchantCountries)) {
return parent::render($element);
}
return '';
}

private function getMerchantCountry(): ?string
{
/** @var \Magento\Config\Block\System\Config\Form $fieldSetForm */
$fieldSetForm = $this->getForm();
$scope = $fieldSetForm->getScope();
$scopeCode = $fieldSetForm->getScopeCode();

if ($countryCode = $this->getRequest()->getParam('paypal_country')) {
return $countryCode;
}

return $this->config->getMerchantCountry($scope, (int)$scopeCode);
}
}
21 changes: 12 additions & 9 deletions Block/Adminhtml/System/Config/Form/Field/Disable.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php
/**
* Magento 2 extensions for Clearpay Payment
*
* @author Clearpay
* @copyright 2016-2021 Clearpay https://www.Clearpay.com
*/
namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Form\Field;

use Magento\Framework\Data\Form\Element\AbstractElement;
declare(strict_types=1);

namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Form\Field;

class Disable extends \Magento\Config\Block\System\Config\Form\Field
{
protected function _getElementHtml(AbstractElement $element)
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
/** @phpstan-ignore-next-line */
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
/** @phpstan-ignore-next-line */
$element->setDisabled('disabled');
return $element->getElementHtml();
}
Expand Down
35 changes: 0 additions & 35 deletions Block/Adminhtml/System/Config/Form/Field/Label.php

This file was deleted.

33 changes: 33 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Form\Field;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\View\Helper\SecureHtmlRenderer;

class Version extends \Magento\Config\Block\System\Config\Form\Field
{
const MODULE_NAME = "Clearpay_Clearpay";

private \Magento\Framework\Module\ResourceInterface $resource;

public function __construct(
\Magento\Framework\Module\ResourceInterface $resource,
Context $context,
array $data = [],
?SecureHtmlRenderer $secureRenderer = null
) {
parent::__construct($context, $data, $secureRenderer);
$this->resource = $resource;
}

/**
* @inheritDoc
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return $this->resource->getDataVersion(self::MODULE_NAME) ?: "";
}
}
34 changes: 0 additions & 34 deletions Block/Adminhtml/System/Config/Form/Field/cbtLabel.php

This file was deleted.

Loading

0 comments on commit eba45cb

Please sign in to comment.