From 3dfb91d8edb2e2c9e82889a335ab7e510ddfcaa1 Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Wed, 18 Jan 2017 16:46:44 +0100 Subject: [PATCH] add PurchaseInvoicePayment --- .../Entities/Generic/InvoicePayment.php | 34 +++++++++++++++++++ .../Moneybird/Entities/PurchaseInvoice.php | 22 ++++++++++++ .../Entities/PurchaseInvoicePayment.php | 11 ++++++ .../Entities/SalesInvoicePayment.php | 31 +++-------------- src/Picqer/Financials/Moneybird/Moneybird.php | 10 ++++++ 5 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 src/Picqer/Financials/Moneybird/Entities/Generic/InvoicePayment.php create mode 100644 src/Picqer/Financials/Moneybird/Entities/PurchaseInvoicePayment.php diff --git a/src/Picqer/Financials/Moneybird/Entities/Generic/InvoicePayment.php b/src/Picqer/Financials/Moneybird/Entities/Generic/InvoicePayment.php new file mode 100644 index 0000000..71d1a9a --- /dev/null +++ b/src/Picqer/Financials/Moneybird/Entities/Generic/InvoicePayment.php @@ -0,0 +1,34 @@ + self::NESTING_TYPE_ARRAY_OF_OBJECTS, ], ]; + + /** + * Register a payment for the current purchase invoice + * + * @param PurchaseInvoicePayment $purchaseInvoicePayment (payment_date and price are required) + * @throws ApiException + */ + public function registerPayment(PurchaseInvoicePayment $purchaseInvoicePayment) + { + if (! isset($purchaseInvoicePayment->payment_date)) { + throw new ApiException('Required [payment_date] is missing'); + } + + if (! isset($purchaseInvoicePayment->price)) { + throw new ApiException('Required [price] is missing'); + } + + $this->connection()->patch($this->endpoint . '/' . $this->id . '/register_payment', + $purchaseInvoicePayment->jsonWithNamespace() + ); + } + } diff --git a/src/Picqer/Financials/Moneybird/Entities/PurchaseInvoicePayment.php b/src/Picqer/Financials/Moneybird/Entities/PurchaseInvoicePayment.php new file mode 100644 index 0000000..b6fd25c --- /dev/null +++ b/src/Picqer/Financials/Moneybird/Entities/PurchaseInvoicePayment.php @@ -0,0 +1,11 @@ +connection, $attributes); } + /** + * @param array $attributes + * @return PurchaseInvoicePayment + */ + public function purchaseInvoicePayment($attributes = []) + { + return new PurchaseInvoicePayment($this->connection, $attributes); + } + /** * @param array $attributes * @return Receipt