macsidigital/laravel-xero
Composer 安装命令:
composer require macsidigital/laravel-xero
包简介
Xero Laravel package
README 文档
README
A little Laravel package to communicate with Xero.
Installation
You can install the package via composer:
composer require macsidigital/laravel-xero
The service provider should automatically register for For Laravel > 5.4.
For Laravel < 5.5, open config/app.php and, within the providers array, append:
MacsiDigital\Xero\Providers\XeroServiceProvider::class
Configuration file
Publish the configuration file
php artisan vendor:publish --provider="MacsiDigital\Xero\Providers\XeroServiceProvider"
This will create a xero/config.php within your config directory. Check the Xero documentation for the relevant values in the config.php file. Ensure that the location of the RSA keys matches.
Usage
Everything has been setup to be similar to Laravel syntax.
We also use a little bit of magic to work with Xero's model names. In Xero there are a few different modules (Accounting, Payroll AU etc.), at the minute we only support a small part of the accounting area, but we have set naming so that additional modules can be added in future.
If the response is anything other than a '200' then we will throw an exception, so use try catch blocks.
So to use the conacts in the Accounting module we would use the following syntax.
$xero = new \MacsiDigital\Xero\Xero; $xero->AccountingContact->functionName();
Find all
The find all function returns a Laravel Collection so you can use all the Laravel Collection magic
$xero = new \MacsiDigital\Xero\Xero; $contacts = $xero->AccountingContact->all();
Filtered
The filtered find function returns a Laravel Collection so you can use all the Laravel Collection magic
$xero = new \MacsiDigital\Xero\Xero; $contacts = $xero->AccountingContact->where('Name', '=', 'Test Name')->get();
To only get a single item use the 'first' method
$xero = new \MacsiDigital\Xero\Xero; $contact = $xero->AccountingContact->where('Name', '=', 'Test Name')->first();
You can also just passs the name and value if it is to equal
$xero = new \MacsiDigital\Xero\Xero; $contact = $xero->AccountingContact->where('Name', 'Test Name')->get(); $contact = $xero->AccountingContact->where('Name', 'Test Name')->first();
Find by ID
Just like Laravel we can use the 'find' method to return a single matched result on the ID
$xero = new \MacsiDigital\Xero\Xero; $contact = $xero->AccountingContact->find('ID_String');
Creating Items
We can create and update records using the save function, below is the full save script for a creation. Please note the functions for adding multi array items, like addresses.
$contact = $xero->AccountingContact->make([ 'Name' => 'Test Name', 'FirstName' => 'First Name', 'LastName' => 'Last Name', 'EmailAddress' => 'test@test.com', 'IsCustomer' => true, ]); $contact->addAddress($xero->AccountingAddress->make([ 'AddressType' => 'POBOX', 'AddressLine1' => 'Test1', 'AddressLine2' => 'Test2', 'AddressLine3' => 'Test3', 'City' => 'City', 'PostalCode' => 'Test Code', 'Country' => 'Test Country', ])); $contact->save();
Example
Here is an example usage case for querying for a contact, creating if not found and then creating an invoice
$contact = $xero->AccountingContact->where('name', 'Test Name')->first(); if($contact == null){ $contact = $xero->AccountingContact->make([ 'Name' => 'Test Name', 'FirstName' => 'First Name', 'LastName' => 'Last Name', 'EmailAddress' => 'test@test.com', 'IsCustomer' => true, ]); $contact->addAddress($xero->AccountingAddress->make([ 'AddressType' => 'POBOX', 'AddressLine1' => 'Test1', 'AddressLine2' => 'Test2', 'AddressLine3' => 'Test3', 'City' => 'City', 'PostalCode' => 'Test Code', 'Country' => 'Test Country', ])); $contact->save(); } $invoice = $xero->AccountingInvoice->make([ 'Contact' => $contact, ]); $invoice->addLineItem($xero->AccountingLineItem->make([ 'Description' => 'Test Description', 'Quantity' => '1', 'UnitAmount' => '1234.56', 'AccountCode' => '200' ])); $invoice->save();
Resources
At present we have the following resources
- Account
- Contacts
- Invoices
- Payments
- PrePayments
- OverPayments
- CreditNotes
We plan to add more resources in the future but setting up additional models is straight forward, below is the invoice model setup. If you create any models, then create a pull request and we will add into main repo.
namespace MacsiDigital\Xero; use MacsiDigital\Xero\Support\Model; class AccountingInvoice extends Model { const ENDPOINT = 'Invoices'; const NODE_NAME = 'Invoice'; const KEY_FIELD = 'InvoiceID'; protected $methods = ['get', 'post', 'put']; protected $attributes = [ 'Type' => 'ACCREC', 'Contact' => '', 'LineItems' => [], 'Date' => '', 'DueDate' => '', 'LineAmountTypes' => '', 'InvoiceNumber' => '', 'Reference' => '', 'BrandingThemeID' => '', 'Url' => '', 'CurrencyCode' => '', 'CurrencyRate' => '', 'Status' => '', 'SentToContact' => '', 'ExpectedPaymentDate' => '', 'PlannedPaymentDate' => '', 'SubTotal' => '', 'TotalTax' => '', 'Total' => '', 'TotalDiscount' => '', 'InvoiceID' => '', 'HasAttachments' => '', 'Payments' => [], 'Prepayments' => [], 'Overpayments' => [], 'AmountDue' => '', 'AmountPaid' => '', 'FullyPaidOnDate' => '', 'AmountCredited' => '', 'UpdatedDateUTC' => '', 'CreditNotes' => [] ]; protected $relationships = [ 'Contact' => '\MacsiDigital\Xero\Models\Accounting\Contact', 'LineItems' => '\MacsiDigital\Xero\Models\Accounting\LineItem', 'Payments' => '\MacsiDigital\Xero\Models\Accounting\Payment', 'Prepayments' => '\MacsiDigital\Xero\Models\Accounting\Prepayment', 'Overpayments' => '\MacsiDigital\Xero\Models\Accounting\Overpayment', ]; public function addLineItem($item) { $this->attributes['LineItems'][] = $item; } }
Testing
At present there is no PHP Unit Testing, but we plan to add it in the future.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email colin@macsi.co.uk instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
macsidigital/laravel-xero 适用场景与选型建议
macsidigital/laravel-xero 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 810 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「macsidigital」 「laravel-xero」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 macsidigital/laravel-xero 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 macsidigital/laravel-xero 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 macsidigital/laravel-xero 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Zoom package
Laravel API Client Builder package
Laravel Zoom package
Laravel Zoom package
Laravel cookie consent package
统计信息
- 总下载量: 810
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-25