langleyfoxall/xero-laravel
Composer 安装命令:
composer require langleyfoxall/xero-laravel
包简介
💸 Access the Xero accounting system using an Eloquent-like syntax
README 文档
README
Xero Laravel allows developers to access the Xero accounting system using an Eloquent-like syntax.
Please note that this version of Xero Laravel supports the Xero OAuth 2.0 implementation. Older Xero apps using OAuth 1.x are no longer supported.
Installation
Xero Laravel can be easily installed using Composer. Just run the following command from the root of your project.
composer require langleyfoxall/xero-laravel
If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.
Setup
First, run the following artisan command from the root of your project. This
will publish the package configuration file.
php artisan vendor:publish --provider="LangleyFoxall\XeroLaravel\Providers\XeroLaravelServiceProvider"
You now need to populate the config/xero-laravel-lf.php file with the
credentials for your Xero app(s). You can create apps and find the
required credentials in the My Apps
section of your Xero account.
If you only intend to use one Xero app, the standard configuration
file should be sufficient. All you will need to do is add the following
variables to your .env file.
XERO_CLIENT_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XERO_CLIENT_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XERO_REDIRECT_URI=https://example.com/xero-callback
OAuth 2.0 flow
In order for users to make use of your Xero app, they must first give your app permission to access their Xero account. To do this, your web application must do the following.
- Redirect the user to the Xero authorization URL.
- Capture the response from Xero, and obtain an access token.
- Retrieve the list of tenants (typically Xero organisations), and let the user select one.
- Store the access token and selected tenant ID against the user's account for future use.
- Before using the access token, check if it has expired and refresh it if necessary.
The controller below shows these steps in action.
<?php use App\Http\Controllers\Controller; use Illuminate\Http\Request; use LangleyFoxall\XeroLaravel\OAuth2; use League\OAuth2\Client\Token\AccessToken; class XeroController extends Controller { private function getOAuth2() { // This will use the 'default' app configuration found in your 'config/xero-laravel-lf.php` file. // If you wish to use an alternative app configuration you can specify its key (e.g. `new OAuth2('other_app')`). return new OAuth2(); } public function redirectUserToXero() { // Step 1 - Redirect the user to the Xero authorization URL. return $this->getOAuth2()->getAuthorizationRedirect(); } public function handleCallbackFromXero(Request $request) { // Step 2 - Capture the response from Xero, and obtain an access token. $accessToken = $this->getOAuth2()->getAccessTokenFromXeroRequest($request); // Step 3 - Retrieve the list of tenants (typically Xero organisations), and let the user select one. $tenants = $this->getOAuth2()->getTenants($accessToken); $selectedTenant = $tenants[0]; // For example purposes, we're pretending the user selected the first tenant. // Step 4 - Store the access token and selected tenant ID against the user's account for future use. // You can store these anyway you wish. For this example, we're storing them in the database using Eloquent. $user = auth()->user(); $user->xero_access_token = json_encode($accessToken); $user->tenant_id = $selectedTenant->tenantId; $user->save(); } public function refreshAccessTokenIfNecessary() { // Step 5 - Before using the access token, check if it has expired and refresh it if necessary. $user = auth()->user(); $accessToken = new AccessToken(json_decode($user->xero_access_token)); if ($accessToken->hasExpired()) { $accessToken = $this->getOAuth2()->refreshAccessToken($accessToken); $user->xero_access_token = $accessToken; $user->save(); } } }
By default, only a limited number of scopes are defined in the configuration file (space separated). You will probably
want to add to the scopes depending on your application's intended purpose. For example adding the
accounting.transactions scope allows you to manage invoices, and adding the accounting.contacts.read allows you to
read contact information.
Xero's documentation provides a full list of available scopes.
Usage
To use Xero Laravel, you first need to get retrieve your user's stored access token and tenant id. You can use these
to create a new XeroApp object which represents your Xero application.
use LangleyFoxall\XeroLaravel\XeroApp; use League\OAuth2\Client\Token\AccessToken; $user = auth()->user(); $xero = new XeroApp( new AccessToken(json_decode($user->xero_oauth_2_access_token)), $user->xero_tenant_id );
You can then immediately access Xero data using Eloquent-like syntax. The following code snippet shows the available syntax. When multiple results are returned from the API they will be returned as Laravel Collection.
# Retrieve all contacts $contacts = $xero->contacts()->get(); $contacts = $xero->contacts; # Retrieve contacts filtered by name $contacts = $xero->contacts()->where('Name', 'Bank West')->get(); # Retrieve an individual contact filtered by name $contact = $xero->contacts()->where('Name', 'Bank West')->first(); # Retrieve an individual contact by its GUID $contact = $xero->contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49'); # Retrieve multiple contact by their GUIDS $contacts = $xero->contacts()->find([ '34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49', '364xxxx7f-2xx3-7xx3-gxx7-6726xxxxhe76', ]);
Available relationships
The list below shows all available relationships that can be used to access
data related to your Xero application (e.g. $xero->relationshipName).
Note: Some of these relationships may not be available if the related service(s) are not enabled for your Xero account.
accounts
addresses
assetsAssetTypeBookDepreciationSettings
assetsAssetTypes
assetsOverviews
assetsSettings
attachments
bankTransactionBankAccounts
bankTransactionLineItems
bankTransactions
bankTransferFromBankAccounts
bankTransferToBankAccounts
bankTransfers
brandingThemes
contactContactPeople
contactGroups
contacts
creditNoteAllocations
creditNotes
currencies
employees
expenseClaimExpenseClaims
expenseClaims
externalLinks
filesAssociations
filesFiles
filesFolders
filesObjects
invoiceLineItems
invoiceReminders
invoices
itemPurchases
itemSales
items
journalJournalLines
journals
linkedTransactions
manualJournalJournalLines
manualJournals
organisationBills
organisationExternalLinks
organisationPaymentTerms
organisationSales
organisations
overpaymentAllocations
overpaymentLineItems
overpayments
payments
payrollAUEmployeeBankAccounts
payrollAUEmployeeHomeAddresses
payrollAUEmployeeLeaveBalances
payrollAUEmployeeOpeningBalances
payrollAUEmployeePayTemplateDeductionLines
payrollAUEmployeePayTemplateEarningsLines
payrollAUEmployeePayTemplateLeaveLines
payrollAUEmployeePayTemplateReimbursementLines
payrollAUEmployeePayTemplateSuperLines
payrollAUEmployeePayTemplates
payrollAUEmployeeSuperMemberships
payrollAUEmployeeTaxDeclarations
payrollAUEmployees
payrollAULeaveApplicationLeavePeriods
payrollAULeaveApplications
payrollAUPayItemDeductionTypes
payrollAUPayItemEarningsRates
payrollAUPayItemLeaveTypes
payrollAUPayItemReimbursementTypes
payrollAUPayItems
payrollAUPayRuns
payrollAUPayrollCalendars
payrollAUPayslipDeductionLines
payrollAUPayslipEarningsLines
payrollAUPayslipLeaveAccrualLines
payrollAUPayslipLeaveEarningsLines
payrollAUPayslipReimbursementLines
payrollAUPayslipSuperannuationLines
payrollAUPayslipTaxLines
payrollAUPayslipTimesheetEarningsLines
payrollAUPayslips
payrollAUSettingAccounts
payrollAUSettingTrackingCategories
payrollAUSettings
payrollAUSuperFundProducts
payrollAUSuperFundSuperFunds
payrollAUSuperFunds
payrollAUTimesheetTimesheetLines
payrollAUTimesheets
payrollUSEmployeeBankAccounts
payrollUSEmployeeHomeAddresses
payrollUSEmployeeMailingAddresses
payrollUSEmployeeOpeningBalances
payrollUSEmployeePayTemplates
payrollUSEmployeePaymentMethods
payrollUSEmployeeSalaryAndWages
payrollUSEmployeeTimeOffBalances
payrollUSEmployeeWorkLocations
payrollUSEmployees
payrollUSPayItemBenefitTypes
payrollUSPayItemDeductionTypes
payrollUSPayItemEarningsTypes
payrollUSPayItemReimbursementTypes
payrollUSPayItemTimeOffTypes
payrollUSPayItems
payrollUSPayRuns
payrollUSPaySchedules
payrollUSPaystubBenefitLines
payrollUSPaystubDeductionLines
payrollUSPaystubEarningsLines
payrollUSPaystubLeaveEarningsLines
payrollUSPaystubReimbursementLines
payrollUSPaystubTimeOffLines
payrollUSPaystubTimesheetEarningsLines
payrollUSPaystubs
payrollUSSalaryandWages
payrollUSSettingAccounts
payrollUSSettingTrackingCategories
payrollUSSettings
payrollUSTimesheetTimesheetLines
payrollUSTimesheets
payrollUSWorkLocations
phones
prepaymentAllocations
prepaymentLineItems
prepayments
purchaseOrderLineItems
purchaseOrders
receiptLineItems
receipts
repeatingInvoiceLineItems
repeatingInvoiceSchedules
repeatingInvoices
reportBalanceSheets
reportBankStatements
reportBudgetSummaries
reportProfitLosses
reportReports
reportTaxTypes
salesTaxBases
salesTaxPeriods
taxRateTaxComponents
taxRates
taxTypes
trackingCategories
trackingCategoryTrackingOptions
userRoles
users
langleyfoxall/xero-laravel 适用场景与选型建议
langleyfoxall/xero-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 243.49k 次下载、GitHub Stars 达 86, 最近一次更新时间为 2018 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「Accounting」 「eloquent」 「xero」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 langleyfoxall/xero-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 langleyfoxall/xero-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 langleyfoxall/xero-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Access auditing middleware intended for use with Slim Framework applications
Accounting module for atmosphere and laravel
Library for working with monetary values, a BCMath library with rounding support.
Alfabank REST API integration
Powerful and streamlined Laravel package for seamless Zoho Books V3 integration
Paquete adicional de Contabilidad para Solunes Digital.
统计信息
- 总下载量: 243.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 86
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2018-10-16
