/**
  * This url is called when a SEOshop customer installs this application
  *
  * @param Request $request
  * @return \Illuminate\View\View
  * @throws \Exception
  */
 public function install(Request $request)
 {
     // Make sure we have received all required information
     $this->validate($request, ['language' => 'required', 'shop_id' => 'required', 'signature' => 'required', 'timestamp' => 'required', 'token' => 'required']);
     // Validate the signature
     $signature = '';
     $input = $request->except('signature');
     ksort($input);
     // Construct the signature
     foreach ($input as $key => $value) {
         $signature .= $key . '=' . $value;
     }
     // The signature contains the app secret
     $signature = md5($signature . config('services.seoshop.secret'));
     // Do the signatures match?
     if ($signature != $request->input('signature')) {
         throw new \Exception('The signature does not match. You haven\'t secretly tampered with it no?');
     }
     // Find or create the user
     $shop = Shop::firstOrNew(array('shop_id' => $request->input('shop_id')));
     $shop->language = $request->input('language');
     $shop->token = $request->input('token');
     $shop->save();
     // Authenticate the user
     Auth::loginUsingId($shop->id);
     // Create the external services
     Webshop::instance()->installExternalServices();
     // Were done here
     return redirect('dashboard');
 }
Ejemplo n.º 2
0
 /**
  * This method will fetch the current external services
  * If these do not exist yet it will create them
  */
 public function installExternalServices()
 {
     $currentServices = Webshop::instance()->external_services->get();
     $hasShipmentService = false;
     $hasPaymentService = false;
     foreach ($currentServices as $currentService) {
         if ($currentService['type'] == 'shipment') {
             $hasShipmentService = true;
         }
         if ($currentService['type'] == 'payment') {
             $hasPaymentService = true;
         }
     }
     if ($hasShipmentService === false) {
         Webshop::instance()->external_services->create(['type' => 'shipment', 'name' => 'My Awesome Shipping Service', 'urlEndpoint' => url('/', [], true), 'rateEstimate' => true, 'isActive' => true]);
     }
     if ($hasPaymentService === false) {
         Webshop::instance()->external_services->create(['type' => 'payment', 'name' => 'My Awesome Payment Service', 'urlEndpoint' => url('/', [], true), 'isActive' => true]);
     }
 }