private function encodeToJson($arr)
 {
     $encoded = json_encode($arr);
     if (mb_detect_encoding($encoded, 'UTF-8', true) != 'UTF-8') {
         $encoded = utf8_encode($encoded);
     }
     OpenpayConsole::debug('JSON UTF8 string: ' . $encoded);
     return $encoded;
 }
 protected function refreshData($data)
 {
     OpenpayConsole::trace('OpenpayApiResourceBase @refreshData');
     if (!$data) {
         return $this;
     }
     if (!is_array($data)) {
         throw new OpenpayApiError("Invalid data received for processing, cannot update the Openpay resource");
     }
     // unsets the unused attributes
     $removed = array_diff(array_keys($this->serializableData), array_keys($data));
     if (count($removed)) {
         OpenpayConsole::debug('OpenpayApiResourceBase @refreshData > removing unused data');
         foreach ($removed as $k) {
             if ($this->serializableData[$k]) {
                 unset($this->serializableData[$k]);
             }
             if ($this->noSerializableData[$k]) {
                 $this->noSerializableData[$k] = null;
             }
             if ($this->derivedResources[$k]) {
                 //$this->derivedResources[$k] = null;
             }
         }
     }
     foreach ($data as $k => $v) {
         $k = strtolower($k);
         $value = $this->processAttribute($k, $v);
         if ($k == 'id') {
             if (!isset($this->id)) {
                 $this->id = $v;
             }
             continue;
             // by default, only protected vars & serializable data will be refresh
             // in this version, noSerializableData does not store any value
         } else {
             if (property_exists($this, $k)) {
                 $this->{$k} = $value;
                 //if ($this->noSerializableData[$k]) {
                 //	$this->noSerializableData[$k] = $value;
                 //}
             } else {
                 $this->serializableData[$k] = $value;
             }
         }
     }
     return $this;
 }