/** * Get client data for Basic Access Authentication * @param string $clientId Client identifier * @param string $clientName Beautiful name for presentation * @param string $clientEmail Client's email * @return \MangoPay\Client Client object */ public function Create($clientId, $clientName, $clientEmail) { $urlMethod = $this->GetRequestUrl('authentication_base'); $requestType = $this->GetRequestType('authentication_base'); $requestData = array('ClientId' => $clientId, 'Name' => $clientName, 'Email' => $clientEmail); $rest = new RestTool(false, $this->_root); $response = $rest->Request($urlMethod, $requestType, $requestData); return $this->CastResponseToEntity($response, '\\MangoPay\\Client'); }
/** * Get token information to OAuth Authentication * @return \MangoPay\Libraries\OAuthToken OAuthToken object with token information */ public function CreateToken() { $urlMethod = $this->GetRequestUrl('authentication_oauth'); $requestType = $this->GetRequestType('authentication_oauth'); $requestData = array('grant_type' => 'client_credentials'); $rest = new RestTool(false, $this->_root); $authHlp = new AuthenticationHelper($this->_root); $urlDetails = parse_url($this->_root->Config->BaseUrl); $rest->AddRequestHttpHeader('Host: ' . @$urlDetails['host']); $rest->AddRequestHttpHeader('Authorization: Basic ' . $authHlp->GetHttpHeaderBasicKey()); $rest->AddRequestHttpHeader('Content-Type: application/x-www-form-urlencoded'); $response = $rest->Request($urlMethod, $requestType, $requestData); return $this->CastResponseToEntity($response, '\\MangoPay\\Libraries\\OAuthToken'); }
/** * Save object in API * @param string $methodKey Key with request data * @param object $entity Entity object to save * @param object $responseClassName Name of entity class from response * @return object Response data */ protected function SaveObject($methodKey, $entity, $responseClassName = null, $secondEntityId = null) { if (is_null($secondEntityId)) { $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entity->Id); } else { $urlMethod = sprintf($this->GetRequestUrl($methodKey), $secondEntityId, $entity->Id); } $requestData = $this->BuildRequestData($entity); $rest = new RestTool(true, $this->_root); $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData); if (!is_null($responseClassName)) { return $this->CastResponseToEntity($response, $responseClassName); } return $response; }