1
votes

I'm trying to write my own payment gateway for WooCommerce and it's going pretty well. Now my payment provider can do a callback to verify the payment status, so i created a callback function.

 add_action('woocommerce_api_'.strtolower(get_class($this)), array(&$this, 'callback'));

    public function callback()
    {
        mail('[email protected]', 'callback ideal', print_r($_REQUEST,true) . print_r($_SERVER,true));

        echo '+';
        return '+';
    }

When i call the callback URL, i recieve the email that's in the callback function, however the output the callback gives is always 1.

I did some googling on what the 1 means, it means the callback doesn't end or isn't called at all.

In my case it does get called, since i recieve the email. Could someone point me in the right direction ? I must be missing something.

Update:

When i kill the script with an exit in the callback function, i can see the output. But this probably isn't the appropriate solution

1

1 Answers

0
votes

The reason might be that this action is been called via some ajax. In wordpress the ajax default returns the die() function before the function ends. So if we don't specify die() in our custom function it will append 1 with the data in our callback. So you have to call die or exit after the output is being echo to the browser to prevent returning and other data in our custom functions which are been called via ajax.

Hope this solution helps you.