/**
  * @author WN
  * @param string $installation
  * @return Installation
  */
 protected function fetchInstallationByExternalId($installation)
 {
     $inst = Installation::where('ext_id', $installation)->get();
     if (count($inst) == 1) {
         return $inst[0];
     }
     throw new ModelNotFoundException('Installation ' . $installation . ' not found.');
 }
Ejemplo n.º 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $installations = Installation::where('active', true);
     if ($this->auth->user() && $this->auth->user()->merchant_id) {
         view()->share('available_installations', $installations->where('merchant_id', $this->auth->user()->merchant_id)->get());
     } else {
         view()->share('available_installations', $installations->get());
     }
     return $next($request);
 }
 /**
  * @author WN
  * @param int $merchantId
  * @return array
  * @throws \Exception
  */
 public function synchroniseAllInstallations($merchantId)
 {
     $rtn = [];
     $merchant = $this->fetchMerchantLocalObject($merchantId);
     $localInstallations = Installation::where('merchant_id', '=', $merchantId)->get();
     try {
         $externalInstallations = $this->installationGateway->getInstallations($merchant->token);
     } catch (\Exception $e) {
         $this->logError('InstallationSynchronisationService failed while fetching for Merchant[' . $merchantId . ']:' . $e->getMessage());
         throw $e;
     }
     $rtn['current'] = $this->synchroniseCurrentInstallations($localInstallations);
     $rtn['new'] = $this->synchroniseNewInstallations($externalInstallations, $localInstallations, $merchantId);
     $rtn['unlinked'] = $this->unlinkRestInstallations($localInstallations);
     return $rtn;
 }
Ejemplo n.º 4
0
 /**
  * @author WN
  * @param Builder $query
  */
 protected function limitToInstallationOnMerchant(Builder $query)
 {
     if (\Auth::user()->merchant_id) {
         $query->whereIn('installation_id', Installation::where('merchant_id', \Auth::user()->merchant_id)->get()->pluck('id')->all());
     }
 }