PHP code example of square-bit / invoicexpress-for-laravel
1. Go to this page and download the library: Download square-bit/invoicexpress-for-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
square-bit / invoicexpress-for-laravel example snippets
use Squarebit\InvoiceXpress\API\Data\ItemData;
use Squarebit\InvoiceXpress\Model\IxItem;
$item = IxItem::find(1234);
$item->description = "a serious description";
$item->save();
$data = ItemData::from([...]);
$item = (new IxItem())->fromData($data)
->save();
$item->delete();
use Squarebit\InvoiceXpress\API\Data\PdfData;
$invoice = (new IxInvoice())
->setClient(IxClient::findOrFail(1234)) // set the invoice's client
->addItem(IxItem::find(2345)) // add an IxItem model
->addItem(ItemData::from([....])) // you can also add from an ItemData
->addItems([ // or from an array
ItemData::from([...]),
IxItem::find(3579),
...
])
->save(); // creates the new invoice (locally and in InvoiceXpress)
->finalizeDocument() // formally registers the invoice
->email(); // email the invoice to the client
// Store the pdf locally
$pdf = $invoice->getPdf()->pdfUrl;
Storage::put('file.jpg', $pdf);
// Pay the invoice and email the receipt
$receipt = $invoice
->pay()
->email();
use Squarebit\InvoiceXpress\Facades\InvoiceXpress;
$itemsEndpoint = InvoiceXpress::items();
$itemData = $itemsEndpoint->get(1234);
$itemData->description = "a serious description";
$itemsEndpoint->update($itemData);
use Squarebit\InvoiceXpress\API\Data\ClientData;
use Squarebit\InvoiceXpress\API\Data\EmailClientData;
use Squarebit\InvoiceXpress\API\Data\EmailData;
use Squarebit\InvoiceXpress\API\Data\InvoiceData;
use Squarebit\InvoiceXpress\API\Data\ItemData;
use Squarebit\InvoiceXpress\API\Data\PartialPaymentData;
use Squarebit\InvoiceXpress\API\Data\StateData;
use Squarebit\InvoiceXpress\Enums\DocumentEventEnum;
use Squarebit\InvoiceXpress\Enums\EntityTypeEnum;
use Squarebit\InvoiceXpress\Facades\InvoiceXpress;
$invoiceEndpoint = InvoiceXpress::invoices();
// Create an Invoice
$invoiceData = $invoiceEndpoint->create(
EntityTypeEnum::SimplifiedInvoice,
InvoiceData::from([
...
'client' => ClientData::from([
...
]),
'items' => [
ItemData::from([])
]
])
);
// Formally register it
$invoiceEndpoint->changeState(
EntityTypeEnum::SimplifiedInvoice,
$invoiceData->id,
StateData::from([
'state' => DocumentEventEnum::Finalized
])
);
// Email the Invoice
$invoiceEndpoint->sendByEmail(
EntityTypeEnum::SimplifiedInvoice,
$invoiceData->id,
EmailData::from([
'client_data' => EmailClientData::from([
'email' => '[email protected]'
]),
'subject' => '...',
'body' => '...',
'cc' => '...',
'bcc' => '...',
])
);
// Get the pdf
$pdfData = $invoiceEndpoint->generatePDF($invoiceData->id)
// Pay the invoice (in total)
$receiptData = $invoiceEndpoint->generatePayment([
EntityTypeEnum::SimplifiedInvoice,
$invoiceData->id,
PartialPaymentData::from([
'amount' => $invoiceData->total,
])
])
$itemsEndpoint = InvoiceXpress::items();
// get an Item by querying the endpoint directly
$itemData = $itemsEndpoint->get(1234);
// create an IxItem model with that data and update it
$item = (new IxItem())->fromData($itemData);
$item->description = 'a more serious description';
// send the modifed data to InvoiceXpress
$itemsEndpoint->update($item->getData());