public function GetReportsResponse($requestParameters, $requestBody, $oauthRequestUri)
 {
     $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method");
     // This step is required since the configuration settings might have been changed.
     $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true);
     $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false);
     $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true);
     $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false);
     // Determine dest URI
     $requestUri = '';
     if ($requestParameters->ApiName) {
         // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu"
         $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName;
     } else {
         if ($oauthRequestUri) {
             // Prepare the request Uri from base Uri and resource Uri.
             $requestUri = $oauthRequestUri;
         } else {
             if ($requestParameters->ResourceUri) {
                 $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri;
             } else {
             }
         }
     }
     $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
     $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
     $oauth->enableDebug();
     $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
     $oauth->disableSSLChecks();
     $httpHeaders = array();
     if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) {
         // IDS call
         $httpHeaders = array('accept' => 'application/json');
         // Log Request Body to a file
         $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE);
         if ($this->ResponseCompressor) {
             $this->ResponseCompressor->PrepareDecompress($httpHeaders);
         }
     } else {
         // IPP call
         $httpHeaders = array('accept' => 'application/json');
     }
     try {
         $OauthMethod = OAUTH_HTTP_METHOD_GET;
         $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders);
     } catch (OAuthException $e) {
         //echo "ERROR:\n";
         //print_r($e->getMessage()) . "\n";
         list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
         $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
         return FALSE;
     }
     list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
     // Log Request Body to a file
     $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
     return array($response_code, $response_xml);
 }
Ejemplo n.º 2
0
 /**
  * Initializes a new instance of the RestHandler class.
  *
  * @param ServiceContext $context The Service Context
  */
 protected function __construct($context)
 {
     $this->serviceContext = $context;
     $this->RequestCompressor = CoreHelper::GetCompressor($this->serviceContext, true);
     $this->ResponseCompressor = CoreHelper::GetCompressor($this->serviceContext, false);
     $this->RequestSerializer = CoreHelper::GetSerializer($this->serviceContext, true);
     $this->ResponseSerializer = CoreHelper::GetSerializer($this->serviceContext, false);
     $this->RequestLogging = CoreHelper::GetRequestLogging($this->serviceContext);
 }
 /**
  * Initializes a new instance of the DataService class.
  *
  * @param ServiceContext $serviceContext IPP Service Context
  */
 public function __construct($serviceContext)
 {
     if (NULL == $serviceContext) {
         throw new ArgumentNullException('Resources.ServiceContextCannotBeNull');
     }
     if (!is_object($serviceContext)) {
         throw new InvalidParameterException('Wrong arg type passed - is not an object.');
     }
     //ServiceContextValidation(serviceContext);
     $this->serviceContext = $serviceContext;
     $this->responseSerializer = CoreHelper::GetSerializer($this->serviceContext, false);
     $this->restHandler = new SyncRestHandler($serviceContext);
     // Set the Service type to either QBO or QBD by calling a method.
     $this->serviceContext->UseDataServices();
 }
 /**
  * Returns the response by calling REST service.
  *
  * @param ServiceContext $requestParameters The parameters
  * @param string $requestBody The request body
  * @param string $oauthRequestUri The OAuth request uri
  * @return array elements are 0: HTTP response code; 1: HTTP response body
  */
 public function GetResponse($requestParameters, $requestBody, $oauthRequestUri)
 {
     $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method");
     // This step is required since the configuration settings might have been changed.
     $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true);
     $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false);
     $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true);
     $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false);
     // Determine dest URI
     $requestUri = '';
     if ($requestParameters->ApiName) {
         // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu"
         $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName;
     } else {
         if ($oauthRequestUri) {
             // Prepare the request Uri from base Uri and resource Uri.
             $requestUri = $oauthRequestUri;
         } else {
             if ($requestParameters->ResourceUri) {
                 $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri;
             } else {
             }
         }
     }
     //minorVersion support
     if ($this->context->minorVersion) {
         if ($this->queryToArray($requestUri) == false) {
             $requestUri .= "?minorversion=" . $this->context->minorVersion;
         } else {
             $requestUri .= "&minorversion=" . $this->context->minorVersion;
         }
     }
     $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
     $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
     $oauth->enableDebug();
     $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
     $oauth->disableSSLChecks();
     $httpHeaders = array();
     if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) {
         // IDS call
         $httpHeaders = array('host' => parse_url($requestUri, PHP_URL_HOST), 'user-agent' => CoreConstants::USERAGENT, 'accept' => '*/*', 'connection' => 'close', 'content-type' => $requestParameters->ContentType, 'content-length' => strlen($requestBody));
         // Log Request Body to a file
         $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE);
         if ($requestBody && $this->RequestCompressor) {
             $this->RequestCompressor->Compress($httpHeaders, $requestBody);
         }
         if ($this->ResponseCompressor) {
             $this->ResponseCompressor->PrepareDecompress($httpHeaders);
         }
     } else {
         // IPP call
         $httpHeaders = array('user-agent' => CoreConstants::USERAGENT);
     }
     try {
         if ('POST' == $requestParameters->HttpVerbType) {
             $OauthMethod = OAUTH_HTTP_METHOD_POST;
         } else {
             if ('GET' == $requestParameters->HttpVerbType) {
                 $OauthMethod = OAUTH_HTTP_METHOD_GET;
             }
         }
         $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders);
     } catch (OAuthException $e) {
         //echo "ERROR:\n";
         //print_r($e->getMessage()) . "\n";
         list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
         $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
         //echo "Response: {$response_code} - {$response_xml} \n";
         //var_dump($oauth->debugInfo);
         //echo "\n";
         //echo "ERROR MESSAGE: " . $oauth->debugInfo['body_recv'] . "\n"; // Useful info from Intuit
         //echo "\n";
         return FALSE;
     }
     list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
     // Log Request Body to a file
     $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
     return array($response_code, $response_xml);
 }
Ejemplo n.º 5
0
 /**
  * Setups serializers objects for responces and requests based on service context
  */
 public function setupSerializers()
 {
     $this->responseSerializer = CoreHelper::GetSerializer($this->serviceContext, false);
     $this->requestSerializer = CoreHelper::GetSerializer($this->serviceContext, true);
 }
Ejemplo n.º 6
0
 /**
  * Initializes a new instance of the Batch class.
  * @param $serviceContext The service context.
  * @param $restHandler The rest handler.
  */
 public function __construct($serviceContext, $restHandler)
 {
     $this->serviceContext = $serviceContext;
     $this->restHandler = $restHandler;
     $this->responseSerializer = CoreHelper::GetSerializer($this->serviceContext, false);
     $this->batchRequests = array();
     $this->batchResponses = array();
     $this->intuitBatchItemResponses = array();
 }