Paygate / PayWeb_Magento_2

This is the PayGate PayWeb3 plugin for Magento 2.
GNU General Public License v3.0
2 stars 6 forks source link

Payment information `paymentTypes` is not being used #39

Closed ChameleonDevil closed 2 years ago

ChameleonDevil commented 2 years ago

The original topic mentioned here (which was closed) : Change paymentTypes in PayWeb/Model/PayGate.php to use static descriptions

At the time when I requested a change to use static descriptions I was still under the impression that paymentTypes have some use, but it turns out it is not used in v2.4.8 at all.

So, since I have now been waiting for the next release mentioned which would include the above changes, this is still not available, and since I am forced to use v2.4.8 at the moment, I investigated $paymentTypes further and to make a solution for our use.

I do not see $paymentTypes being used anywhere.

Inside PayWeb/Model/PayGate.php function prepareFields() does this:

    if ($paymentType !== '0' && $this->getConfigData('paygate_pay_method_active') != '0') {

$fields['PAY_METHOD'] = $this->getPaymentType($paymentType); $fields['PAY_METHOD_DETAIL'] = $this->getPaymentTypeDetail($paymentType); }

getPaymentType():

    public function getPaymentType($pt)
    {
        switch ($pt) {
            case self::BANK_TRANSFER:
                return self::BANK_TRANSFER;
                break;
            case self::ZAPPER_METHOD:
                return 'EW';
                break;
            case self::SNAPSCAN_METHOD:
                return 'EW';
                break;
            case self::MOBICRED_METHOD:
                return 'EW';
                break;
            case self::MOMOPAY_METHOD:
                return 'EW';
                break;
            case self::MASTERPASS_METHOD:
                return 'EW';
                break;
            case self::PAYPAL_METHOD:
                return 'EW';
                break;
            default:
                return 'CC';
                break;
        }
    }

getPaymentDetail():

    public function getPaymentTypeDetail($ptd)
    {
        switch ($ptd) {
            case self::BANK_TRANSFER:
                return self::BANK_TRANSFER_METHOD_DETAIL;
                break;
            case self::ZAPPER_METHOD:
                return self::ZAPPER_DESCRIPTION;
                break;
            case self::SNAPSCAN_METHOD:
                return self::SNAPSCAN_DESCRIPTION;
                break;
            case self::MOBICRED_METHOD:
                return self::MOBICRED_DESCRIPTION;
                break;
            case self::MOMOPAY_METHOD:
                return self::MOMOPAY_METHOD_DETAIL;
                break;
            case self::MASTERPASS_METHOD:
                return self::MASTERPASS_DESCRIPTION;
                break;
            case self::PAYPAL_METHOD:
                return self::PAYPAL_DESCRIPTION;
                break;
            default:
                return self::CREDIT_CARD_DESCRIPTION;
                break;
        }
    }

At first when I opened this ticket I assumed it is that $paymentTypes inside /PayGate.php used, however I now realise this is not the case:

/view/frontend/web/template/payment/paygate.html

<!-- ko foreach: { data: JSON.parse(getPaymentTypesList()), as: 'option' }

This is referenced inside view/frontend/web/js/view/payment/method-renderer/paygate-method.js:

      getPaymentTypesList: function () {
        var paymentTypes = window.checkoutConfig.payment.paygate.paymentTypeList
        return paymentTypes
      },

paymentTypeList is defined in /PayWeb/Model/PaygateConfigProvider.php:

'paymentTypeList'           => $this->getPaymentTypes()

Relevant part inside PaygateConfigProvider->getPaymentTypes():

        $allTypes = array(
            'CC'            => array(
                'value' => 'CC',
                'label' => "Card",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/mastercard-visa.svg'),
            ),
            'BT'            => array(
                'value' => 'BT',
                'label' => "SiD Secure EFT",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/sid.svg'),
            ),
            'EW-ZAPPER'     => array(
                'value' => 'EW-ZAPPER',
                'label' => "Zapper",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/zapper.svg'),
            ),
            'EW-SNAPSCAN'   => array(
                'value' => 'EW-SNAPSCAN',
                'label' => "SnapScan",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/snapscan.svg'),
            ),
            'EW-MOBICRED'   => array(
                'value' => 'EW-MOBICRED',
                'label' => "Mobicred",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/mobicred.svg'),
            ),
            'EW-MOMOPAY'    => array(
                'value' => 'EW-MOMOPAY',
                'label' => "MoMoPay",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/momopay.svg'),
            ),
            'EW-MASTERPASS' => array(
                'value' => 'EW-MASTERPASS',
                'label' => "MasterPass",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/masterpass.svg'),
            ),
            'EW-PAYPAL'     => array(
                'value' => 'EW-PAYPAL',
                'label' => "PayPal",
                'image' => $this->getViewFileUrl('PayGate_PayWeb::images/paypal.svg'),
            )

In short:

Since I am using v2.4.8 there is no easy way to submit a Pull Request, as I will have to override both PayGate.php and PaygateConfigProvider.php

ChameleonDevil commented 2 years ago

So in summary: paymentTypes is not used at all, and several places different payment descriptions are used, some as constants, some as hard-coded information. I really hope a future version can improve on this for other users that may have similar requirements.

I had to end up throwing away a <preference /> override which was going to use paymentTypes, instead I now made a <plugin /> to change descriptions:

\PayGate\PayWeb\Model\PaygateConfigProvider::getPaymentTypes -> afterGetPaymentTypes() plugin

Summarized version: I had to decode the JSON from getPaymentTypes() and then update the payment types I needed, then re-encode JSON to return result.

NOTE: _updatePaymentTypes($paymentTypes) (not shown here) is where all the logic is to parse the JSON and filter relevant payment types to be updated.

     * @param \PayGate\PayWeb\Model\PaygateConfigProvider $subject
     * @param string $json
     * @return JSON JSON encoding string
     */
    public function afterGetPaymentTypes(
        \PayGate\PayWeb\Model\PaygateConfigProvider $subject,
        string $json
    ) {
        $paymentTypes = json_decode($json);

        $this->_updatePaymentTypes($paymentTypes);
        $json = json_encode($paymentTypes);

        return $json;
    }
appinlet commented 2 years ago

@ChameleonDevil we're looking into this and will revert once we have feedback.

appinlet commented 2 years ago

@ChameleonDevil just a quick update, the upcoming release will make use of these descriptions:


return array(
            [
                'value' => 'CC',
                'label' => $this->paymentMethod->getPaymentTypeDescription('CC'),
            ],
            [
                'value' => 'BT',
                'label' => $this->paymentMethod->getPaymentTypeDescription('BT'),
            ],
            [
                'value' => 'EW-ZAPPER',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-ZAPPER'),
            ],
            [
                'value' => 'EW-SNAPSCAN',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-SNAPSCAN'),
            ],
            [
                'value' => 'EW-MOBICRED',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-MOBICRED'),
            ],
            [
                'value' => 'EW-MOMOPAY',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-MOMOPAY'),
            ],
            [
                'value' => 'EW-SCANTOPAY',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-SCANTOPAY'),
            ],
            [
                'value' => 'EW-PAYPAL',
                'label' => $this->paymentMethod->getPaymentTypeDescription('EW-PAYPAL'),
            ]
        );
    }`