Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion SWServices/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Services {
private static $_expirationDate = null;
private static $_proxy = null;
private static $_timeSession = "PT2H";
private static $_timeOut = 60;

public function __construct($params) {
if(isset($params['url'])){
Expand All @@ -37,6 +38,9 @@ public function __construct($params) {
self::$_expirationDate = new \DateTime('NOW');
self::$_expirationDate->add(new \DateInterval(self::$_timeSession));
}
if(isset($params['_timeOut'])){
self::$_timeOut = $params['_timeOut'];
}
}

public static function get_token(){
Expand Down Expand Up @@ -75,7 +79,9 @@ public static function set_token($token){
public static function get_proxy(){
return self::$_proxy;
}

public static function get_timeout(){
return self::$_timeOut;
}

};

Expand Down
16 changes: 14 additions & 2 deletions SWServices/Stamp/StampRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SWServices\Stamp;
use Exception;
class StampRequest{
public static function sendReq($url, $token, $xml, $version, $proxy){
public static function sendReq($url, $token, $xml, $version, $proxy, $timeout=60){
$delimiter = '-------------' . uniqid();
$fileFields = array(
'xml' => array(
Expand Down Expand Up @@ -32,6 +32,12 @@ public static function sendReq($url, $token, $xml, $version, $proxy){
$curl = curl_init($url.'/cfdi33/stamp/'.$version);
curl_setopt($curl , CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl , CURLOPT_POST, true);

// TIMEOUT
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); // seconds
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); // seconds
// END TIMEOUT

if(isset($proxy)){
curl_setopt($curl , CURLOPT_PROXY, $proxy);
}
Expand All @@ -56,7 +62,7 @@ public static function sendReq($url, $token, $xml, $version, $proxy){
}


public static function sendReqB64($url, $token, $xml, $version){
public static function sendReqB64($url, $token, $xml, $version, $timeout=60){
$delimiter = '-------------' . uniqid();
$fileFields = array(
'xml' => array(
Expand Down Expand Up @@ -85,6 +91,12 @@ public static function sendReqB64($url, $token, $xml, $version){
$curl = curl_init($url.'/cfdi33/stamp/'.$version.'/b64');
curl_setopt($curl , CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl , CURLOPT_POST, true);

// TIMEOUT
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // seconds
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // seconds
// END TIMEOUT

curl_setopt($curl , CURLOPT_HTTPHEADER , array(
'Content-Type: multipart/form-data; boundary=' . $delimiter,
'Content-Length: ' . strlen($data),
Expand Down
14 changes: 7 additions & 7 deletions SWServices/Stamp/StampService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ public static function Set($params){
return new StampService($params);
}
public static function StampV1($xml){
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v1",Services::get_proxy());
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v1",Services::get_proxy(),Services::get_default_timeout());
}
public static function StampV2($xml, $isb64 = false){
if($isb64){
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v2",Services::get_proxy());
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v2",Services::get_proxy(),Services::get_default_timeout());
}
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v2",Services::get_proxy());
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v2",Services::get_proxy(),Services::get_default_timeout());
}

public static function StampV3($xml, $isb64 = false){
if($isb64){
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v3",Services::get_proxy());
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v3",Services::get_proxy(),Services::get_default_timeout());
}
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v3",Services::get_proxy());
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v3",Services::get_proxy(),Services::get_default_timeout());
}
public static function StampV4($xml, $isb64 = false){
if($isb64){
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v4",Services::get_proxy());
return stampRequest::sendReqB64(Services::get_url(), Services::get_token(), $xml, "v4",Services::get_proxy(),Services::get_default_timeout());
}
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v4",Services::get_proxy());
return stampRequest::sendReq(Services::get_url(), Services::get_token(), $xml, "v4",Services::get_proxy(),Services::get_default_timeout());
}
}

Expand Down