Skip to content

Instantly share code, notes, and snippets.

@miguelius
Last active September 10, 2016 15:36
Show Gist options
  • Save miguelius/54b14f64eb0efeeac05ea840790598d3 to your computer and use it in GitHub Desktop.
Save miguelius/54b14f64eb0efeeac05ea840790598d3 to your computer and use it in GitHub Desktop.
Cliente para afip
<?php
class AFIPClient extends SoapClient {
protected function callCurl($url, $data, $action) {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", 'SOAPAction: "' . $action . '"'));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
$response = curl_exec($handle);
if (empty($response)) {
Logger::log(curl_error($handle));
throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle));
}
curl_close($handle);
return $response;
}
public function __doRequest($request,$location,$action,$version,$one_way = 0) {
return $this->callCurl($location, $request, $action);
}
public static function newInstance($url, $options) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
$temp_file = tempnam(sys_get_temp_dir(), 'wsdl');
$fp = fopen($temp_file, 'w+');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
curl_close ($ch);
fclose($fp);
return new AFIPClient($temp_file, $options);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment