<?php 
namespace PortalPeople\paygate;
use PortalPeople\paygate\models\Paygate;

class Module extends \yii\base\Module implements \yii\base\BootstrapInterface
{
    public $controllerNamespace = 'PortalPeople\paygate\controllers';

    /** @var bool Set to true to register URL rules on bootstrap */
    public $registerRoutes = true;
    
    public function bootstrap($app)
    {
        $this->id = 'paygate';

        if (!isset($app->getModules()[$this->id])) {
            $app->setModule($this->id, $this);
        }

        $app->setComponents(["{$this->id}" => [
            'class' => 'PortalPeople\paygate\Module',
            'cartsClass' => 'backend\models\Cartsbe',
            'paymentResponsesClass' => 'backend\models\Paymentresponsesbe',
            'connection' => [
               'url' => Paygate::SANDBOX_URL,
            ]
        ]]);
        if($this->registerRoutes){
            $app->urlManager->addRules([
                [
                    'pattern' => 'v3/<controller:payments>/paygate',
                    'route' => "{$this->id}/<controller>/payment"
                ],
                [
                    'pattern' => 'v3/<controller:payments>/paygate-request',
                    'route' => "{$this->id}/<controller>/request"
                ]
            ], false);
        }
    }
}