1. Go to this page and download the library: Download daursu/xero 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/ */
use \Daursu\Xero\Models\Invoice;
use \Daursu\Xero\Models\Contact;
// Retrieve all the invoices
$invoices = Invoice::get();
foreach ($invoices as $invoice) {
print_r($invoice->toArray());
print_r($invoice->getId());
print_r($invoice->InvoiceID);
}
// Retrive a single invoice
$invoice = Invoice::find("0263f2bd-5825-476b-b6cf-6b76896a8cff");
var_dump($invoice);
// The get method also takes additional parameters
$contact = Contact::get(array('where' => 'Name.Contains("Dan")'));
use \Daursu\Xero\Models\Invoice;
use \Daursu\Xero\Models\Contact;
// Initialize from an array
$invoice = new Invoice(array(
'Type' => 'ACCREC',
'Status' => 'DRAFT',
'Date' => date('Y-m-d'),
...
));
// Now you will need to attach a contact to the invoice
// Note that this time I am not passing an array to the constructor,
// this is just another way you can initialize objects
$contact = new Contact();
$contact->Name = "John Smith";
// Now you can assign it like this
$invoice->Contact = $contact;
// or
$invoice->setRelationship($contact);
// Save the invoice
$invoice->save(); // returns true or false
// Other methods
$invoice->update();
$invoice->create();
print_r($invoice->toArray()); // should have all the properties populated once it comes back from Xero
use \Daursu\Xero\Models\Contact;
use \Daursu\Xero\Models\Address;
$contact = new Contact;
$contact->name = "John";
// IMPORTANT: A collection can only contain a single type of model
// in this case it can only hold addresses.
$collection = Address::newCollection(array(
array('AddressType' => 'NEW', 'AddressLine1' => 'Cambridge', 'AddressLine2' => 'England'),
array('AddressType' => 'OTHER', 'AddressLine1' => 'London', 'AddressLine2' => 'England'),
));
// Push an new item
$collection->push(array('AddressType' => 'STREET', 'AddressLine1' => 'Street', 'AddressLine2' => 'England'));
// Push an existing object
$address = new Address(array('AddressType' => 'OBJECT', 'AddressLine1' => 'Oxford', 'AddressLine2' => 'England'));
$collection->push($address);
// Now set the relationship
$contact->setRelationship($collection);
// Or like this
$contact->Addresses = $collection;
// Save the contact
$contact->save();
// You can output an object using different methods
$address->toArray();
$address->toJson();
$address->toXML();
// File CreditNote.php
namespace Daursu\Xero\Models;
class CreditNote extends BaseModel {
/**
* The name of the primary column.
*
* @var string
*/
protected $primary_column = 'CreditNoteID';
}
use \Daursu\Xero\Models\CreditNote;
use \Daursu\Xero\Models\Contact;
$creditNote = new CreditNote();
$creditNote->Type = 'ACCPAYCREDIT';
$creditNote->Contact = new Contact(array("Name"=> "John");
$creditNote->save();
// Create a collection of credit notes
$collection = CreditNote::newCollection();
$collection->push($creditNote);
app/config/app.php
php artisan config:publish daursu/xero
app/config/packages/daursu/xero/config.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.