Skip to content

Commit

Permalink
Merge pull request #32 from FacturAPI/fix/post_with_body_null
Browse files Browse the repository at this point in the history
fix(execute_post): accept and validate nullish body in execute post m…
  • Loading branch information
raul-facturapi authored Aug 30, 2024
2 parents 957765b + ecf9d7e commit f6e64ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Http/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ protected function execute_post_request($url, $body, $formenc = false)
*
* @throws Facturapi_Exception
*/
protected function execute_JSON_post_request($url, $body)
protected function execute_JSON_post_request($url, $body = null)
{
$headers[] = 'Authorization: Basic ' . $this->FACTURAPI_KEY;
$headers[] = 'Content-Type: application/json';

// initialize cURL and send POST data
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body ? json_encode($body) : null);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ public function update_draft( $id, $body ) {
* @param query : URL query params
* @return JSON Stamped Invoice object
* @throws Facturapi_Exception
*/
public function stamp_draft( $id, $query ) {
*/
public function stamp_draft( $id, $query = null ) {
try {
return json_decode( $this->execute_JSON_post_request( $this->get_request_url( $id . "/stamp", $query ), null ) );
return json_decode( $this->execute_JSON_post_request( $this->get_request_url( $id . "/stamp", $query ) ) );
} catch ( Facturapi_Exception $e ) {
throw new Facturapi_Exception( 'Unable to stamp draft: ' . $e );
}
Expand Down

0 comments on commit f6e64ae

Please sign in to comment.