mandasa2022 / drillcutmyob
MYOB Account Right v2 的 Laravel 封装器
dev-main
2022-06-28 05:29 UTC
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/database: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
- nesbot/carbon: ^2.58
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0
- phpunit/phpunit: ^8.0|^9.3
This package is auto-updated.
Last update: 2024-09-28 10:17:56 UTC
README
MYOB AccountRight v2 的便捷 Laravel 封装器。这仍然处于 alpha 阶段,并将定期包含破坏性更改。完整 README 正在编写中。
安装
您可以通过 composer 安装此软件包
composer require mandasa2022/drillcutmyob
设置
环境要求
MYOB_CLIENT_ID=
MYOB_CLIENT_SECRET=
MYOB_REDIRECT_URI=myob/login
MYOB_GRANT_TYPE=authorization_code
MYOB_SCOPE=CompanyFile
发布预设配置以存储您的 MYOB 认证详情
php artisan vendor:publish --provider="Mandasa\Drillcutmyob\DrillcutmyobServiceProvider" --tag="migrations" php artisan migrate
您现在需要通过以下方式进行认证
use Mandasa\Drillcutmyob\Drillcutmyob; use Mandasa\Drillcutmyob\Models\Remote\CompanyFile; use Mandasa\Drillcutmyob\Models\Remote\Contact\Customer; $drillcutmyob = new Drillcutmyob; //Redirect your user to MYOB to authenticate account right v2 $drillcutmyob->authenticate()->getCode(); //When the code is returned, get your access token $drillcutmyob->authenticate()->getToken(); //Now you can save your credentials like so //You would first load the company files the MYOB user has access to $drillcutmyob->of(CompanyFile::class)->load(); //Then save them like so (the username and passwords are Base64 encoded in Drillcutmyob) $drillcutmyob->authenticate()->saveCompanyFileCredentials([ 'username' => 'USERNAME', 'password' => 'PASSWORD', 'company_file_guid' => 'COMPANY_FILE_GUID', 'company_file_name' => 'COMPANY_FILE_NAME', 'company_file_uri' => 'COMPANY_FILE_URI'' ]);
使用方法
获取
完成此步骤后,您将能够像平常一样查询 API
//And now query the API with the supported models (and paginate if supported) $drillcutmyob->of(Customer::class)->page(1); //page 1 //Or (if the Model is a paginted model it will stil default to pagination due to MYOB api restrictions) $drillcutmyob->of(Customer::class)->load(); //page 1 $drillcutmyob->of(Customer::class)->load(2); //page 2 //You can also load the specified model by UID .. here replace UID with your customer UID $drillcutmyob->of(Customer::class)->loadByUid('UID'); //Or just return the first from a search $drillcutmyob->of(TaxCode::class)->whereCode('GST')->first(); //The customer class also has some helper function (whereEmail) $drillcutmyob->of(Customer::class)->whereEmail('drillcutmyob@gmail.com')->get();
如果适当,您还可以公开 MYOB 的原始 API
$drillcutmyob->rawGet('/Contact/Employee'); $drillcutmyob->rawPost('/Contact/Employee', $data);
发布
准备好发布后,您可以执行以下操作,例如保存客户
$taxCode = $this->drillcutmyob->of(TaxCode::class)->whereCode('GST')->first(); $customer = (new Customer)->create([ 'CompanyName' => 'Drillcut', 'LastName' => 'Phillips', 'FirstName' => 'Tim', 'IsIndividual' => false, "TaxCode" => [ "UID" => $taxCode['UID'], ], "FreightTaxCode" => [ "UID" => $taxCode['UID'], ], ]) $drillcutmyob->save($customer);
测试
composer test
待办事项
- 创建 API 认证。
- 创建基本模型语法以检索数据
- 实现可编码数据的基模型
- 创建请求类
- 清理请求类。
- 为适当的模型创建获取和设置,而不是当前的随意方式
- 编写测试
- 使 OAuth2 请求类减少对请求类的依赖
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
有关详细信息,请参阅 CONTRIBUTING。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。
Laravel 包模板
此软件包是使用 Laravel 包模板 生成的。