Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Initial release for Magento v2.4
Browse files Browse the repository at this point in the history
Publish initial version of the PGC plugin, targeting Magento v2.4
  • Loading branch information
rtucek committed Apr 15, 2021
0 parents commit 008aaa7
Show file tree
Hide file tree
Showing 114 changed files with 8,997 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
.env_*
build/
dist/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
37 changes: 37 additions & 0 deletions Pgc/Block/Checkout/PaymentJsLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);

namespace Pgc\Pgc\Block\Checkout;

use Magento\Framework\View\Element\Template;
use Pgc\Pgc\Helper\Data;

class PaymentJsLoader extends Template
{
/**
* @var Data
*/
private Data $helper;

/**
* Constructor
*
* @param Template\Context $context
* @param Data $helper ,
* @param array $data
*/
public function __construct(
Template\Context $context,
Data $helper,
array $data = []
) {
parent::__construct($context, $data);
$this->helper = $helper;
}

public function getHost()
{
return $this->helper->getHostUrl();
//return $this->helper->getGeneralConfigData('host');
}
}
59 changes: 59 additions & 0 deletions Pgc/Block/Customer/CardRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Pgc\Pgc\Block\Customer;

use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Block\AbstractCardRenderer;
use Pgc\Pgc\Model\Ui\ConfigProvider;

class CardRenderer extends AbstractCardRenderer
{
/**
* @return string
*/
public function getNumberLast4Digits(): string
{
return $this->getTokenDetails()['maskedCC'];
}

/**
* @return string
*/
public function getExpDate(): string
{
return $this->getTokenDetails()['expirationDate'];
}

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

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

/**
* @return int
*/
public function getIconWidth(): int
{
return $this->getIconForType($this->getTokenDetails()['type'])['width'];
}

/**
* @param PaymentTokenInterface $token
* @return bool
*/
public function canRender(PaymentTokenInterface $token): bool
{
return $token->getPaymentMethodCode() === ConfigProvider::CREDITCARD_CODE;
}
}
76 changes: 76 additions & 0 deletions Pgc/Block/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Pgc\Pgc\Block;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form\Cc;
use Magento\Payment\Helper\Data as Helper;
use Magento\Payment\Model\Config;
use Magento\Payment\Model\MethodInterface;
use Pgc\Pgc\Gateway\Config\Config as GatewayConfig;
use Pgc\Pgc\Model\Ui\ConfigProvider;

class Form extends Cc
{
/**
* @var GatewayConfig
*/
protected GatewayConfig $gatewayConfig;

/**
* @var Helper
*/
private Helper $paymentDataHelper;

/**
* Form constructor.
* @param Context $context
* @param Config $paymentConfig
* @param GatewayConfig $gatewayConfig
* @param Helper $helper
* @param array $data
*/
public function __construct(
Context $context,
Config $paymentConfig,
GatewayConfig $gatewayConfig,
Helper $helper,
array $data = []
) {
parent::__construct($context, $paymentConfig, $data);
$this->gatewayConfig = $gatewayConfig;
$this->paymentDataHelper = $helper;
}

/**
* @return bool
*/
public function useCcv(): bool
{
return true;
//$this->gatewayConfig->isCcvEnabled();
}

/**
* Check if vault enabled
* @return bool
* @throws LocalizedException
*/
public function isVaultEnabled(): bool
{
$storeId = $this->_storeManager->getStore()->getId();
$vaultPayment = $this->getVaultPayment();
return $vaultPayment->isActive($storeId);
}

/**
* Get configured vault payment for payment
* @return MethodInterface
* @throws LocalizedException
*/
private function getVaultPayment(): MethodInterface
{
return $this->paymentDataHelper->getMethodInstance(ConfigProvider::CC_VAULT_CODE);
}
}
38 changes: 38 additions & 0 deletions Pgc/Block/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

namespace Pgc\Pgc\Block;

use Magento\Framework\Phrase;
use Magento\Payment\Block\ConfigurableInfo;
use Pgc\Pgc\Gateway\Response\FraudHandler;

class Info extends ConfigurableInfo
{
/**
* Returns label
*
* @param string $field
* @return Phrase
*/
protected function getLabel($field)
{
return __($field);
}

/**
* Returns value view
*
* @param string $field
* @param string $value
* @return string | Phrase
*/
protected function getValueView($field, $value)
{
switch ($field) {
case FraudHandler::FRAUD_MSG_LIST:
return implode('; ', $value);
}
return parent::getValueView($field, $value);
}
}
53 changes: 53 additions & 0 deletions Pgc/Block/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Pgc\Pgc\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Pgc\Pgc\Model\Ui\ConfigProvider;

/**
* Class Payment
*/
class Payment extends Template
{
/**
* @var ConfigProvider
*/
private ConfigProvider $config;

/**
* Constructor
*
* @param Context $context
* @param ConfigProvider $config
* @param array $data
*/
public function __construct(
Context $context,
ConfigProvider $config,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
}

/**
* @return string
*/
public function getPaymentConfig(): string
{
$payment = $this->config->getConfig()['payment'];
$config = $payment[$this->getCode()];
$config['code'] = $this->getCode();
return json_encode($config, JSON_UNESCAPED_SLASHES);
}

/**
* @return string
*/
public function getCode(): string
{
return ConfigProvider::CREDITCARD_CODE;
}
}
Loading

0 comments on commit 008aaa7

Please sign in to comment.