guilty/poweroffice
Composer 安装命令:
composer require guilty/poweroffice
包简介
PowerOffice PHP API Client
关键字:
README 文档
README
Poweroffice API client, used it to talk to the PowerOffice API: https://api.poweroffice.net/Web/docs/index.html
Installation
You can install the package via composer:
composer require guilty/poweroffice
Usage
Standalone
You can use the package as a standalone PHP Package, here is a simple example:
<?php use Guilty\Poweroffice\Services\PowerofficeService; use Guilty\Poweroffice\Sessions\ValueStoreSession; use GuzzleHttp\Client; use Spatie\Valuestore\Valuestore; $client = new Client(); $store = Valuestore::make(config("poweroffice.store_path")); $session = new ValueStoreSession($store); $service = new PowerOfficeService( $client, $session, "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key true // Test Mode );
Laravel
You can publish the config file like so
php artisan vendor:publish --provider="Guilty\Poweroffice\PowerofficeServiceProvider" --tag="config"
This is the contents of the published config file:
<?php return [ 'application_key' => env("POWEROFFICE_APPLICATION_KEY"), 'client_key' => env("POWEROFFICE_CLIENT_KEY"), 'test_mode' => env("POWEROFFICE_TEST_MODE"), 'store_path' => storage_path("poweroffice.json"), // Used with the ValueStoreSession ];
To get started, add the following environment variable to your .env file:
POWEROFFICE_APPLICATION_KEY=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa POWEROFFICE_CLIENT_KEY=bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb POWEROFFICE_TEST_MODE=true
Session Implementations
The PowerOffice API uses the "client_credentials" grant type for authentication, to keep track of the "session" (access token, refresh token and expire date) we use a Session class that stores these values for us, out of the box the following session implementations are provided:
Provided Session Implementations
- ArraySession - Used for testing
- ValueStoreSession - Can be used in production, saves all data in a json file defined in the "poweroffice.store_path" config option, uses Spatie's ValueStore package
- RedisSession - Can be used in production, saves all data in a redis cache, keys are prefixed with
POWEROFFICE_SESSION_{KEYNAME}, expects a Predis Client.
Implementing your own session class
Create a new class that implements the SessionInterface interface and add the required methods, the actual implementation is up to you, you can put the data in a database, a file, in redis, or whatever you need.
OR...
extend the AbstractSession which implements some of the methods for you.
Here is the interface you need to implement.
<?php namespace Guilty\Poweroffice\Interfaces; interface SessionInterface { public function setAccessToken($accessToken); public function getAccessToken(); public function setRefreshToken($refreshToken); public function getRefreshToken(); public function canRefresh(); public function disconnect(); public function setExpireDate(\DateTime $expireDate); /** @return \DateTimeImmutable */ public function getExpireDate(); public function hasExpired(); public function isValid(); public function setFromResponse($response); }
Here is an example extending the AbstractSession.
<?php use Guilty\Poweroffice\Sessions\AbstractSession; // Or whatever else you want to store your session class ExcelSpreadsheetSession extends AbstractSession { public function setAccessToken($accessToken) { /* TODO: Implement */ } public function getAccessToken() { /* TODO: Implement */ } public function setRefreshToken($refreshToken) { /* TODO: Implement */ } public function getRefreshToken() { /* TODO: Implement */ } public function disconnect() { /* TODO: Implement */ } public function setExpireDate(\DateTime $expireDate) { /* TODO: Implement */ } public function getExpireDate() { /* TODO: Implement */ } }
Using the service class
You can use the performRequest() method directly if you just want to use this package as a thin wrapper for Guzzle that handles the oAuth session storage and maintenance, here is an example:
<?php require "./vendor/autoload.php"; use Guilty\Poweroffice\Services\PowerofficeService; use GuzzleHttp\Client; use Guilty\Poweroffice\Sessions\ArraySession; $service = new PowerOfficeService( new Client(), new ArraySession(), "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key true // Test Mode ); $customer = $service->performRequest("post", "/Customer", [ "json" => [ "firstName" => "John", "lastName" => "Smith", "emailAddress" => "johnsmith@example.com", "invoiceEmailAddress" => "johnsmith@example.com", "isArchived" => false, "isPerson" => true, "invoiceDeliveryType" => 1, // PDF By Email "since" => (new DateTimeImmutable())->format("Y-m-d"), "mailAddress" => $address = [ "address1" => "123 Fakestreet", "city" => "Lazytown", "zipCode" => "1234", "countryCode" => "NO", // ISO Country Code (norway) "isPrimary" => true, ], "streetAddresses" => [$address], // Must be an array ] ]); // All responses will include a success key, that can be used for error handling if ($response["success"] === false) { throw new Exception("Customer could not be created"); }
Or you can use the methods provided, that will prefill the method and path for you, as well as make it easier to provide certain data (like start and end dates).
<?php require "./vendor/autoload.php"; use Guilty\Poweroffice\Services\PowerofficeService; use GuzzleHttp\Client; use Guilty\Poweroffice\Sessions\ArraySession; $service = new PowerOfficeService( new Client(), new ArraySession(), "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key true // Test Mode ); $customer = $service->createCustomer([ "json" => [ "firstName" => "John", "lastName" => "Smith", "emailAddress" => "johnsmith@example.com", "invoiceEmailAddress" => "johnsmith@example.com", "isArchived" => false, "isPerson" => true, "invoiceDeliveryType" => 1, // PDF By Email "since" => (new DateTimeImmutable())->format("Y-m-d"), "mailAddress" => $address = [ "address1" => "123 Fakestreet", "city" => "Lazytown", "zipCode" => "1234", "countryCode" => "NO", // ISO Country Code (norway) "isPrimary" => true, ], "streetAddresses" => [$address], // Must be an array ] ]); // All responses will include a success key, that can be used for error handling if ($response["success"] === false) { throw new Exception("Customer could not be created"); }
Note about oData filtering
It seems that PowerOffice's API is case sensitive when it comes to the field names in oData filtering.
TODO
The following services are implemented in the API client wrapper:
Sessions
- ArraySession (testing)
- ValueStoreSession (production)
- RedisSession (production)
Functionality
- oData filter builder
Services
- Bank/BankTransfer
- Bank/ClientBankAccount
- Blob
- BrandingTheme
- Client
- ClientAuth
- ContactGroup
- Customer
- DebtCollection
- Department
- Employee
- ExternallyDeliverableInvoice
- GeneralLedgerAccount
- Import
- InvoiceAttachment
- JournalEntryVoucher
- Location
- OutgoingInvoice
- PartyBankAccount
- PartyContactPerson
- Payroll/PayItem
- Payroll/SalaryLine
- Product
- ProductGroup
- Project
- ProjectActivity
- ProjectTeamMember
- RecurringInvoice
- Reporting/AccountTransactions
- Reporting/CustomerLedger
- Reporting/InvoiceJournal
- Reporting/SupplierLedger
- Reporting/TrialBalance
- Reporting/Usage
- SubledgerNumberSeries
- Supplier
- TimeTracking/Activity
- TimeTracking/HourType
- TimeTracking/TimeTrackingEntry
- VatCode
License
The MIT License (MIT). Please see License File for more information.
Brought to you by Guilty AS
The Poweroffice logo and Trademark is the property of Poweroffice AS
guilty/poweroffice 适用场景与选型建议
guilty/poweroffice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「client」 「guilty」 「poweroffice」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 guilty/poweroffice 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 guilty/poweroffice 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 guilty/poweroffice 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
APSIS PHP API Client
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-12