I am building a payment Gateway for WooCommerce where the payment takes place in an offsite URL. I need that page to be able to message back to the WooCommerce plugin, and a "callback" URL is really all I need.
WooCommerce seems to have this, but I can't get it to work. You're supposed to be able to ping:
http://yoursite/wc-api/WC_your_gateway
And then you're supposed to add add_action( 'woocommerce_api_callback', 'callback_handler' ); And then it's supposed to fire a function like this public function callback_handler() {}
But when I go to that URL, all I see is a 1 on my page - my handler should be redirecting to another page (that's what I set it to do to make it obvious). What I'd LOVE is if anyone has an example of this working. I've tried placing the add_action and the handler function lots of places, no luck.
I have the same problem. Try to add exit; or wp_die(); in the end of your callback function.
This works for me.
I had the same problem, so, this is what worked for me:
class WC_mygateway extends WC_Payment_Gateway {
public function __construct() {
//'woocommerce_api_'.strtolower(get_class($this)) will result in 'woocommerce_api_wc_mygateway'
add_action('woocommerce_api_'.strtolower(get_class($this)), array(&$this, 'handle_callback'));
}
function handle_callback() {
//Handle the thing here!
}
}
function woocommerce_mygateway_add_gateway( $methods ) {
$methods[] = 'WC_mygateway';
return $methods
}
add_filter( 'woocommerce_payment_gateways', 'woocommerce_mygateway_add_gateway');
Make sure you are not missing any of those details, other wise it wont work. Also you can call it using http://example.com/?wc-api=wc_mygateway or http://example.com/wc-api/wc_mygateway
Hope this work for everyone getting stuck with this issue!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With