Skip to content

Commit

Permalink
Convert order to invoice, book customer invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Jan 24, 2020
1 parent c270009 commit ab83d9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Models/CustomerInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
class CustomerInvoice extends Model
{

protected $entity = 'customer-invoices';
protected $entity = 'customer-invoices';
protected $primaryKey = 'number';

public function book()
{
return $this->request->handleWithExceptions(function () {

return $this->request->client->post("{$this->entity}/{$this->{$this->primaryKey}}/book")
->getBody()
->getContents();
});
}
}
20 changes: 20 additions & 0 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Rackbeat\Models;


use Rackbeat\Builders\CustomerInvoiceBuilder;
use Rackbeat\Builders\OrderShipmentBuilder;
use Rackbeat\Utils\Model;

Expand Down Expand Up @@ -58,4 +59,23 @@ public function shipments()
]);
});
}

/**
* @param bool $book Should the invoice be booked
* @return CustomerInvoice
* @throws \Rackbeat\Exceptions\RackbeatClientException
* @throws \Rackbeat\Exceptions\RackbeatRequestException
*/
public function convertToInvoice($book = false)
{
return $this->request->handleWithExceptions(function () use ($book) {

$response = json_decode((string)$this->request->client->post("{$this->entity}/{$this->{$this->primaryKey}}/convert-to-invoice?bbok={$book}")
->getBody());

$invoice = (new CustomerInvoiceBuilder($this->request))->find($response->invoice_id);

return $invoice;
});
}
}

0 comments on commit ab83d9d

Please sign in to comment.