Skip to content

Commit bbe829a

Browse files
committed
Change API version to v2
1 parent d3b6724 commit bbe829a

File tree

10 files changed

+63
-25
lines changed

10 files changed

+63
-25
lines changed

src/Facturapi.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class Facturapi {
3636
public $Retentions;
3737
public $Tools;
3838

39-
public function __construct( $api_key ) {
40-
$this->Customers = new Customers( $api_key );
41-
$this->Organizations = new Organizations( $api_key );
42-
$this->Products = new Products( $api_key );
43-
$this->Invoices = new Invoices( $api_key );
44-
$this->Receipts = new Receipts( $api_key );
45-
$this->Catalogs = new Catalogs( $api_key );
46-
$this->Retentions = new Retentions( $api_key );
47-
$this->Tools = new Tools( $api_key );
39+
public function __construct( $api_key, $api_version = 'v2' ) {
40+
$this->Customers = new Customers( $api_key, $api_version );
41+
$this->Organizations = new Organizations( $api_key, $api_version );
42+
$this->Products = new Products( $api_key, $api_version );
43+
$this->Invoices = new Invoices( $api_key, $api_version );
44+
$this->Receipts = new Receipts( $api_key, $api_version );
45+
$this->Catalogs = new Catalogs( $api_key, $api_version );
46+
$this->Retentions = new Retentions( $api_key, $api_version );
47+
$this->Tools = new Tools( $api_key, $api_version );
4848
}
4949
}

src/Http/BaseClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BaseClient {
88
// BaseClient class to be extended by specific clients
99
protected $FACTURAPI_KEY;
1010
protected $ENDPOINT;
11-
protected $API_VERSION;
11+
protected $API_VERSION = 'v2';
1212
protected $BASE_URL = 'https://www.facturapi.io/';
1313
/**
1414
* The HTTP status of the most recent request
@@ -38,8 +38,9 @@ class BaseClient {
3838
*
3939
* @param $FACTURAPI_KEY : String value of Facturapi API Key for requests
4040
*/
41-
public function __construct( $FACTURAPI_KEY ) {
41+
public function __construct( $FACTURAPI_KEY, $API_VERSION = 'v2' ) {
4242
$this->FACTURAPI_KEY = base64_encode( $FACTURAPI_KEY . ":" );
43+
$this->API_VERSION = $API_VERSION;
4344
}
4445

4546
/**

src/Resources/Catalogs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
class Catalogs extends BaseClient {
99
protected $ENDPOINT = 'catalogs';
10-
protected $API_VERSION = 'v1';
11-
1210

1311
/**
1412
* Search a product key in SAT's catalog

src/Resources/Customers.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Customers extends BaseClient {
99
protected $ENDPOINT = 'customers';
10-
protected $API_VERSION = 'v1';
1110

1211
/**
1312
* Get all Customers

src/Resources/Invoices.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Invoices extends BaseClient {
99
protected $ENDPOINT = 'invoices';
10-
protected $API_VERSION = 'v1';
1110

1211

1312
/**

src/Resources/Organizations.php

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
class Organizations extends BaseClient
99
{
1010
protected $ENDPOINT = 'organizations';
11-
protected $API_VERSION = 'v1';
1211

1312

1413
/**
@@ -211,20 +210,66 @@ public function uploadCertificate($id, $params)
211210
}
212211

213212
/**
214-
* Get the Api Keys for an Organization
213+
* Get the Test Api Key for an Organization
215214
*
216215
* @param id : Unique ID for Organization
217216
*
218-
* @return JSON object for requested Organization
217+
* @return String Test Api Key
218+
*
219+
* @throws Facturapi_Exception
220+
**/
221+
public function getTestApiKey($id)
222+
{
223+
try {
224+
return json_decode($this->execute_get_request($this->get_request_url($id) . "/apikeys/test"));
225+
} catch (Facturapi_Exception $e) {
226+
throw new Facturapi_Exception('Unable to get organization\'s test key: ' . $e);
227+
}
228+
}
229+
230+
/**
231+
* Renews the Test Api Key for an Organization and makes the previous one inactive
232+
*
233+
* @param id : Unique ID for Organization
234+
*
235+
* @return String Test Api Key
219236
*
220237
* @throws Facturapi_Exception
221238
**/
222-
public function getApiKeys($id)
239+
public function renewTestApiKey($id)
223240
{
224241
try {
225-
return json_decode($this->execute_get_request($this->get_request_url($id) . "/apikeys"));
242+
return json_decode(
243+
$this->execute_JSON_put_request(
244+
$this->get_request_url($id) . "/apikeys/test",
245+
[]
246+
)
247+
);
248+
} catch (Facturapi_Exception $e) {
249+
throw new Facturapi_Exception('Unable to renew organization\'s test key: ' . $e);
250+
}
251+
}
252+
253+
/**
254+
* Renews the Test Api Key for an Organization and makes the previous one inactive
255+
*
256+
* @param id : Unique ID for Organization
257+
*
258+
* @return String Live Api Key
259+
*
260+
* @throws Facturapi_Exception
261+
**/
262+
public function renewLiveApiKey($id)
263+
{
264+
try {
265+
return json_decode(
266+
$this->execute_JSON_put_request(
267+
$this->get_request_url($id) . "/apikeys/live",
268+
[]
269+
)
270+
);
226271
} catch (Facturapi_Exception $e) {
227-
throw new Facturapi_Exception('Unable to get organization\'s api keys: ' . $e);
272+
throw new Facturapi_Exception('Unable to renew organization\'s live key: ' . $e);
228273
}
229274
}
230275

src/Resources/Products.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Products extends BaseClient {
99
protected $ENDPOINT = 'products';
10-
protected $API_VERSION = 'v1';
1110

1211

1312
/**

src/Resources/Receipts.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Receipts extends BaseClient {
99
protected $ENDPOINT = 'receipts';
10-
protected $API_VERSION = 'v1';
1110

1211

1312
/**

src/Resources/Retentions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Retentions extends BaseClient {
99
protected $ENDPOINT = 'retentions';
10-
protected $API_VERSION = 'v1';
1110

1211

1312
/**

src/Resources/Tools.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Tools extends BaseClient {
99
protected $ENDPOINT = 'tools';
10-
protected $API_VERSION = 'v1';
1110

1211

1312
/**

0 commit comments

Comments
 (0)