/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $data = $this->csv_to_array(base_path() . '/database/seeds/csv_files/payment_processors.csv');
     foreach ($data as $d) {
         $url = $d['url'];
         try {
             $meta = new WebsiteMeta($url);
             $payment_processor = new PaymentProcessor(['name' => $d['name'], 'url' => $url, 'meta_title' => $meta->title(), 'meta_description' => $meta->description(), 'meta_keywords' => $meta->keywords()]);
             $payment_processor->save();
         } catch (Exception $e) {
             error_log($e->getMessage() . "<br>" . 'The URL "' . $url . '" does not exist or is experiencing technical issues.');
         }
     }
 }
 /**
  * A function to retrieve all faucets associated with a
  * payment processor.
  *
  * @param $paymentProcessorSlug
  * @return array|null
  */
 public function paymentProcessorFaucets($paymentProcessorSlug)
 {
     try {
         //Obtain payment processor by related slug.
         $paymentProcessor = PaymentProcessor::findBySlug($paymentProcessorSlug);
         // Use model relationship to obtain associated faucets
         $faucets = $paymentProcessor->faucets;
         $activeFaucets = [];
         // Iterate over all related faucets,
         // obtaining only ones that are active.
         foreach ($faucets as $f) {
             if ($f->is_paused == false && $f->has_low_balance == false) {
                 array_push($activeFaucets, $f);
             }
         }
         return $activeFaucets;
     } catch (Exception $e) {
         return null;
     }
 }
 /**
  * Show the form for editing the specified faucet.
  *
  * @param $slug
  * @return Response
  */
 public function edit($slug)
 {
     try {
         //Grab the faucet to edit
         $faucet = Faucet::findBySlugOrId($slug);
         //Obtain payment processors associated with the faucet.
         $paymentProcessors = PaymentProcessor::lists('name', 'id');
         $faucetPaymentProcessors = $faucet->payment_processors;
         //Retrieve ids of associated payment processors,
         //and putting them into an array.
         $paymentProcessorIds = [];
         foreach ($faucetPaymentProcessors as $paymentProcessor) {
             array_push($paymentProcessorIds, (int) $paymentProcessor->id);
         }
         $submitButtonText = "Submit Changes";
         //Return the faucets edit view, with fields pre-populated.
         return view('faucets.edit', compact('faucet', 'paymentProcessors', 'paymentProcessorIds', 'submitButtonText'));
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
 }
 /**
  * Create and download payment processors data as CSV file.
  */
 public function getPaymentProcessorsData()
 {
     $paymentProcessors = PaymentProcessor::all();
     $this->createCsv($paymentProcessors, 'payment_processors');
 }
 public function faucets($paymentProcessorSlug)
 {
     try {
         $paymentProcessor = PaymentProcessor::findBySlugOrId($paymentProcessorSlug);
         $faucets = $paymentProcessor->faucets;
         $activeFaucets = [];
         foreach ($faucets as $f) {
             if ($f->is_paused == false && $f->has_low_balance == false) {
                 array_push($activeFaucets, $f);
             }
         }
         return view('payment_processors.rotator.index', compact('paymentProcessor', 'activeFaucets', 'paymentProcessorSlug'));
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
 }