How do I hook in a custom membership gateway from a plugin?

I’ve created a plugin to add a custom payment gateway to the membership

when I call M_register_gateway from a plugin I get an error saying class M_Gateway not found.

if i call it inside an add_action("init","register_my_gateway",10) the error goes away, but my plugin does not get listed in the settings page.

Please help.