Moving module from project to another project

I write a module in this the backend with this name space:

namespace backend\modules\payment;

so if I move module to another project in frontend the module will broke;

and another problem is that I add module with name "payment" in config

'payment' => [

            'class' => 'backend\modules\payment\Bank',

            'components' => [

                'service'  => [

                    'class' => 'backend\modules\payment\components\Service',




and I get full url to actionReturn in module’s “service” component using this method:

public function getReturnUrl()


        return \yii\helpers\Url::toRoute('payment/return',true);


now if I want to change module name in another project , I have to go and change all this functions to get valid url ,

is there any way to fix this and action’s url not be depended on module name

Make that module into a composer package ?

Then the namespace would be your_name/your_package.