Exemple #1
0
 public static function updateSubscriptionIfExpired($userId = false)
 {
     if (!$userId) {
         $userId = \Auth::user()->id;
     }
     \Log::info(self::subscriptionLeftDays($userId));
     if (self::subscriptionLeftDays($userId) < 1) {
         UserTrialPeriod::where('user_id', $userId)->update(['expired' => 1]);
         // todo fire SubscriptionExpired event
     }
 }
Exemple #2
0
 /**
  * Format data for responses to requests.
  */
 public static function formatData($data, $success = true, $message = '', $status_code = 200)
 {
     $content = array('success' => $success, 'data' => $data, 'message' => $message);
     if ($status_code !== 200 && $message) {
         \Log::warning($message, array('status_code' => $status_code, 'data' => $data));
     }
     if ($status_code == 200 && $message) {
         \Log::info($message, array('status_code' => $status_code, 'data' => $data));
     }
     return response($content, $status_code)->header('Access-Control-Allow-Origin', '*');
 }
 /**
  * Log the api request that resulted in an error
  *
  * @param  object $response the apiClient response object
  * @param  object $request  the apiClient request object
  * @param  string $httpVerb GET | POST | PUT
  * @param  string $endpoint full url to endpoint
  * @param  array  $data     the data that was passed to the request
  * @return void
  */
 public function logError($response, $request, $httpVerb, $endpoint, $data)
 {
     // Info variables
     $code = null;
     $body = null;
     // Set info variables if we have a response from the api
     if ($response) {
         $code = $response->getStatusCode();
         $body = $response->getBody();
     }
     // Set message based on code error
     $message = 'API Response Error: ';
     switch ($code) {
         // Networking error
         case null:
             $message .= 'Could Not Make A Connection';
             break 1;
             // Server error
         // Server error
         case 500:
             $message .= 'Internal Server Error';
             break 1;
             // Server error
         // Server error
         case 503:
             $message .= 'Service Unavailable';
             break 1;
     }
     // Log this error
     \Log::error($message, ['code' => $code, 'body' => $body, 'httpVerb' => $httpVerb, 'endpoint' => $endpoint, 'data' => $data]);
     // 10.5.3 502 Bad Gateway
     // Translate api 500 error responses as 502's from the website
     if ($code === 500) {
         abort(502);
     }
     // "10.5.5 504 Gateway Timeout"
     // Show api communication error page
     // only for networking errors "null" to the api
     if ($code === null || $code === 503) {
         abort(504);
     }
 }