MultiSafepay / Magento2Msp

MultiSafepay plugin for Magento 2 (Deprecated) see: https://github.com/MultiSafepay/magento2
Open Software License 3.0
29 stars 25 forks source link

[PLGMAGTWOS-374] Please refactor your __constructor #89

Closed Luciferiix closed 3 years ago

Luciferiix commented 5 years ago

I have a 'Issue' with the next piece of code. It says a lot about your code reviews and company ethics. Your a payment provider, please act like one and start caring about ethics and security.

https://github.com/MultiSafepay/Magento2Msp/blob/master/Model/Connect.php#L216-L354

    /**
     * @param \Magento\Framework\Model\Context                        $context
     * @param \Magento\Framework\Registry                             $registry
     * @param \Magento\Framework\Api\ExtensionAttributesFactory       $extensionFactory
     * @param \Magento\Framework\Api\AttributeValueFactory            $customAttributeFactory
     * @param \Magento\Payment\Helper\Data                            $paymentData
     * @param \Magento\Framework\App\Config\ScopeConfigInterface      $scopeConfig
     * @param \Magento\Payment\Model\Method\Logger                    $logger
     * @param \Magento\Framework\Module\ModuleListInterface           $moduleList
     * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface    $localeDate
     * @param \Magento\Store\Model\StoreManagerInterface              $storeManager
     * @param \Magento\Checkout\Model\Session                         $checkoutSession
     * @param \Magento\CatalogInventory\Api\StockRegistryInterface    $stockRegistry
     * @param \Magento\Framework\UrlInterface                         $urlBuilder
     * @param \Magento\Framework\App\RequestInterface                 $requestHttp
     * @param \Magento\Sales\Model\Order\Email\Sender\InvoiceSender   $invoiceSender
     * @param \Magento\Framework\App\ProductMetadataInterface         $productMetadataInterface
     * @param \Magento\Sales\Api\InvoiceRepositoryInterface           $invoiceRepositoryInterface
     * @param \Magento\Sales\Api\TransactionRepositoryInterface       $transactionRepositoryInterface
     * @param \Magento\Framework\Locale\Resolver                      $localeResolver
     * @param \Magento\Sales\Api\OrderRepositoryInterface             $orderRepositoryInterface
     * @param \Magento\Sales\Model\OrderNotifier                      $orderNotifier
     * @param \Magento\Sales\Model\Order\StatusResolver               $statusResolver
     * @param \MultiSafepay\Connect\Model\Api\MspClient               $mspClient
     * @param \MultiSafepay\Connect\Helper\Data as HelperData         $helperData
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
     * @param \Magento\Framework\Data\Collection\AbstractDb           $resourceCollection
     * @param array                                                   $data
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        Context $context,
        Registry $registry,
        ExtensionAttributesFactory $extensionFactory,
        AttributeValueFactory $customAttributeFactory,
        Data $paymentData,
        ScopeConfigInterface $scopeConfig,
        Logger $logger,
        ModuleListInterface $moduleList,
        TimezoneInterface $localeDate,
        StoreManagerInterface $storeManager,
        Session $checkoutSession,
        UrlInterface $urlBuilder,
        RequestInterface $requestHttp,
        StockRegistryInterface $stockRegistry,
        InvoiceSender $invoiceSender,
        ProductMetadataInterface $productMetadataInterface,
        InvoiceRepositoryInterface $invoiceRepositoryInterface,
        TransactionRepositoryInterface $transactionRepositoryInterface,
        Resolver $localeResolver,
        OrderRepositoryInterface $orderRepositoryInterface,
        OrderNotifier $orderNotifier,
        StatusResolver $statusResolver,
        MultisafepayTokenizationFactory $multisafepayTokenizationFactory,
        MspClient $mspClient,
        HelperData $helperData,
        \Magento\Customer\Model\Session $customerSession,
        AbstractResource $resource = null,
        AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        parent::__construct(
            $context,
            $registry,
            $extensionFactory,
            $customAttributeFactory,
            $paymentData,
            $scopeConfig,
            $logger,
            $resource,
            $resourceCollection,
            $data
        );
        $this->_customerSession = $customerSession;
        $this->_client = $mspClient;
        $this->_checkoutSession = $checkoutSession;
        $this->_storeManager = $storeManager;
        $this->_urlBuilder = $urlBuilder;
        $this->_requestHttp = $requestHttp;
        $this->_mspHelper = $helperData;
        $this->_mspToken = $multisafepayTokenizationFactory;
        $this->_minAmount = $this->getConfigData('min_order_total');
        $this->_maxAmount = $this->getConfigData('max_order_total');
        $this->_invoiceSender = $invoiceSender;
        $this->stockRegistry = $stockRegistry;
        $this->_transactionRepositoryInterface = $transactionRepositoryInterface;
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/multisafepay.log');
        $this->logger = new \Zend\Log\Logger();
        $this->logger->addWriter($writer);
        $this->_client->logger = $this->logger;
        $this->_client->debug = ($this->getMainConfigData('msp_debug')) ? true : false;
        $app_state = $this->_appState;
        $area_code = $app_state->getAreaCode();
        $this->_productMetadataInterface = $productMetadataInterface;
        $this->_localeResolver = $localeResolver;
        $this->_orderRepositoryInterface = $orderRepositoryInterface;
        $this->_orderNotifier = $orderNotifier;
        $this->_statusResolver = $statusResolver;
        $invoiceId = $requestHttp->getParam('invoice_id');
        if ($invoiceId && $app_state->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
            $invoice = $invoiceRepositoryInterface->get($invoiceId);
            if ($invoice) {
                //the invoice is loaded so we can check the invoice currencies.
                $base_currency_code = $invoice->getBaseCurrencyCode();
                $order_currency_code = $invoice->getOrderCurrencyCode();
                if ($base_currency_code != $order_currency_code) {
                    $this->_canRefund = false;
                    $this->_canRefundInvoicePartial = false;
                }
                /*
                 * Refunding from the Magento backend is disabled when the order processed a Fooman Surcharge
                 * This is done because the Fooman extension has an issue with partial refunds, causing wrong amounts refunded online at MultiSafepay
                 * Issue has been reported at Fooman, once resolved this functionality will be supported again.
                 */
                $extensionAttributes = $invoice->getExtensionAttributes();
                if ($extensionAttributes) {
                    if (method_exists($extensionAttributes, 'getFoomanTotalGroup')) {
                        $invoiceTotalGroup = $extensionAttributes->getFoomanTotalGroup();
                        if ($invoiceTotalGroup) {
                            $items = $invoiceTotalGroup->getItems();
                            if (!empty($items)) {
                                $this->_canRefund = false;
                                $this->_canRefundInvoicePartial = false;
                            }
                        }
                    }
                }
            }
        }
    }
Ruud-MultiSafepay commented 5 years ago

@Luciferiix Thank you for reporting. We have created an internal task for this report and will try to review as soon as possible. Internal reference: PLGMAGTWOS-374

Jasper-MultiSafepay commented 5 years ago

@Luciferiix Thank you for notifying us of these issues. We have reviewed the issues and are implementing some solutions. Could you send an email to techsupport@multisafepay.com, so we can keep contact with you?

vinodsowdagar commented 3 years ago

Hi @Luciferiix ,

Thank you for reporting this.

Unfortunately, this plugin is deprecated and we are not providing support for it anymore. Please upgrade to our New Magento 2 plugin..

This issue has not occurred in the new plugin and the new plugin also has tons of other improvements. I am closing this issue for now. If you have any more comments or questions, feel free to create a new issue in the new plugin repo.