承接 mradcliffe/xeroclient 相关项目开发

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

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

mradcliffe/xeroclient

Composer 安装命令:

composer require mradcliffe/xeroclient

包简介

Provides a Guzzle client for use with the Xero Accounting and Payroll APIs.

README 文档

README

xeroclient is a PHP library that extends Guzzle to provide integration with the Xero API. It is primarily used as an API layer for your own project. It supports connecting to the Accounting API, Payroll API and File API URLs as either a private, public or partner application although implementation and storage of OAuth2 configuration is up to the implementing software. xeroclient aims to abide by the following criteria in regard to Xero integration:

  1. Abides by the PSR-2 standard.
  2. Uses contemporary PHP libraries such as Guzzle.
  3. Is lightweight and pluggable into a variety of frameworks that do normalization and data modeling their own way.
  4. Is testable.

Ultimately it is up to the software that uses xeroclient to deal with serialization, data modeling, OAuth2 redirect work flow, and configuration or content management.

Build Status

Please see CONTRIBUTING for more information about contributing to this project including Code of Conduct, Accountability, and How to get started.

Dependencies

Usage

Request an access token from Xero API using OAuth2.

// Create a new provider.
$provider = new \Radcliffe\Xero\XeroProvider([
    'clientId' => 'my consumer key',
    'clientSecret' => 'my consumer secret',
    'redirectUri' => 'https://example.com/path/to/my/xero/callback',
    // This will always request offline_access.
    'scopes' => \Radcliffe\Xero\XeroProvider::getValidScopes('accounting'),
]);

// Gets the URL to go to get an authorization code from Xero.
$url = $provider->getAuthorizationUrl();

Create with a guzzle client from an authorization code (see above)

$client = \Radcliffe\Xero\XeroClient::createFromToken('my consumer key', 'my consumer secret', $code, 'authorization_code', 'accounting');
// Store the access token for the next 30 minutes or so if making additional requests.
$tokens = $client->getRefreshedToken();

Create with a guzzle client with an access token

$client = \Radcliffe\Xero\XeroClient::createFromToken(
	'my consumer key',
	'my consumer secret',
	'my access token',
	null,
	'accounting',
	[],
	[],
	'https://example.com/path/to/my/xero/callback'
);

Create with a guzzle client with a refresh token

Access tokens expire after 30 minutes so you can create a new client with a stored refresh token too.

$client = \Radcliffe\Xero\XeroClient::createFromToken(
	'my consumer key',
	'my consumer secret',
	'my request token',
	'refresh_token',
	'accounting',
	[],
	[],
	'https://example.com/path/to/my/xero/callback'
);
// Get the refreshed tokens and store it somewhere.
$tokens = $client->getRefreshedToken();

Use the client instance to make requests

try {
	$options = [
		'query' => ['where' => 'Name.StartsWith("John")'],
		'headers' => ['Accept' => 'application/json'],
	];
	$response = $client->request('GET', 'Accounts', $options);

	// Or use something like Symfony Serializer component.
	$accounts = json_decode($response->getBody()->getContents());
} catch (\GuzzleHttp\Exception\ClientException $e) {
	echo 'Request failed because of ' . $e->getResponse()->getStatusCode();
}

Error handling

If the configured client does not have a valid Xero API URL or if an auth_token is not provided, then XeroRequestException is thrown as part of the Guzzle request.

Previously XeroClient would throw an exception on instantiation, but this is no longer the case. If the initialize method is used directly, XeroClient will probably fail for other reasons.

Use with a legacy OAuth1 application

Please see the 0.2 branch and versions < 0.3.0.

Xero Helper Trait

The XeroHelperTrait provides some useful methods to attach to your classes for dealing with various Xero API query parameters and headers.

License

  • This software is primarily licensed under the MIT license.
  • Exception is granted to use the software under the GPLv2 license.

Alternate libraries

  • xero-php-oauth2 provides an auto-generated SDK for accessing the Xero API that injects Guzzle into each model.
  • xero-php provides an all-in-one solution based on data model assumptions using Curl for PHP 5.3 applications.
  • PHP-Xero provides OAuth1 and Xero classes in the global namespace. Horribly outdated and should not be used. I have a fork.
  • XeroBundle provides a Symfony2 Bundle that is the inspiration for this lightweight library. It is possible to wrap your own factory class to ignore the Symfony2 bundle configuration. Currently broken (my fault) unless you use my fork.
  • XeroOAuth-PHP provides OAuth1 and Xero classes in the global namespace and maintained by the Xero API team for older PHP 5.3 applications.
  • Xero API provides a Drupal module that integrates with the Xero API. In Drupal 8 this depends on this library or XeroBundle above.
  • There are numerous other libraries providing custom code.

Affiliation

This library is not affiliated with Xero Limited.

mradcliffe/xeroclient 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

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