/** * Make a request to the API * * @param string $method The request method to use * @param string $endpoint The API endpoint to call * @param string $params The parameters to send with the request * * @return object The returned object */ public function request($method, $endpoint, $params = array()) { // If there is no http_authorization, try checking for access_token if (!isset($params['http_authorization'])) { // No http_authorization and no access_token? Fail if (!isset($this->account_details['access_token'])) { throw new GoCardless_ClientException('Access token missing'); } // access_token found so set Authorization header to contain bearer $params['http_bearer'] = $this->account_details['access_token']; } // Set application specific user agent suffix if found if (isset($this->account_details['ua_tag'])) { $params['ua_tag'] = $this->account_details['ua_tag']; } if (substr($endpoint, 0, 6) == '/oauth') { // OAuth API calls don't require /api/v1 base $url = $this->base_url . $endpoint; } else { // http://sandbox.gocardless.com | /api/v1 | /test $url = $this->base_url . self::$api_path . $endpoint; } // Call Request class (might be aliased for testing) with URL & params return call_user_func(GoCardless::getClass('Request') . '::' . $method, $url, $params); }