voov / billingo-api-datamapper
Billingo API 数据映射器
0.1
2016-02-23 20:32 UTC
Requires
Requires (Dev)
- symfony/var-dumper: 3.0.*
This package is auto-updated.
Last update: 2024-09-25 22:01:29 UTC
README
警告:本包功能高度实验性,不建议在生产环境中使用!
此库为Billingo API提供CRUD访问,并为每个API端点创建了数据映射模型
- 发票 (
Billingo\API\DataMapper\Models\Invoices
) - 发票块 (
Billingo\API\DataMapper\Models\InvoiceBlocks
) - 银行账户 (
Billingo\API\DataMapper\Models\BankAccounts
) - 费用 (
Billingo\API\DataMapper\Models\Expenses
) - 客户 (
Billingo\API\DataMapper\Models\Clients
) - 支付方式 (
Billingo\API\DataMapper\Models\PaymentMethods
) - 增值税 (
Billingo\API\DataMapper\Models\Vat
)
工厂
虽然您可以在不使用Billingo工厂的情况下使用包含的模型,但不建议这样做。
use Billingo\API\Connector\HTTP\Request; use Billingo\API\DataMapper\BillingoFactory; $client = new Request([ 'public_key' => 'YOUR_PUBLIC_KEY', 'private_key' => 'YOUR_PRIVATE_KEY', ]); $factory = new BillingoFactory($client);
用法
使用类常量加载数据
当使用PHP 5.6+时,在指定要创建的模型时,可以使用 ::class
常量。
use Billingo\API\DataMapper\Models\Clients; $clients = $factory->make(Clients::class)->loadAll();
按名称加载数据
使用类名加载数据。
$vat = $factory->makeFromName('vat')->loadAll();
按给定ID加载数据
您可以使用 load
函数加载数据,而不是使用 loadAll
加载每个模型。
$client = $factory->make(Clients::class)->load('12344567');
创建新资源
要创建新资源,请使用相同的工厂方法。
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class); // you can either use magic variables $client->name = 'Test Client Co.'; // or simple fill the whole model with an array $client->fill([ 'name' => 'Test Client Co.' // ... ]); $client->save();
更新资源
您可以通过先加载资源,然后修改必要的字段并调用 save
方法来轻松更新已保存的资源。底层库知道它需要更新资源而不是创建新资源。
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class)->load('12344567'); $client->name = 'Test Client Updated Co.'; $client->save();
删除资源
要删除资源,请首先简单加载资源,然后调用 delete
函数。
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class)->load('12344567')->delete();
特殊发票函数
在Invoice模型中有几个辅助函数可以使使用更加简单。
use Billingo\API\DataMapper\Models\Invoices; $invoice = $factory->make(Invoices::class)->load('12344567'); $invoice->pay(3500, 1);
支付
设置发票已支付或部分支付
public function pay($amount, $paymentMethodId, $date=null)
取消
取消发票。函数返回新的取消发票。
public function cancel()
发送
将发票发送给客户
public function send()