Reputation: 9
I have been struggling with this for some time now. I almost explored all google replies etc...
Here is my code:
class WC_Gateway_mysolugion extends WC_Payment_Gateway {
public function __construct() {
...
...
/* Hook IPN callback logic*/
add_action( 'woocommerce_api_wc_gateway_mysolugion', array( $this, 'check_callback' ) );
}
....
function check_callback() {
// other code
}
The problem is that the function check_callback
never get called when controll returns back to the site from payment gateway site.
What I am doing wrong?
Any help will be appreciated.
Thanks.
Upvotes: 0
Views: 4307
Reputation: 9
Thanks @LoicTheAztec, for replying and helping. However, I found the reason why it was not working for me.
In my case I moved the callback function out of the mail gateway class and it started working. Simply put it in separate class and initiate that class in constructor of the main gateway class. that's it.
cheers,
Upvotes: 0
Reputation: 254388
Payment gateways should be created as additional plugins that hook into WooCommerce. Inside the plugin, you need to create a class after plugins are loaded (or alternatively at initialisation if is on function.php file of your active theme, see below).
So your code will look to this:
// for a plugin (the better choice)
add_action( 'plugins_loaded', 'init_mysolugion_gateway' );
// OR for theme function.php file
// add_action( 'init', 'init_mysolugion_gateway' );
function init_mysolugion_gateway() {
class WC_Gateway_mysolugion extends WC_Payment_Gateway {
public function __construct() {
// ...
// ...
/* Hook IPN callback logic*/
add_action( 'woocommerce_api_wc_gateway_mysolugion', array( $this, 'check_callback' ) );
}
}
}
As well as defining your class, you need to also tell WooCommerce (WC) that it exists. Do this by filtering woocommerce_payment_gateways:
add_filter( 'woocommerce_payment_gateways', 'add_gateway_mysolugion' );
function add_gateway_mysolugion( $methods ) {
$methods[] = 'WC_Gateway_mysolugion';
return $methods;
}
Then you can add your callback function and this should work now:
function check_callback() {
// other code
}
References:
Upvotes: 2