Ok, there is good news and bad news, but hopefully more good than bad...
Good: The fix I was trying to implement did work, I just mis-counted the output buffer nesting level - after adding an extra flush, it stopped the postback error in ePDQ.
Bad: The ePDQ postback is done separately from the client redirect, so although the postback shows the thank you message, the client never sees it.
Bad: The atrociously spelt 'barkalys' gateway does not provide a setting for the return URL used to redirect the client after successful payment, and defaults to your website home page.
Good: The gateway's source code is now open source, so I can see that a setting can be added to the database for a custom return URL. If you create an article in Joomla containing your thank you message (instead of using the setting on the order form), and make a note of the URL, you could manually add a record to the database using an SQL query like this:
INSERT INTO `jos_nbill_payment_gateway` (`gateway_id`, `g_key`, `g_value`, `label`, `help_text`, `required`, `admin_can_edit`, `ordering`) VALUES ('barkalys', 'return_url', '
http://www.example.com/your_success_article_here.html', 'Return URL', '', '0', '1', '99');
Bad: I have not tested the above, and I don't know whether the success message would also be displayed in the case of failure. If the above is not a satisfactory solution, I would have to refer you back to OSDCS or alternatively advise you to employ the services of a PHP developer to further develop the gateway script.