Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
add example: how to retrieve a PDF invoice from Collmex
  • Loading branch information
mjaschen committed Nov 26, 2024
1 parent 22c5721 commit 245b90c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ return [

### Fetch from Collmex API

Load a Collmex *Customer* record:
#### Load a Collmex *Customer* record:

```php
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
Expand Down Expand Up @@ -164,6 +164,34 @@ foreach ($records as $record) {
var_dump($collmexResponse->getResponseRaw());
```

#### Fetch a PDF Invoice from Collmex

```php
use MarcusJaschen\Collmex\Client\Curl as CurlClient;
use MarcusJaschen\Collmex\Request;
use MarcusJaschen\Collmex\Type\InvoiceGet;

$collmexRequest = new Request(new CurlClient('USER', 'PASSWORD', 'CUSTOMER_ID'));
$getInvoice = new InvoiceGet(['invoice_id' => '1', 'format' => InvoiceGet::FORMAT_ZIP]);

try {
$collmexResponse = $collmexRequest->send($getInvoice->getCsv());
} catch (\Exception) {
// Error Handling ...
}

/** @var \Symfony\Component\Finder\Finder $files */
$files = $collmexResponse->getFilesByType(type: 'pdf');

/** @var SplFileInfo $file */
foreach ($files as $file) {
$pdfContent = file_get_contents($file->getPathname());
// save, mail, display, etc.
break;
}
```


### Send Data to Collmex

Create a new Collmex *Customer* record and get the Collmex customer ID from the response data:
Expand Down

0 comments on commit 245b90c

Please sign in to comment.