1. Go to this page and download the library: Download bluerock/sellsy-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bluerock / sellsy-client example snippets
use Bluerock\Sellsy\Entities;
use Bluerock\Sellsy\Api;
# create a new Contact instance using the related DTO
$contact = new Entities\Contact([
'civility' => 'mr',
'first_name' => 'Jean',
'last_name' => 'MOULIN',
'email' => '[email protected]',
'website' => 'example.com',
'mobile_number' => '0612121212',
'position' => 'Directeur',
'social' => new Entities\ContactSocials([
'twitter' => 'https://twitter.com/u/example',
]),
]);
# store the freshly created Contact into Sellsy
$api = new Api\ContactsApi();
$response = $api->store($contact);
var_dump(
$response->json()
);
$api = new Bluerock\Sellsy\Api\CompaniesApi();
# ... GET single entity
$company = $api->find("123")->entity();
# ... GET collection of entities (index, search..)
$companies = $api->index()->entities();
// Configure the first Sellsy account
Bluerock\Sellsy\Core\Config::switchInstance('first-sellsy')
->set('client_id', 'id-1')
->set('client_secret', 'secret1');
// Configure another one
Bluerock\Sellsy\Core\Config::switchInstance('other-sellsy')
->set('client_id', 'id-2')
->set('client_secret', 'secret2');
// From now, each request is on the 'other-sellsy' account
// ...
// To switch back to the first account
Bluerock\Sellsy\Core\Config::switchInstance('first-sellsy');
use Bluerock\Sellsy\Api\ContactsApi;
$contacts = new ContactsApi();
$contacts->index();
$contacts->search($filters);
$contacts->show($contact_id);
$contacts->store($contact);
use Bluerock\Sellsy\Core\Client;
# via an instance...
$client = new Client();
$client->contacts()->show($contact_id);
# ... or statically.
Client::taxes()->index();
$response->entity(); # Get single resource entity, when available
$response->entities(); # Get resource entities collection, when available (for listing/search)
$response->pagination(); # Get the pagination object, when available
$response->type(); # Returns the type of the data, between "listing" and "single"
$response->json(); # Get raw json data from response, as an associative array
$response->base(); # Get the underlying \Illuminate\Http\Client\Response object
$response->body(): string;
$response->json(): array|mixed;
$response->status(): int;
$response->ok(): bool;
$response->successful(): bool;
$response->failed(): bool;
$response->serverError(): bool;
$response->clientError(): bool;
$response->header($header): string;
$response->headers(): array;
/**
* @return \Bluerock\Sellsy\Entities\Contact|false
* @throws \Illuminate\Http\Client\RequestException
*/
public function maybeFindMyContact($contact_id)
{
try {
return Bluerock\Sellsy\Core\Client::contacts()
->show($contact_id)
->entity();
} catch (\Illuminate\Http\Client\RequestException $e) {
# return false if the contact is not found (404 error).
if ($e->response->clientError() && $e->response->status() === 404) {
return false;
}
# throw the exception for any other status code.
throw $e;
}
}