Skip to content

krzaczek/Brightpearl-PHP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brightpearl PHP API wrapper using Guzzle 5

Build Status

This wrapper uses arrays for the same json requests as you would send to the Brightpearl API. Please refer to the Brightpearl API docs for extra/optional field info.

This library package is brought to you by TheGenieLab.

Installation

Composer

    "require": {
        "thegenielab/brightpearl": "0.3.*"
    }

Laravel (optional)

Service Provider (config/app.php)

'Brightpearl\Laravel\ServiceProvider'

Facade (config/app.php)

'Brightpearl'     => 'Brightpearl\Laravel\Facade'

Services (config/services.php) - global package settings (not required - can be overrided by you later, use this for defaults)

    'brightpearl' => array(
        'dev_reference' => 'sahara',
        'dev_secret'    => 'fcVGPrRapgRyT83CJb9kg8wBpgIV7tdKikdKA/7SmvY=',
        'app_reference' => 'parcelforce',
        'account_code'  => '',
        'account_token' => '',
        'api_domain'    => '',
        'staff_token'   => '',
    ),

Usage

Basic (any php app)

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']);

Services

These are the api method calls generated by the service config files using GuzzleHttp/Guzzle-Services. For

Accounting

getAccountingTaxCode() - Retrieve accounting tax code(s)

// 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']);

Contact

getContact() - Retrieve contact info

// get a specific contact by id
$contact = $client->getContact(['id' => '1']);

getContactAddress() - Retrieve contact address

// get a specific contact address by id
$contactAddress = $client->getContactAddress(['id' => '1']);

postContactAddress() - Create new contact Address

/**
 * 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() - Create new contact (requires contact address)

/**
 * 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);

Integration

getWebhook() - Retrieve accounting tax code(s)

// 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() - Create new webhook (requires contact address)

/**
 * 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() - Delete an existing webhook

/* delete a specific webhook by id (empty json with status 200 is good) */
$response = $client->deleteWebhook(['id' => '1']);

Order

getOrder() - Retrieve order(s)

// Tax code by id
$order = $client->getOrder(['id' => '1']);

// Tax code by idset
$orders = $client->getOrder(['id' => '1-3,4,5']);

postOrder() - Create new order

/**
 * 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() - Create new order row

/**
 * 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);

Resources

This API wrapper uses resource definitions to map uris, parameters, headers and other API elements for these method calls. Coverage within the resources might not always be reflected in this documentation so please feel free to refer to them as an additional resource, they are located within src/resources

Contributing

Currently API coverage only represents a portion of the Brightpearl API. If you want to contribute send bug fixes, additional resource services and features in a pull request at the develop branch. Thanks!

About

Brightpearl PHP API wrapper based on Guzzle

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%