thegenielab / brightpearl
Brightpearl API PHP Guzzle Wrapper
Requires
- php: >=5.4
- guzzlehttp/guzzle: ~5.0
- guzzlehttp/guzzle-services: ~0.4
Requires (Dev)
- phpunit/phpunit: ~4.2
This package is not auto-updated.
Last update: 2017-06-19 08:39:40 UTC
README
此包装器使用数组,用于发送与您发送到Brightpearl API相同的json请求。请参考Brightpearl API文档以获取额外/可选字段信息。
此库包由TheGenieLab提供。
安装
Composer
"require": { "thegenielab/brightpearl": "0.3.*" }
Laravel(可选)
服务提供者(config/app.php)
'Brightpearl\Laravel\ServiceProvider'
外观(config/app.php)
'Brightpearl' => 'Brightpearl\Laravel\Facade'
服务(config/services.php)- 全局包设置(不是必需的 - 可以由您稍后覆盖,使用此作为默认值)
'brightpearl' => array( 'dev_reference' => 'sahara', 'dev_secret' => 'fcVGPrRapgRyT83CJb9kg8wBpgIV7tdKikdKA/7SmvY=', 'app_reference' => 'parcelforce', 'account_code' => '', 'account_token' => '', 'api_domain' => '', 'staff_token' => '', ),
使用
基本(任何PHP应用程序)
use \Brightpearl\Client; $client = new Client([ 'dev_reference' => 'sahara', 'dev_secret' => 'fcVGPrRapgRyT83CJb9kg8wBpgIV7tdKikdKA/7SmvY=', 'app_reference' => 'parcelforce', 'account_code' => 'topfurniture', 'account_token' => 'c72a9373-86f5-4138-a41f-c26cd9abfe4e', 'api_domain' => 'eu1', ]); // example call $response = $client->getOrder(['id' => '1']);
Laravel
$client = Brightpearl::settings([ 'account_code' => 'topfurniture', 'account_token' => 'c72a9373-86f5-4138-a41f-c26cd9abfe4e', 'api_domain' => 'eu1', ]); // example call $response = $client->getOrder(['id' => '1']); // or even just $response = Brightpearl::getOrder(['id' => '1']);
服务
这些是通过使用GuzzleHttp/Guzzle-Services生成的服务配置文件创建的API方法调用。对于
会计
getAccountingTaxCode()
- 获取会计税号
// All tax codes on account $allTaxCodes = $client->getAccountingTaxCode(); // Tax code by id $taxCode = $client->getAccountingTaxCode(['id' => '1']); // Tax code by idset $taxCodes = $client->getAccountingTaxCode(['id' => '1-3,4,5']);
联系人
getContact()
- 获取联系人信息
// get a specific contact by id $contact = $client->getContact(['id' => '1']);
getContactAddress()
- 获取联系人地址
// get a specific contact address by id $contactAddress = $client->getContactAddress(['id' => '1']);
postContactAddress()
- 创建新的联系人地址
/** * Required fields: * addressLine1, postalCode * * Required option field: * countryIsoCode or countryId * * Optional fields: * addressLine2, addressLine3, addressLine4 */ $address = [ "addressLine1" => "100 Something St", "postalCode" => "33000", "countryIsoCode" => "USA", ]; $addressId = $client->postContactAddress($address);
postContact()
- 创建新的联系人(需要联系人地址)
/** * Required fields: * firstName, lastName, postAddressIds * * Optional fields: * salutation, communication, contactStatus * relationshipToAccount, organisation * marketingDetails, financialDetails * assignment */ $contact = [ "firstName" => "Jane", "lastName" => "Smith", "postAddressIds" => [ "DEF" => $addressId, "BIL" => $addressId, "DEL" => $addressId, ], ]; $contactId = $client->postContact($contact);
集成
getWebhook()
- 获取会计税号
// All web hooks $allWebhooks = $client->getWebhook(); // Web hook by id $webhook = $client->getWebhook(['id' => '1']); // Web hooks by idset $webhooks = $client->getWebhook(['id' => '1-3,4,5']);
postWebhook()
- 创建新的webhook(需要联系人地址)
/** * Required fields: * subscribeTo, httpMethod, uriTemplate * bodyTemplate, contentType, idSetAccepted */ $webhook = [ "subscribeTo" => "Product", "httpMethod" => "POST", "uriTemplate" => "http://www.example.com/callback", "bodyTemplate" => '{\n \"accountCode\": \"${account-code}\",\n \"resourceType\": \"${resource-type}\",\n \"id\": \"${resource-id}\",\n \"lifecycle-event\": \"${lifecycle-event}\"\n\n}', "contentType" => "application/json", "idSetAccepted" => false ]; $webhookId = $client->postWebhook($contact);
deleteWebhook()
- 删除现有的webhook
/* delete a specific webhook by id (empty json with status 200 is good) */ $response = $client->deleteWebhook(['id' => '1']);
订单
getOrder()
- 获取订单
// Tax code by id $order = $client->getOrder(['id' => '1']); // Tax code by idset $orders = $client->getOrder(['id' => '1-3,4,5']);
postOrder()
- 创建新订单
/** * Required fields: * orderTypeCode, parties * * Optional fields: * reference, priceListId, placedOn * orderStatus, delivery, invoices * currency, assignment, warehouseId */ $order = [ "orderTypeCode" => "SO", "parties" => [ "customer" => [ "contactId" => 204 ] ] ]; $orderId = $client->postOrder($order);
postOrderRow()
- 创建新订单行
/** * Required fields: * orderId, magnitude, taxCode, * rowNet, rowTax * * Required option field: * productId or productName * * Optional fields: * nominalCode */ $row = [ "orderId" => 45, "productId" => 123, // or productName for free text row "quantity" => [ "magnitude" => 3 ], "rowValue" => [ "taxCode" => "T20", "rowNet" => [ "value" => 12.21 ], "rowTax" => [ "value" => 2.44 ] ] ]; $rowId = $this->brightpearl()->postOrderRow($row);
资源
此API包装器使用资源定义来映射uri、参数、标头和其他API元素,用于这些方法调用。资源中的覆盖率可能不会在文档中始终反映出来,因此请随时将其作为额外资源参考,它们位于src/resources
贡献
目前API覆盖率仅代表Brightpearl API的一部分。如果您想贡献,请在develop分支发送错误修复、额外的资源服务和功能pull请求。谢谢!