Пример #1
0
 public static function errorHandler($resp, $code)
 {
     $resp = json_decode($resp, true);
     $message = isset($resp['message']) ? $resp['message'] : null;
     $message_to_purchaser = isset($resp['message_to_purchaser']) ? $resp['message_to_purchaser'] : null;
     $type = isset($resp['type']) ? $resp['type'] : null;
     $params = isset($resp['param']) ? $resp['param'] : null;
     if (isset($code) != true || $code == 0) {
         throw new Conekta_NoConnectionError(Conekta_Lang::translate('error.requestor.connection', array('BASE' => Conekta::$apiBase), Conekta_Lang::EN), Conekta_Lang::translate('error.requestor.connection_purchaser', null, Conekta::$locale), $type, $code, $params);
     }
     switch ($code) {
         case 400:
             throw new Conekta_MalformedRequestError($message, $message_to_purchaser, $type, $code, $params);
         case 401:
             throw new Conekta_AuthenticationError($message, $message_to_purchaser, $type, $code, $params);
         case 402:
             throw new Conekta_ProcessingError($message, $message_to_purchaser, $type, $code, $params);
         case 404:
             throw new Conekta_ResourceNotFoundError($message, $message_to_purchaser, $type, $code, $params);
         case 422:
             throw new Conekta_ParameterValidationError($message, $message_to_purchaser, $type, $code, $params);
         case 500:
             throw new Conekta_ApiError($message, $message_to_purchaser, $type, $code, $params);
         default:
             throw new self($message, $message_to_purchaser, $type, $code, $params);
     }
 }
Пример #2
0
 public function instanceUrl()
 {
     $id = $this->id;
     if (!$id) {
         throw new Conekta_Error(Conekta_Lang::translate('error.resource.id', array('RESOURCE' => get_class()), Conekta_Lang::EN), Conekta_Lang::translate('error.resource.id_purchaser', null, Conekta::$locale));
     }
     $class = get_class($this);
     $base = $this->classUrl($class);
     $extn = urlencode($id);
     return "{$base}/{$extn}";
 }
Пример #3
0
 public function instanceUrl()
 {
     $id = $this->id;
     if (!$id) {
         throw new Conekta_Error(Conekta_Lang::translate('error.resource.id', array('RESOURCE' => get_class()), Conekta_Lang::EN), Conekta_Lang::translate('error.resource.id_purchaser', null, Conekta::$locale));
     }
     $class = get_class($this);
     $base = '/subscription';
     $customerUrl = $this->customer->instanceUrl();
     return "{$customerUrl}{$base}";
 }
Пример #4
0
 protected static function readDirectory($directory)
 {
     if (!empty(self::$cache)) {
         return self::$cache;
     }
     $langs = array();
     if ($handle = opendir($directory)) {
         while ($lang = readdir($handle)) {
             if (strpos($lang, '.php') !== false) {
                 $langKey = str_replace('.php', '', $lang);
                 $langs[$langKey] = (include $directory . '/' . $lang);
             }
         }
         closedir($handle);
     }
     self::$cache = $langs;
     return $langs;
 }
Пример #5
0
 public function testShouldTranslatesMessage()
 {
     $this->assertEqual('There was an error. Please contact system administrator.', Conekta_Lang::translate('error.resource.id_purchaser', null, Conekta_Lang::EN));
     $this->assertEqual('Hubo un error. Favor de contactar al administrador del sistema.', Conekta_Lang::translate('error.resource.id_purchaser', null, Conekta_Lang::ES));
 }