ayles-software/xero-laravel

Laravel 对 Xero 的包装

3.5.0 2024-01-10 22:45 UTC

This package is auto-updated.

Last update: 2024-09-11 00:27:03 UTC


README

Xero Laravel 为 xero 提供包装。

需求

  • Laravel 6+
  • PHP 7.2+

安装

使用 composer 安装

composer require ayles-software/xero-laravel

设置

发布配置。

php artisan vendor:publish --provider="AylesSoftware\XeroLaravel\ServiceProvider"

现在您需要填充 config/xero-laravel.php 文件,其中包含您的 Xero 应用程序的凭据。您可以在 Xero 账户的 我的应用 部分创建应用并找到所需的凭据。将以下变量添加到您的 .env 文件中。

XERO_REDIRECT_URL=
XERO_CLIENT_ID=
XERO_CLIENT_SECRET=

配置文件还包含 Xero 访问范围。要获取新的访问令牌,需要 offline_access 范围。访问令牌 30分钟后过期。有关范围的信息,请参阅xero 文档

迁移

此包使用 XeroAccess 模型来管理访问令牌。运行迁移以创建此表。

OAuth 流程

首先,您必须授权应用程序,这需要设置控制器和路由。一旦应用程序已被授权,Xero 的访问将由本包自我管理。一旦访问令牌过期,将根据需要请求新的令牌。

XeroOAuth::class 提供OAuth流程和访问令牌的再生。

授权控制器的示例。

<?php

namespace App\Http\Controllers;

use AylesSoftware\XeroLaravel\XeroOAuth;

class XeroOAuthController extends Controller
{
    public function __invoke(XeroOAuth $xeroOAuth)
    {
        return $xeroOAuth->flow();
    }
}

用法

use AylesSoftware\XeroLaravel\Facades\Xero;

# Retrieve all contacts 
$contacts = Xero::contacts()->get();

# Retrieve an individual contact by its GUID
$contact =  Xero::contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49');

# Retrieve contacts filtered by name
$contacts = Xero::contacts()->where('Name', 'ANZ')->get();

# Retrieve an individual contact filtered by name
$contact = Xero::contacts()->where('Name', 'ANZ')->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',
]);

有关用法信息,请参阅 https://github.com/calcinai/xero-php

感谢

此包受到 Langley Foxall 优秀人才的启发。

可用关系

以下列表显示了所有可用的关系,可用于访问与您的 Xero 应用程序相关的数据(例如 $xero->relationshipName)。

注意:如果相关服务未为您启用,则某些这些关系可能不可用。

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

许可证

Xero Laravel 是开源软件,使用 MIT 许可证