$k; if ((static::getSavedNestedResources()->includes($k)) && ($v instanceof ApiResource)) { $v->saveWithParent = true; } return $v; } /** * @return ApiResource The refreshed resource. */ public function refresh() { $requestor = new ApiRequestor($this->_opts->apiKey, static::baseUrl()); $url = $this->instanceUrl(); list($response, $this->_opts->apiKey) = $requestor->request( 'get', $url, $this->_retrieveOptions, $this->_opts->headers ); $this->setLastResponse($response); $this->refreshFrom($response->json, $this->_opts); return $this; } /** * @return string The name of the class, with namespacing and underscores * stripped. */ public static function className() { $class = get_called_class(); // Useful for namespaces: Foo\Charge if ($postfixNamespaces = strrchr($class, '\\')) { $class = substr($postfixNamespaces, 1); } // Useful for underscored 'namespaces': Foo_Charge if ($postfixFakeNamespaces = strrchr($class, '')) { $class = $postfixFakeNamespaces; } if (substr($class, 0, strlen('Stripe')) == 'Stripe') { $class = substr($class, strlen('Stripe')); } $class = str_replace('_', '', $class); $name = urlencode($class); $name = strtolower($name); return $name; } /** * @return string The base URL for the given class. */ public static function baseUrl() { return Stripe::$apiBase; } /** * @return string The endpoint URL for the given class. */ public static function classUrl() { $base = static::className(); return "/v1/${base}s"; } /** * @return string The instance endpoint URL for the given class. */ public static function resourceUrl($id) { if ($id === null) { $class = get_called_class(); $message = "Could not determine which URL to request: " . "$class instance has invalid ID: $id"; throw new Error\InvalidRequest($message, null); } $id = Util\Util::utf8($id); $base = static::classUrl(); $extn = urlencode($id); return "$base/$extn"; } /** * @return string The full API URL for this API resource. */ public function instanceUrl() { return static::resourceUrl($this['id']); } }