My WooCommerce plugin callback function stop working after wc update

admin

Administrator
Staff member
<blockquote>
TL;DR WooCommerce callback url that run a class with the same name broke. Like I could access my
Code:
valitorcallback
class by going to
Code:
http://mywebsite.com/wc-api/valitorcallback
, is there way to enable that url or somehow access this class?
</blockquote>

I developed a WooCommerce payment gateway plugin to connect to an Icelandic paypal like company Valitor.

The payment flow is simple:

<ol>
<li>Customers add items to his cart and goes to checkout.</li>
<li>Redirect customer of a web-store to Valitor with order info in the parameters of the request.</li>
<li>Customer pays with his credit card or his debit card.</li>
<li>The customer is redirected to provided thank-you page and Valitor calls another url (the callback) to notify that the payment is complete and with the order info and verification codes/method.</li>
</ol>

The only thing the plugin does is step 2 and 4. In step 4, if the order is valid then the plugin lower the stock and change the state of the order to says the payment has been completed.

<strong>The problem is after a WooCommerce update about 2 months ago the callback url broke</strong>, probably because of security reasons. I have not been able to find a code to enable this url again or to solve this. It think it can be done with add_action method or some hooks but I've not been able to get that to work.

Here is the guide I think is the key but I'm doing something wrong: <a href="http://docs.woothemes.com/document/payment-gateway-api/#section-4" rel="nofollow">http://docs.woothemes.com/document/payment-gateway-api/#section-4</a>

The Code plugin structure is like this:

Code:
&lt;?php

function initWooCommerceValitorGatewayPlugin()
{
    class WooCommerceValitorGateway extends WC_Payment_Gateway
    {
        public function __construct()
        {
            // ...Varible code...

            // Actions
            add_action('woocommerce_update_options_payment_gateways_'.$this-&gt;id, array($this, 'process_admin_options'));
        }

        public function init_form_fields()
        {
            // ...Define settings code...
        }

        public function process_payment($orderId)
        {
            // ...Magic code...

            // Redirect to Valitor with all necessary data 
            return array(
                'result' =&gt; 'success',
                'redirect' =&gt; add_query_arg($valitorData, $gatewayUrl)
            );
        }

        // ...Helper functions code (like sending an email)...
    }
}

class valitorcallback
{
    public function __construct()
    {
        $this-&gt;verifyPayment();
    }

    public function verifyPayment()
    {
        // ...Verification code...
    }

    // ...Helper functions code (like sending an email)...

}

// Add plugin to wordpress/woocommerce
add_action('plugins_loaded', 'initWooCommerceValitorGatewayPlugin');

function addValitorGateway($methods)
{
    $methods[] = 'WooCommerceValitorGateway'; 
    return $methods;
}
// Add gateway method to woocommerce
add_filter('woocommerce_payment_gateways', 'addValitorGateway');

?&gt;

Now you see the functions name and maybe can tell me where should add_action be placed.

I know of the mywebsite.com/wc-api/v3/... REST API but I was hoping that I could just enable the url again so I don't have to code that part again and I'm not sure how to get that plugin settings from another file.

Thanks, Sigurður

EDIT: added TL;DR section at top and bold when I state the problem.