marketpress payment gateway - payfast for south africans

hello!

so on a couple of my sites, and client sites, we use payfast for payment with marketpress.

payfast has a php file or two, that we can upload to the payments gateway folder, and voilla, we can take payments.

however, every time there's a marketpress update, the payment gateway simply falls away.

as i'm using the automated one click sexy update feature inside hub, i really don't notice when there's an update, i just get an irate grumble from one of my clients, and then i know i'm the lucky winner of re-doing the payfast upload and extract, and "activating" the gateway on each of the sites.

so - here's my question.

i have the php files that does the heavy lifting, it was already created. but - how do i make this gateway into a completely separate plugin, that still engages with marketpress even after an update?

the way i understand it, marketpress looks in the gateway folder, and regurgitates whatever it sees there. and as long as marketpress is going to update everything in that folder too, it's going to overwrite the gateway every time.

writing a separate plugin in a separate place, won't tell the gateway folder that there's something else sitting in a separate place, so it's not the .php files that are weird, it's the location where marketpress looks that will be the problem.

how do i get past that?

    Predrag Dubajic

    Hey Symi,

    Hope all is well

    When you update plugins and themes it will overwrite entire folder with the new one and thus remove any files that were additionally added to its folders.

    I'm afraid that I'm not familiar with a hook that could be used in order to pull gateways from external source but let me forward this thread to our second level support dev guys so they can check the code and see what could be done about this.
    Please note that, developer response might be slower than usual staff response, so we appreciate your patience on this.

    Best regards,
    Predrag

    Ivan

    Hi, Symi !

    If this payment gateway uses php class - You can try to create (wordpress_folder)/wp-content/mu-plugins/wpmu_add_custom_gateway.php file via FTP and add the following code in this file

    <?php
    function wpmu_add_custom_gateway() {
        //register custom payment gateway
        if ( function_exists( 'mp_register_gateway_plugin' ) ) {
            mp_register_gateway_plugin( PHP_CLASS_NAME, YOUR_PLUGIN_GATEWAY_NAME, YOUR_ADMIN_GATEWAY_NAME );
        }
    }
    
    add_action('init', 'wpmu_add_custom_gateway');

    Don't forget change these variables to real value:
    - PHP_CLASS_NAME - the case-sensitive name of your plugin class
    - YOUR_PLUGIN_GATEWAY_NAME - the sanitized private name for your plugin
    - YOUR_ADMIN_GATEWAY_NAME - pretty name of your gateway, for the admin side

    Also, you can add files of the gateway to (wordpress_folder)/wp-content/mu-plugins/ folder.

    Please let me know how it goes.

    Best regards,
    Ivan.

    Symi

    Whoaah - Ivan, you're a BISCUIT! *beams excitedly*

    I need to check what may sound like simple copy and paste actions to you... with you before I get cute and break stuff.

    Here are my variables to fix:
    - PHP_CLASS_NAME - the case-sensitive name of your plugin class
    - YOUR_PLUGIN_GATEWAY_NAME - the sanitized private name for your plugin
    - YOUR_ADMIN_GATEWAY_NAME - pretty name of your gateway, for the admin side

    And here's the first bit of the .php file of the plugin.

    <?php
    
    class MP_Gateway_PayFast extends MP_Gateway_API
    {

    so as the php class i get: MP_Gateway_PayFast
    then - here's variables lower down in the code:

    //set names here to be able to translate
            $this->admin_name  = __( 'PayFast', 'mp' );
            $this->public_name = __( 'PayFast', 'mp' );

    and as the plugin name both admin / public side, i get: PayFast

    Do I add in the single inverts?

    thank so much!

    S

    Symi

    Hello Ivan ,

    So I created the/mu-plugins/ directory beneath wp_content/
    Then, I copied the code above, and plonked it into a file named wpmu_add_custom_gateway.php
    I copied that file up to the new mu-plugins directory.
    There are 2 payfast files, payfast.php and payfast_common.inc
    I copied them into the mu-plugins directory too.

    And I won this error:

    This page isn’t working

    lifestylestuff.guru is currently unable to handle this request.
    HTTP ERROR 500

    What should I do?

    I have enabled remote support on the site.

    Ivan

    Hi Symi!

    Thank you for your quick message when you provided Grant access to your site for us with your CPanel credentials - this saved time for us

    It happened because of the MP_Gateway_PayFast class use MP_Gateway_API which isn't included at that moment.
    I changed this code to

    <?php
    function wpmu_add_custom_gateway() {
        //register custom payment gateway
        if ( function_exists( mp_register_gateway_plugin ) && class_exists( 'MP_Gateway_API' ) ) {
            require_once( WP_CONTENT_DIR . '/pay_fast/payfast.php');
            mp_register_gateway_plugin( 'MP_Gateway_PayFast', __( 'PayFast', 'mp' ), __( 'PayFast', 'mp' )  );
        }
    }
    
    add_action('init', 'wpmu_add_custom_gateway');

    Also, I moved files of your payment gateway to (wordpress_folder)/wp-content/pay_fast folder.

    It seems it works now. Please, check this.

    Best regards,
    Ivan.

    Symi

    Kind Ivan,

    thank you for engaging with this.

    I've had a look at this page, it's where the gateway should show up:
    https://domain_name/wp-admin/admin.php?page=store-settings-payments

    Payfast shows up twice as a payment gateway now, and the usual options when selecting it, to add in my credentials, doesn't show up at the bottom of the page.

    I've tried selecting either of the payfasts, or both, and it makes no difference to the settings display.

    Your access is still active.

    I've also granted access for you on another site.
    I've left the name of the site on THIS site's comments where the remote access is granted?
    on there, is a working version of the payfast gateway so you can compare them?

    I hope that helps.

    Again - thank you so much for engaging with this.

    Ivan

    Hi Symi !

    Payfast shows up twice

    It happened because there was registration the same Payment Gateway in your class at the end of file. I deleted this and renamed the class as MP_Gateway_PayFast_copy. Also, I changed code of the MU plugin to

    function wpmu_add_custom_gateway( $_gateways ) {
        //register custom payment gateway
        if ( !isset( $_gateways['payfast'] ) && function_exists( 'mp_register_gateway_plugin' ) ) {
            require_once( WP_CONTENT_DIR . '/pay_fast/payfast.php');
            mp_register_gateway_plugin( 'MP_Gateway_PayFast_copy', 'payfast', __( 'PayFast', 'mp' )  );
            $_gateways = MP_Gateway_API::get_gateways();
        }
        return $_gateways;
    }
    
    add_filter('mp_gateway_api/get_gateways', 'wpmu_add_custom_gateway', 1);

    It should work, please, check it.

    Best regards,
    Ivan.