Skip to content

Commit

Permalink
Add sales invoice attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvw committed Sep 16, 2017
1 parent 47d09a7 commit 72ece22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
29 changes: 28 additions & 1 deletion src/Picqer/Financials/Moneybird/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,34 @@ public function delete($url)
}
}

/**
* @param string $method
* @param string $url
* @param array $options
*/
public function request($method, $url, $options)
{
$headers = [];

// If access token is not set or token has expired, acquire new token
if (empty($this->accessToken)) {
$this->acquireAccessToken();
}

// If we have a token, sign the request
if (!empty($this->accessToken)) {
$headers['Authorization'] = 'Bearer ' . $this->accessToken;
}

$options['headers'] = $headers;

try {
$this->client()->request($method, $this->formatUrl($url, 'post'), $options);
} catch (Exception $e) {
$this->parseExceptionForErrorMessages($e);
}
}

/**
* @return string
*/
Expand Down Expand Up @@ -482,6 +510,5 @@ public function setScopes($scopes)
{
$this->scopes = $scopes;
}

}

21 changes: 18 additions & 3 deletions src/Picqer/Financials/Moneybird/Entities/SalesInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function sendInvoice($deliveryMethod = 'Email')
'delivery_method' => $deliveryMethod
]
]));

return $this;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public function registerPayment(SalesInvoicePayment $salesInvoicePayment)
$this->connection()->patch($this->endpoint . '/' . $this->id . '/register_payment',
$salesInvoicePayment->jsonWithNamespace()
);

return $this;
}

Expand All @@ -169,7 +169,7 @@ public function addNote(Note $note)
$this->connection()->post($this->endpoint . '/' . $this->id . '/notes',
$note->jsonWithNamespace()
);

return $this;
}

Expand All @@ -186,4 +186,19 @@ public function duplicateToCreditInvoice()

return $this->makeFromResponse($response);
}

/**
* @param string $file
*/
public function addAttachment($file)
{
$this->connection()->request('post', $this->endpoint . '/' . $this->id . '/attachments', [
'multipart' => [
[
'name' => 'file',
'contents' => fopen($file, 'r'),
],
]
]);
}
}

0 comments on commit 72ece22

Please sign in to comment.