Inheritance: extends EntityModel
 protected function meetsGatewayTypeLimits($gatewayTypeId)
 {
     if (!$gatewayTypeId) {
         return true;
     }
     $accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id', '=', $gatewayTypeId)->first();
     if ($accountGatewaySettings) {
         $invoice = $this->invoice();
         if ($accountGatewaySettings->min_limit !== null && $invoice->balance < $accountGatewaySettings->min_limit) {
             return false;
         }
         if ($accountGatewaySettings->max_limit !== null && $invoice->balance > $accountGatewaySettings->max_limit) {
             return false;
         }
     }
     return true;
 }
 /**
  * @return \Illuminate\Http\RedirectResponse
  */
 public function savePaymentGatewayLimits()
 {
     $gateway_type_id = intval(Input::get('gateway_type_id'));
     $gateway_settings = AccountGatewaySettings::scope()->where('gateway_type_id', '=', $gateway_type_id)->first();
     if (!$gateway_settings) {
         $gateway_settings = AccountGatewaySettings::createNew();
         $gateway_settings->gateway_type_id = $gateway_type_id;
     }
     $gateway_settings->min_limit = Input::get('limit_min_enable') ? intval(Input::get('limit_min')) : null;
     $gateway_settings->max_limit = Input::get('limit_max_enable') ? intval(Input::get('limit_max')) : null;
     if ($gateway_settings->max_limit !== null && $gateway_settings->min_limit > $gateway_settings->max_limit) {
         $gateway_settings->max_limit = $gateway_settings->min_limit;
     }
     $gateway_settings->save();
     event(new UserSettingsChanged());
     Session::flash('message', trans('texts.updated_settings'));
     return Redirect::to('settings/' . ACCOUNT_PAYMENTS);
 }
 public function actions()
 {
     $actions = [[uctrans('texts.resend_confirmation_email'), function ($model) {
         return $model->resendConfirmationUrl;
     }, function ($model) {
         return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->resendConfirmationUrl);
     }], [uctrans('texts.edit_gateway'), function ($model) {
         return URL::to("gateways/{$model->public_id}/edit");
     }, function ($model) {
         return !$model->deleted_at;
     }], [uctrans('texts.finish_setup'), function ($model) {
         return $model->setupUrl;
     }, function ($model) {
         return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->setupUrl);
     }], [uctrans('texts.manage_account'), function ($model) {
         $accountGateway = $this->getAccountGateway($model->id);
         $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/';
         return ['url' => $endpoint . 'account/' . $accountGateway->getConfig()->accountId, 'attributes' => 'target="_blank"'];
     }, function ($model) {
         return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY;
     }], [uctrans('texts.terms_of_service'), function ($model) {
         return 'https://go.wepay.com/terms-of-service-us';
     }, function ($model) {
         return $model->gateway_id == GATEWAY_WEPAY;
     }]];
     foreach (Cache::get('gatewayTypes') as $gatewayType) {
         $actions[] = [trans('texts.set_limits', ['gateway_type' => $gatewayType->name]), function () use($gatewayType) {
             $accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id', '=', $gatewayType->id)->first();
             $min = $accountGatewaySettings && $accountGatewaySettings->min_limit !== null ? $accountGatewaySettings->min_limit : 'null';
             $max = $accountGatewaySettings && $accountGatewaySettings->max_limit !== null ? $accountGatewaySettings->max_limit : 'null';
             return "javascript:showLimitsModal('{$gatewayType->name}', {$gatewayType->id}, {$min}, {$max})";
         }, function ($model) use($gatewayType) {
             // Only show this action if the given gateway supports this gateway type
             if ($model->gateway_id == GATEWAY_CUSTOM) {
                 return $gatewayType->id == GATEWAY_TYPE_CUSTOM;
             } else {
                 $accountGateway = $this->getAccountGateway($model->id);
                 $paymentDriver = $accountGateway->paymentDriver();
                 $gatewayTypes = $paymentDriver->gatewayTypes();
                 return in_array($gatewayType->id, $gatewayTypes);
             }
         }];
     }
     return $actions;
 }