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

Change paymentTypes in PayWeb/Model/PayGate.php to use `static` descriptions #36

Closed ChameleonDevil closed 2 years ago

ChameleonDevil commented 2 years ago

I have a request from my company to change the text displayed for some of the payment options, and the current implementation of PayWeb/Model/PayGate.php uses constants for the descriptions:

    protected $paymentTypes = [
        self::CREDIT_CARD_METHOD   => self::CREDIT_CARD_DESCRIPTION,
        self::BANK_TRANSFER_METHOD => self::BANK_TRANSFER_METHOD_DETAIL,
        self::ZAPPER_METHOD        => self::ZAPPER_DESCRIPTION,
        self::SNAPSCAN_METHOD      => self::SNAPSCAN_DESCRIPTION,
        self::MOBICRED_METHOD      => self::MOBICRED_DESCRIPTION,
        self::MOMOPAY_METHOD       => self::MOMOPAY_METHOD_DETAIL,
        self::SCANTOPAY_METHOD     => self::SCANTOPAY_DESCRIPTION,
        self::PAYPAL_METHOD        => self::PAYPAL_DESCRIPTION,
    ];

I would like to override the descriptions for these payment types inside Model/PayGate.php without changing anything else, so that any updates you do on this file in the future remains.

I would like to request static to be used for these payment type descriptions instead of self:

    protected $paymentTypes = [
        self::CREDIT_CARD_METHOD   => static::CREDIT_CARD_DESCRIPTION,
        self::BANK_TRANSFER_METHOD => static::BANK_TRANSFER_METHOD_DETAIL,
        self::ZAPPER_METHOD        => static::ZAPPER_DESCRIPTION,
        self::SNAPSCAN_METHOD      => static::SNAPSCAN_DESCRIPTION,
        self::MOBICRED_METHOD      => static::MOBICRED_DESCRIPTION,
        self::MOMOPAY_METHOD       => static::MOMOPAY_METHOD_DETAIL,
        self::SCANTOPAY_METHOD     => static::SCANTOPAY_DESCRIPTION,
        self::PAYPAL_METHOD        => static::PAYPAL_DESCRIPTION,
    ];

This means that I just change the values for the constants inside the overriding class, without having to completely change protected $paymentTypes

const CREDIT_CARD_DESCRIPTION     = 'Credit Card';
appinlet commented 2 years ago

@ChameleonDevil thank you, this request has been added to the backlog for review.

appinlet commented 2 years ago
Screenshot 2022-09-08 at 15 00 27

This will be included in the next release @ChameleonDevil

ChameleonDevil commented 2 years ago
Screenshot 2022-09-08 at 15 00 27

This will be included in the next release @ChameleonDevil

Thank you very much!

ChameleonDevil commented 2 years ago

Since I have now been waiting for the next release mentioned here which is not available, and since I am forced to use v2.4.8 at the moment, I investigated $paymentTypes further.

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