承接 daursu/xero 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

daursu/xero

Composer 安装命令:

composer require daursu/xero

包简介

An elegant Laravel 4 wrapper for the official Xero API.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

This is a wrapper for the official Xero API php library, found at: https://github.com/XeroAPI/XeroOAuth-PHP

Note: I have not implemented the entire API, instead I have created the core logic which can then be extended (see the examples below).

I have tested the library only with a Private app, but it should work for the others.

Installation

Using composer simply add this to your composer.json file:

"require": {
  "daursu/xero": "dev-master"
}

Use composer to install this package.

$ composer update

Registering the Package

Register the service provider within the providers array found in app/config/app.php:

'providers' => array(
	// ...

	'Daursu\Xero\XeroServiceProvider',
)

Publish the configuration file

php artisan config:publish daursu/xero

This should create a new file in app/config/packages/daursu/xero/config.php. Update this file with your own settings and API key. There is also a folder called certs, where I recommend you to put your certificates.

Here is a guide how to generate your public/private key http://developer.xero.com/documentation/advanced-docs/public-private-keypair/

Usage

The syntax is very simillar to the Laravel Eloquent one.

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")'));

Create or update a record

This is pretty straight forward as well.

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

Collections

Collections are used when you need to specify multiple relationships (ie. A contact might have multiple addresses.

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();

Output methods

// You can output an object using different methods
$address->toArray();
$address->toJson();
$address->toXML();

Extend the library

I have not implemented all the models that Xero provides, however it is very easy to implement. Here is an example of adding a new model called CreditNote.

// File CreditNote.php
<?php namespace Daursu\Xero\Models;

class CreditNote extends BaseModel {

	/**
	 * The name of the primary column.
	 *
	 * @var string
	 */
	protected $primary_column = 'CreditNoteID';

}

That's it. You can now use it:

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);

Feel free to fork and send pull requests if you extend this library.

Changelog

  • Version 0.2 - Fix namespaces to adhere to PSR-0. Fixes certain autoload issues.
  • Version 0.1 - Initial release

License & Credits

Credits go to the official Xero API library found at https://github.com/XeroAPI/XeroOAuth-PHP.

This code is licensed under the MIT license. Feel free to modify and distribute.

http://www.softwareassistance.net

http://www.computerassistance.uk.com

daursu/xero 适用场景与选型建议

daursu/xero 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 300 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「illuminate」 「xero」 「payroll」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 daursu/xero 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 daursu/xero 我们能提供哪些服务?
定制开发 / 二次开发

基于 daursu/xero 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 300
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-06