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

class Module extends \yii\base\Module implements \yii\base\BootstrapInterface
{
    public $controllerNamespace = 'PortalPeople\paygate\controllers';
    
    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::productionUrl,
               'merchantcode' => '',
               'terminal' => '1',
               'currency' => '978',
               'transactiontype' => '0',
               'secret' => Paygate::Ds_KEY, 
            ]
        ]]);
        if($app->name == 'IonClubApi'){
            $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);
        }
    }
}