Skip to content

Commit e095596

Browse files
committed
Merge pull request #6 from EliasZ/patch-1
add findByInvoiceId & registerPayment method to SalesInvoice
2 parents 75f7f6a + c9212ba commit e095596

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/Picqer/Financials/Moneybird/Entities/SalesInvoice.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,38 @@ public function sendInvoice($deliveryMethod = 'Email')
9999
]
100100
]));
101101
}
102+
103+
/**
104+
* Find SalesInvoice by invoice_id
105+
*
106+
* @param $invoiceId
107+
* @return static
108+
*/
109+
public function findByInvoiceId($invoiceId)
110+
{
111+
$result = $this->connection()->get($this->getUrl() . '/find_by_invoice_id/' . urlencode($invoiceId));
112+
113+
return $this->makeFromResponse($result);
114+
}
115+
116+
/**
117+
* Register a payment for the current invoice
118+
*
119+
* @param array $data required keys are payment_date and price
120+
* @throws ApiException
121+
*/
122+
public function registerPayment(array $data)
123+
{
124+
if (! isset($data['payment_date'])) {
125+
throw new ApiException('Required [payment_date] is missing');
126+
}
127+
128+
if (! isset($data['price'])) {
129+
throw new ApiException('Required [price] is missing');
130+
}
131+
132+
$this->connection()->patch($this->url . '/' . $this->id . '/register_payment', json_encode([
133+
'payment' => $data
134+
]));
135+
}
102136
}

0 commit comments

Comments
 (0)