pagantis /
magento-2X
| 1 | <?php |
||||||
| 2 | namespace Pagantis\Pagantis\Controller\Payment; |
||||||
| 3 | |||||||
| 4 | use Magento\Framework\App\Action\Action; |
||||||
| 5 | use Magento\Framework\App\Action\Context; |
||||||
| 6 | use Magento\Framework\App\ResourceConnection; |
||||||
| 7 | use Magento\Framework\App\RequestInterface; |
||||||
| 8 | use Magento\Framework\App\Request\InvalidRequestException; |
||||||
| 9 | use Pagantis\Pagantis\Helper\Config; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 10 | |||||||
| 11 | class ConfigV2 extends Action |
||||||
| 12 | { |
||||||
| 13 | /** Config tablename */ |
||||||
| 14 | const CONFIG_TABLE = 'Pagantis_config'; |
||||||
| 15 | |||||||
| 16 | /** @var mixed $config */ |
||||||
| 17 | protected $config; |
||||||
| 18 | |||||||
| 19 | /** @var ResourceConnection $dbObject */ |
||||||
| 20 | protected $dbObject; |
||||||
| 21 | |||||||
| 22 | /** |
||||||
| 23 | * Variable which contains extra configuration. |
||||||
| 24 | * @var array $defaultConfigs |
||||||
| 25 | */ |
||||||
| 26 | public $defaultConfigs = array('PAGANTIS_TITLE'=>'Paga en cuotas', |
||||||
| 27 | 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE', |
||||||
| 28 | 'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE', |
||||||
| 29 | 'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', |
||||||
| 30 | 'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, |
||||||
| 31 | 'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, |
||||||
| 32 | 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', |
||||||
| 33 | 'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER', |
||||||
| 34 | 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'default', |
||||||
| 35 | 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default', |
||||||
| 36 | 'PAGANTIS_FORM_DISPLAY_TYPE'=>0, |
||||||
| 37 | 'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, |
||||||
| 38 | 'PAGANTIS_DISPLAY_MAX_AMOUNT'=>0, |
||||||
| 39 | 'PAGANTIS_URL_OK'=>'', |
||||||
| 40 | 'PAGANTIS_URL_KO'=>'', |
||||||
| 41 | 'PAGANTIS_TITLE_EXTRA' => 'Pay up to 12 comfortable installments with Pagantis. Completely online and sympathetic request, and the answer is immediate!' |
||||||
| 42 | ); |
||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * ConfigV2 constructor. |
||||||
| 46 | * |
||||||
| 47 | * @param Context $context |
||||||
| 48 | * @param Config $pagantisConfig |
||||||
| 49 | * @param ResourceConnection $dbObject |
||||||
| 50 | * @param RequestInterface $request |
||||||
| 51 | */ |
||||||
| 52 | public function __construct( |
||||||
| 53 | Context $context, |
||||||
| 54 | Config $pagantisConfig, |
||||||
| 55 | ResourceConnection $dbObject, |
||||||
| 56 | RequestInterface $request |
||||||
| 57 | ) { |
||||||
| 58 | $this->config = $pagantisConfig->getConfig(); |
||||||
| 59 | $this->dbObject = $dbObject; |
||||||
| 60 | |||||||
| 61 | // CsrfAwareAction Magento2.3 compatibility |
||||||
| 62 | if (interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) { |
||||||
| 63 | if (isset($request) && $request->isPost() && empty($request->getParam('form_key'))) { |
||||||
|
0 ignored issues
–
show
The method
isPost() does not exist on Magento\Framework\App\RequestInterface. It seems like you code against a sub-type of Magento\Framework\App\RequestInterface such as Magento\Framework\Webapi\Request or Magento\Framework\App\Request\Http.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 64 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); |
||||||
| 65 | $formKey = $objectManager->get(\Magento\Framework\Data\Form\FormKey::class); |
||||||
| 66 | $request->setParam('form_key', $formKey->getFormKey()); |
||||||
|
0 ignored issues
–
show
The method
setParam() does not exist on Magento\Framework\App\RequestInterface. Did you maybe mean setParams()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 67 | } |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | return parent::__construct($context); |
||||||
|
0 ignored issues
–
show
Are you sure the usage of
parent::__construct($context) targeting Magento\Framework\App\Action\Action::__construct() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | /** |
||||||
| 74 | * Main function |
||||||
| 75 | * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
||||||
| 76 | */ |
||||||
| 77 | public function execute() |
||||||
| 78 | { |
||||||
| 79 | try { |
||||||
| 80 | $response = array('status'=>null); |
||||||
| 81 | $tableName = $this->dbObject->getTableName(self::CONFIG_TABLE); |
||||||
| 82 | $secretKey = $this->_request->getParam('secret'); |
||||||
| 83 | $privateKey = isset($this->config['pagantis_private_key']) ? $this->config['pagantis_private_key'] : null; |
||||||
| 84 | |||||||
| 85 | /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
||||||
| 86 | $dbConnection = $this->dbObject->getConnection(); |
||||||
| 87 | if ($privateKey != $secretKey) { |
||||||
| 88 | $response['status'] = 401; |
||||||
| 89 | $response['result'] = 'Unauthorized'; |
||||||
| 90 | } elseif ($this->_request->isPost()) { |
||||||
| 91 | if (count($_POST)) { |
||||||
| 92 | foreach ($_POST as $config => $value) { |
||||||
| 93 | if (isset($this->defaultConfigs[$config]) && $response['status']==null) { |
||||||
| 94 | $dbConnection->update( |
||||||
| 95 | $tableName, |
||||||
| 96 | array('value' => $value), |
||||||
| 97 | "config='$config'" |
||||||
| 98 | ); |
||||||
| 99 | } else { |
||||||
| 100 | $response['status'] = 400; |
||||||
| 101 | $response['result'] = 'Bad request'; |
||||||
| 102 | } |
||||||
| 103 | } |
||||||
| 104 | } else { |
||||||
| 105 | $response['status'] = 422; |
||||||
| 106 | $response['result'] = 'Empty data'; |
||||||
| 107 | } |
||||||
| 108 | } |
||||||
| 109 | |||||||
| 110 | $formattedResult = array(); |
||||||
| 111 | if ($response['status']==null) { |
||||||
| 112 | $dbResult = $dbConnection->fetchAll("select * from $tableName"); |
||||||
| 113 | foreach ($dbResult as $value) { |
||||||
| 114 | $formattedResult[$value['config']] = $value['value']; |
||||||
| 115 | } |
||||||
| 116 | $response['result'] = $formattedResult; |
||||||
| 117 | } |
||||||
| 118 | $result = json_encode($response['result']); |
||||||
| 119 | header("HTTP/1.1 ".$response['status'], true, $response['status']); |
||||||
| 120 | header('Content-Type: application/json', true); |
||||||
| 121 | header('Content-Length: '.strlen($result)); |
||||||
| 122 | echo($result); |
||||||
| 123 | exit(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 124 | } catch (\Exception $e) { |
||||||
| 125 | die($e->getMessage()); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 126 | } |
||||||
| 127 | } |
||||||
| 128 | |||||||
| 129 | /** |
||||||
| 130 | * @param RequestInterface $request |
||||||
| 131 | * |
||||||
| 132 | * @return InvalidRequestException|null |
||||||
| 133 | */ |
||||||
| 134 | public function createCsrfValidationException(RequestInterface $request) |
||||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 135 | { |
||||||
| 136 | return null; |
||||||
| 137 | } |
||||||
| 138 | |||||||
| 139 | /** |
||||||
| 140 | * @param RequestInterface $request |
||||||
| 141 | * |
||||||
| 142 | * @return bool|null |
||||||
| 143 | */ |
||||||
| 144 | public function validateForCsrf(RequestInterface $request) |
||||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 145 | { |
||||||
| 146 | return true; |
||||||
| 147 | } |
||||||
| 148 | } |
||||||
| 149 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: