lasserafn/php-dinero

PHP Dinero REST 封装库

1.0.3 2020-11-23 12:38 UTC

README

这是一个 Dinero 的 PHP 封装库。由 lasserafn/laravel-dinero 分支而来。

Build Status Coverage StyleCI Status Total Downloads Latest Stable Version License

安装

  1. 需要使用 composer
composer require lasserafn/php-dinero

要求

  • PHP +5.6

入门指南

  1. 在 Dinero 上申请开发者

  2. 获取你的客户端 ID 和密钥

  3. 登录 Dinero 后,找到组织 ID(左下角)

  1. 在 Dinero 中创建 API 密钥

  2. 如下使用封装库

 $dinero = new \LasseRafn\Dinero\Dinero( $clientId, $clientSecret );
 $dinero->auth( $apiKey, $orgId ); // this WILL send a request to the auth API.
 
 $contacts = $dinero->contacts()->perPage(10)->page(2)->get();
 
 // Do something with the contacts.
 $invoices = $dinero->invoices()->all();
 $products = $dinero->products()->deletedOnly()->all();

你也可以使用旧的认证令牌,如果你不希望在每次设置新的 Dinero 实例时进行认证。

 $dinero = new \LasseRafn\Dinero\Dinero( $clientId, $clientSecret );
 $dinero->setAuth($token, $orgId); // this will NOT send a request to the auth API.
 
 $products = $dinero->products()->deletedOnly()->all();

使用方法

创建联系人

// Create Instance
$dinero = new \LasseRafn\Dinero\Dinero( $clientId, $clientSecret );

// Auth to a Dinero account
$dinero->auth( $apiKey, $orgId );
 
// Create the contact
$contact = $dinero->contacts()->create([ 'IsPerson' => true, 'Name' => 'Test', 'CountryKey' => 'DK' ]);

// if the request succeeded, $contact will be a \LasseRafn\Dinero\Models\Contact object.