示例#1
0
 protected function _http($Context, $url_path, $raw_body)
 {
     $method = 'GET';
     if ($raw_body) {
         $method = 'POST';
     }
     $url = $this->_getBaseURL() . $url_path;
     $authcreds = $Context->authcreds();
     $params = array();
     $OAuth = new QuickBooks_IPP_OAuth($this->_oauth_consumer_key, $this->_oauth_consumer_secret);
     $signed = $OAuth->sign($method, $url, $authcreds['oauth_access_token'], $authcreds['oauth_access_token_secret'], $params);
     //print_r($signed);
     $HTTP = new QuickBooks_HTTP($signed[2]);
     $headers = array('Content-Type' => 'application/json', 'Request-Id' => QuickBooks_Utilities::GUID());
     $HTTP->setHeaders($headers);
     // Turn on debugging for the HTTP object if it's been enabled in the payment processor
     $HTTP->useDebugMode($this->_debug);
     //
     $HTTP->setRawBody($raw_body);
     $HTTP->verifyHost(false);
     $HTTP->verifyPeer(false);
     if ($method == 'POST') {
         $return = $HTTP->POST();
     } else {
         if ($method == 'GET') {
             $return = $HTTP->GET();
         } else {
             $return = null;
             // ERROR
         }
     }
     $this->_last_request = $HTTP->lastRequest();
     $this->_last_response = $HTTP->lastResponse();
     //
     $this->log($HTTP->getLog(), QUICKBOOKS_LOG_DEBUG);
     $info = $HTTP->lastInfo();
     print "Info: ";
     print_r($info);
     $errnum = $HTTP->errorNumber();
     $errmsg = $HTTP->errorMessage();
     if ($errnum) {
         // An error occurred!
         $this->_setError(QuickBooks_Payments::ERROR_HTTP, $errnum . ': ' . $errmsg);
         return false;
     }
     if ($info['http_code'] == 401) {
         $this->_setError(QuickBooks_Payments::ERROR_AUTH, 'Payments return a 401 Unauthorized status.');
         return false;
     }
     // Everything is good, return the data!
     $this->_setError(QuickBooks_Payments::ERROR_OK, '');
     return $return;
 }