Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add downloadable attachment option (as mentioned in the changelog per 2023-07-27) #286

Merged
Merged
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
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Estimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class Estimate extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => EstimateAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'custom_fields' => [
'entity' => SalesInvoiceCustomField::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
16 changes: 16 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/EstimateAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class EstimateAttachment.
*/
class EstimateAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'estimates';
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class ExternalSalesInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => ExternalSalesInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => ExternalSalesInvoiceDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class ExternalSalesInvoiceAttachment.
*/
class ExternalSalesInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'external_sales_invoices';
}
10 changes: 10 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/GeneralDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ class GeneralDocument extends Model
* @var string
*/
protected $namespace = 'general_document';

/**
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => GeneralDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class GeneralDocumentAttachment.
*/
class GeneralDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/general_documents';
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class GeneralJournalDocument extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => GeneralJournalDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'general_journal_document_entries' => [
'entity' => GeneralJournalDocumentEntry::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class GeneralJournalDocumentAttachment.
*/
class GeneralJournalDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/general_journal_documents';
}
46 changes: 46 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Generic/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Picqer\Financials\Moneybird\Entities\Generic;

use Picqer\Financials\Moneybird\Model;

/**
* Class InvoiceDetail.
*/
abstract class Attachment extends Model
{
/**
* @var string
*/
protected $attachmentPath = 'attachments';

/**
* @var array
*/
protected $fillable = [
'id',
'administration_id',
'attachable_id',
'attachable_type',
'filename',
'content_type',
'size',
'rotation',
'created_at',
'updated_at',
];

/**
* Download the file.
*
* @return string file data
*
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
*/
public function download()
{
$response = $this->connection()->download($this->getEndpoint() . '/' . urlencode($this->attachable_id) . '/' . $this->attachmentPath . '/' . urlencode($this->id) . '/download');

return $response->getBody()->getContents();
}
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/PurchaseInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class PurchaseInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => PurchaseInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => PurchaseInvoiceDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class SalesInvoiceAttachment.
*/
class PurchaseInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/purchase_invoices';
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class Receipt extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => ReceiptAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'details' => [
'entity' => ReceiptDetail::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
16 changes: 16 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/ReceiptAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class ReceiptAttachment.
*/
class ReceiptAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/receipts';
}
4 changes: 4 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/SalesInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class SalesInvoice extends Model
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => SalesInvoiceAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
'custom_fields' => [
'entity' => SalesInvoiceCustomField::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class SalesInvoiceAttachment.
*/
class SalesInvoiceAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'sales_invoices';
}
10 changes: 10 additions & 0 deletions src/Picqer/Financials/Moneybird/Entities/TypelessDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ class TypelessDocument extends Model
* @var string
*/
protected $namespace = 'typeless_document';

/**
* @var array
*/
protected $multipleNestedEntities = [
'attachments' => [
'entity' => TypelessDocumentAttachment::class,
'type' => self::NESTING_TYPE_ARRAY_OF_OBJECTS,
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Picqer\Financials\Moneybird\Entities;

use Picqer\Financials\Moneybird\Entities\Generic\Attachment;

/**
* Class TypelessDocumentAttachment.
*/
class TypelessDocumentAttachment extends Attachment
{
/**
* @var string
*/
protected $endpoint = 'documents/typeless_documents';
}